[Add] Framework-API, Core 添加多个单元测试类;

[Add] AbstractBotCodeTest, BasicBotCodeTest, CollectionUtilsTest, MessageChainTest 添加多个针对相应类的完整单元测试类;
This commit is contained in:
2020-11-21 10:14:55 +08:00
parent 12b8b41ac3
commit dc1abdbdac
4 changed files with 423 additions and 0 deletions

View File

@ -0,0 +1,96 @@
/*
* Copyright (C) 2020 LamGC
*
* ContentGrabbingJi is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* ContentGrabbingJi is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package net.lamgc.cgj.bot.framework.base;
import net.lamgc.cgj.bot.framework.Platform;
import net.lamgc.cgj.bot.framework.message.AbstractBotCode;
import net.lamgc.cgj.bot.framework.message.BotCode;
import org.junit.Assert;
import org.junit.Test;
import java.util.HashMap;
import java.util.Map;
/**
* @see BasicBotCode
*/
public class BasicBotCodeTest {
@Test
public void getPlatform() {
BotCode botCode = new BasicBotCode("test");
Assert.assertEquals("ContentGrabbingJi", botCode.getPlatform().getPlatformName());
Assert.assertEquals("CGJ", botCode.getPlatform().getPlatformIdentify());
}
@Test
public void contentToStringWithoutParameter() {
BotCode botCode = new BasicBotCode("test");
Assert.assertEquals("[test]", botCode.contentToString());
}
@Test
public void contentToStringWithParameter() {
final Map<String, String> argumentsMap = new HashMap<>();
argumentsMap.put("arg1", "value1");
argumentsMap.put("arg2", "Hello World.");
argumentsMap.put("arg3", "测试");
BotCode botCode = new BasicBotCode("test", argumentsMap);
Assert.assertEquals("[test:arg3=%E6%B5%8B%E8%AF%95&arg2=Hello+World.&arg1=value1]", botCode.contentToString());
}
@Test
public void createInstanceByBotCode() {
class TestBotCode extends AbstractBotCode {
public TestBotCode(String functionName, Map<String, String> functionProperties) {
super(functionName, functionProperties);
}
@Override
public Platform getPlatform() {
return null;
}
@Override
public String contentToString() {
return null;
}
}
final Map<String, String> argumentsMap = new HashMap<>();
argumentsMap.put("arg1", "value1");
argumentsMap.put("arg2", "Hello World.");
argumentsMap.put("arg3", "测试");
BotCode expectBotCode = new TestBotCode("function", argumentsMap);
BotCode botCode = new BasicBotCode(expectBotCode);
Assert.assertEquals(expectBotCode.getFunctionName(), botCode.getFunctionName());
Assert.assertTrue(expectBotCode.getPropertiesKeys().containsAll(botCode.getPropertiesKeys()));
for (String key : expectBotCode.getPropertiesKeys()) {
Assert.assertEquals(expectBotCode.getProperty(key), botCode.getProperty(key));
}
}
}