Skip to content

Commit

Permalink
More tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kniazkov committed Aug 30, 2024
1 parent 478fa42 commit 06c3fe8
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 43 deletions.
77 changes: 34 additions & 43 deletions src/test/java/org/cqfn/astranaut/core/utils/JsonSerializerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.
*/
Expand All @@ -77,14 +78,30 @@ 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"
);
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.
*/
Expand Down Expand Up @@ -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<ChildDescriptor> getChildTypes() {
return Collections.emptyList();
}

@Override
public List<String> getHierarchy() {
return Collections.singletonList(this.getName());
public String getData() {
return "Abracadabra";
}

@Override
public Map<String, String> getProperties() {
return new MapUtils<String, String>().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<String, String> getProperties() {
return new MapUtils<String, String>().put("language", "elven").make();
}

@Override
public Node getChild(final int index) {
public Builder createBuilder() {
return null;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"root": {
"type": "Root",
"children": [
{
"type": "GandalfTheGrey",
"data": "Abracadabra"
}
]
},
"language": "elven"
}

0 comments on commit 06c3fe8

Please sign in to comment.