[Update] Core 提升 JsonFrameworkDescriptorSerializerTest 测试覆盖率至 100%;

[Update] JsonFrameworkDescriptorSerializerTest 提升测试覆盖率;
[Add] badBotCode-MissingPatternsField-framework.json, badBotCode-PatternsFieldNonArray-framework.json 添加两种错误解析数据;
[Change] test-framework.json 调整解析数据以检查两种软错误解析情况;
This commit is contained in:
LamGC 2020-11-08 21:36:39 +08:00
parent 789c86406c
commit 4b97bf5803
Signed by: LamGC
GPG Key ID: 6C5AE2A913941E1D
4 changed files with 92 additions and 1 deletions

View File

@ -74,6 +74,8 @@ public class JsonFrameworkDescriptorSerializerTest {
List<PluginDependency> expectedDependency = new ArrayList<>(); List<PluginDependency> expectedDependency = new ArrayList<>();
expectedDependency.add(new PluginDependency("RequireDepend@1.0.0")); expectedDependency.add(new PluginDependency("RequireDepend@1.0.0"));
expectedDependency.add(new PluginDependency("OptionalDepend?@1.0.0")); expectedDependency.add(new PluginDependency("OptionalDepend?@1.0.0"));
expectedDependency.add(new PluginDependency("AllVersionSupportedDependA"));
expectedDependency.add(new PluginDependency("AllVersionSupportedDependB@*"));
Assert.assertEquals(expectedDependency, descriptor.getDependencies()); Assert.assertEquals(expectedDependency, descriptor.getDependencies());
@ -82,6 +84,8 @@ public class JsonFrameworkDescriptorSerializerTest {
List<Author> expectedAuthors = new ArrayList<>(); List<Author> expectedAuthors = new ArrayList<>();
expectedAuthors.add(new Author("LamGC", "https://github.com/LamGC", "lam827@lamgc.net")); expectedAuthors.add(new Author("LamGC", "https://github.com/LamGC", "lam827@lamgc.net"));
expectedAuthors.add(new Author("UserA"));
expectedAuthors.add(new Author("UserB"));
Assert.assertEquals(expectedAuthors, descriptor.getAuthors()); Assert.assertEquals(expectedAuthors, descriptor.getAuthors());
@ -125,6 +129,24 @@ public class JsonFrameworkDescriptorSerializerTest {
} }
} }
@Test
public void botCode_MissingPatternsTest() throws IOException {
try (Reader resourceReader = getResourceAsReader("badBotCode-MissingPatternsField-framework.json")) {
List<Pattern> patterns = gson.fromJson(resourceReader, DefaultFrameworkDescriptor.class)
.getBotCodeDescriptor().getPatterns();
Assert.assertTrue(patterns.isEmpty());
}
}
@Test
public void botCode_PatternsFieldNonArrayTest() throws IOException {
try (Reader resourceReader = getResourceAsReader("badBotCode-PatternsFieldNonArray-framework.json")) {
List<Pattern> patterns = gson.fromJson(resourceReader, DefaultFrameworkDescriptor.class)
.getBotCodeDescriptor().getPatterns();
Assert.assertTrue(patterns.isEmpty());
}
}
@Test(expected = JsonParseException.class) @Test(expected = JsonParseException.class)
public void platform_NonAObjectTest() throws IOException { public void platform_NonAObjectTest() throws IOException {
try (Reader resourceReader = getResourceAsReader("badPlatform-NonObject-framework.json")) { try (Reader resourceReader = getResourceAsReader("badPlatform-NonObject-framework.json")) {

View File

@ -0,0 +1,28 @@
// framework.json , .
{
"id": "cgj-mirai",
"description": "test",
"version": "3.0.0-alpha",
"requiresVersion": "=>3.0.0",
"provider": "Github@LamGC, Github@mamoe",
"license": "AGPL-3.0",
"frameworkClass": "com.example.FrameworkMain",
"dependencies": [
"RequireDepend@1.0.0",
"OptionalDepend?@1.0.0"
],
"platform": {
"name": "Tencent QQ",
"identify": "qq"
},
"authors": [
{
"name": "LamGC",
"url": "https://github.com/LamGC",
"email": "lam827@lamgc.net"
}
],
"botCode": {
}
}

View File

@ -0,0 +1,31 @@
// framework.json , .
{
"id": "cgj-mirai",
"description": "test",
"version": "3.0.0-alpha",
"requiresVersion": "=>3.0.0",
"provider": "Github@LamGC, Github@mamoe",
"license": "AGPL-3.0",
"frameworkClass": "com.example.FrameworkMain",
"dependencies": [
"RequireDepend@1.0.0",
"OptionalDepend?@1.0.0"
],
"platform": {
"name": "Tencent QQ",
"identify": "qq"
},
"authors": [
{
"name": "LamGC",
"url": "https://github.com/LamGC",
"email": "lam827@lamgc.net"
}
],
"botCode": {
"patterns": {
}
}
}

View File

@ -8,7 +8,9 @@
"frameworkClass": "com.example.FrameworkMain", "frameworkClass": "com.example.FrameworkMain",
"dependencies": [ "dependencies": [
"RequireDepend@1.0.0", "RequireDepend@1.0.0",
"OptionalDepend?@1.0.0" "OptionalDepend?@1.0.0",
"AllVersionSupportedDependA",
"AllVersionSupportedDependB@*"
], ],
"platform": { "platform": {
@ -20,6 +22,14 @@
"name": "LamGC", "name": "LamGC",
"url": "https://github.com/LamGC", "url": "https://github.com/LamGC",
"email": "lam827@lamgc.net" "email": "lam827@lamgc.net"
},
{
"name": "UserA",
"url": []
},
{
"name": "UserB",
"email": []
} }
], ],
"botCode": { "botCode": {