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 06c3fe8 commit df35300
Showing 1 changed file with 35 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.util.TreeMap;
import org.cqfn.astranaut.core.base.CoreException;
import org.cqfn.astranaut.core.base.DefaultFactory;
import org.cqfn.astranaut.core.base.EmptyTree;
import org.cqfn.astranaut.core.base.Node;
import org.cqfn.astranaut.core.base.Tree;
import org.cqfn.astranaut.core.base.Type;
Expand All @@ -39,7 +40,6 @@

/**
* Test for {@link JsonDeserializer} class.
*
* @since 1.0.2
*/
class JsonDeserializerTest {
Expand All @@ -59,8 +59,10 @@ class JsonDeserializerTest {
private static final String TESTS_PATH = "src/test/resources/json/";

/**
* Test for a tree deserialization from a JSON string.
* Small syntax tree description.
*/
private static final String SMALL_TREE = "{ \"root\": { \"type\": \"Example\" } }";

@Test
void testDeserialization() {
final String source = this.getFileContent("test_deserialization.json");
Expand All @@ -86,25 +88,17 @@ void testDeserialization() {
Assertions.assertEquals(0, second.getChildCount());
}

/**
* Test deserialization of a JSON object that contains a tree not related
* to some language.
*/
@Test
void loadIntoDraftNode() {
final String source = "{ \"root\": { \"type\": \"Example\" } }";
final JsonDeserializer deserializer = new JsonDeserializer(
source,
JsonDeserializerTest.SMALL_TREE,
language -> DefaultFactory.EMPTY
);
final Tree tree = deserializer.convert();
Assertions.assertNotNull(tree);
Assertions.assertEquals("Example", tree.getRoot().getTypeName());
}

/**
* Testing the deserialization of a tree that contains actions.
*/
@Test
void loadTreeWithActions() {
final String source = this.getFileContent("tree_containing_delete_action.json");
Expand All @@ -117,9 +111,6 @@ void loadTreeWithActions() {
Assertions.assertTrue(expected.deepCompare(actual));
}

/**
* Testing the deserialization of a pattern that contains a hole.
*/
@Test
void loadPatternWithHole() {
final String source = this.getFileContent("pattern_with_hole.json");
Expand All @@ -132,6 +123,36 @@ void loadPatternWithHole() {
Assertions.assertTrue(expected.deepCompare(actual));
}

@Test
void deserializeInvalidJson() {
final JsonDeserializer deserializer = new JsonDeserializer(
".[]test",
language -> DefaultFactory.EMPTY
);
final Tree result = deserializer.convert();
Assertions.assertSame(EmptyTree.INSTANCE, result);
}

@Test
void deserializeJsonWithWrongFormat() {
final JsonDeserializer deserializer = new JsonDeserializer(
"null",
language -> DefaultFactory.EMPTY
);
final Tree result = deserializer.convert();
Assertions.assertSame(EmptyTree.INSTANCE, result);
}

@Test
void deserializeWithNullFactory() {
final JsonDeserializer deserializer = new JsonDeserializer(
JsonDeserializerTest.SMALL_TREE,
language -> null
);
final Tree result = deserializer.convert();
Assertions.assertSame(EmptyTree.INSTANCE, result);
}

/**
* Returns content of the specified file.
* @param name The name of the file
Expand Down

0 comments on commit df35300

Please sign in to comment.