diff --git a/src/test/java/org/cqfn/astranaut/core/utils/JsonSerializerTest.java b/src/test/java/org/cqfn/astranaut/core/utils/JsonSerializerTest.java index 537f783..fbc8c73 100644 --- a/src/test/java/org/cqfn/astranaut/core/utils/JsonSerializerTest.java +++ b/src/test/java/org/cqfn/astranaut/core/utils/JsonSerializerTest.java @@ -27,17 +27,13 @@ import java.nio.file.Path; import java.util.Arrays; import java.util.Collections; -import java.util.List; import java.util.Map; import org.cqfn.astranaut.core.base.Builder; -import org.cqfn.astranaut.core.base.ChildDescriptor; import org.cqfn.astranaut.core.base.DraftNode; -import org.cqfn.astranaut.core.base.EmptyFragment; import org.cqfn.astranaut.core.base.EmptyTree; -import org.cqfn.astranaut.core.base.Fragment; import org.cqfn.astranaut.core.base.Node; +import org.cqfn.astranaut.core.base.NodeAndType; import org.cqfn.astranaut.core.base.Tree; -import org.cqfn.astranaut.core.base.Type; import org.cqfn.astranaut.core.example.LittleTrees; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -59,6 +55,11 @@ class JsonSerializerTest { */ private static final String TESTS_PATH = "src/test/resources/json/"; + /** + * Test node with language. + */ + private static final Node TEST_NODE_LANG = new TestNodeWithTypeWithLanguage(); + /** * Test for a tree serialization to a JSON string. */ @@ -77,7 +78,7 @@ void testSerializationToString() { */ @Test void testSerializationWithLanguageSpecified() { - final Tree tree = new Tree(new TestNodeWithTypeWithLanguage()); + final Tree tree = new Tree(JsonSerializerTest.TEST_NODE_LANG); final boolean result = this.serializeAndCompare( tree, "serialization_language_specified.json" @@ -85,6 +86,22 @@ void testSerializationWithLanguageSpecified() { Assertions.assertTrue(result); } + /** + * Test for a tree serialization where language is specified. + */ + @Test + void testSerializationNestedWithLanguageSpecified() { + final DraftNode.Constructor ctor = new DraftNode.Constructor(); + ctor.setName("Root"); + ctor.setChildrenList(Collections.singletonList(JsonSerializerTest.TEST_NODE_LANG)); + final Tree tree = new Tree(ctor.createNode()); + final boolean result = this.serializeAndCompare( + tree, + "serialization_nested_language_specified.json" + ); + Assertions.assertTrue(result); + } + /** * Test for a tree serialization to a JSON string. */ @@ -186,65 +203,39 @@ private boolean serializeAndCompare(final Tree tree, final String filename) { } /** - * Some type where language is specified. + * Some node which has a type where language is specified. * * @since 1.1.0 */ - private static class TestTypeWithLanguage implements Type { + private static class TestNodeWithTypeWithLanguage extends NodeAndType { + @Override public String getName() { return "GandalfTheGrey"; } @Override - public List getChildTypes() { - return Collections.emptyList(); - } - - @Override - public List getHierarchy() { - return Collections.singletonList(this.getName()); + public String getData() { + return "Abracadabra"; } @Override - public Map getProperties() { - return new MapUtils().put("language", "elven").make(); + public int getChildCount() { + return 0; } @Override - public Builder createBuilder() { + public Node getChild(final int index) { return null; } - } - - /** - * Some node which has a type where language is specified. - * - * @since 1.1.0 - */ - private static class TestNodeWithTypeWithLanguage implements Node { - @Override - public Fragment getFragment() { - return EmptyFragment.INSTANCE; - } - - @Override - public Type getType() { - return new TestTypeWithLanguage(); - } - - @Override - public String getData() { - return "Abracadabra"; - } @Override - public int getChildCount() { - return 0; + public Map getProperties() { + return new MapUtils().put("language", "elven").make(); } @Override - public Node getChild(final int index) { + public Builder createBuilder() { return null; } } diff --git a/src/test/resources/json/serialization_nested_language_specified.json b/src/test/resources/json/serialization_nested_language_specified.json new file mode 100644 index 0000000..cd8df2b --- /dev/null +++ b/src/test/resources/json/serialization_nested_language_specified.json @@ -0,0 +1,12 @@ +{ + "root": { + "type": "Root", + "children": [ + { + "type": "GandalfTheGrey", + "data": "Abracadabra" + } + ] + }, + "language": "elven" +} \ No newline at end of file