Skip to content

Commit

Permalink
Add failign test for #51, just in case
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Apr 24, 2020
1 parent b5dcbd8 commit f6e9813
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,53 +12,53 @@
*/
public class ReadViaJSONTest extends TestBase
{
private final TreeCodec TREE_CODEC = new JacksonJrsTreeCodec();
private final JSON treeJSON = jsonWithTreeCodec();
private final TreeCodec TREE_CODEC = new JacksonJrsTreeCodec();
private final JSON treeJSON = jsonWithTreeCodec();

public void testSimpleList() throws Exception
{
final String INPUT = "[true,\"abc\"]";
// and then through jr-objects:
TreeNode node = treeJSON.treeFrom(INPUT);
public void testSimpleList() throws Exception
{
final String INPUT = "[true,\"abc\"]";
// and then through jr-objects:
TreeNode node = treeJSON.treeFrom(INPUT);

assertTrue(node instanceof JrsArray);
assertEquals(2, node.size());
// actually, verify with write...
final StringWriter writer = new StringWriter();
final JsonGenerator g = _factory.createGenerator(writer);
TREE_CODEC.writeTree(g, node);
g.close();
assertEquals(INPUT, writer.toString());
}
assertTrue(node instanceof JrsArray);
assertEquals(2, node.size());
// actually, verify with write...
final StringWriter writer = new StringWriter();
final JsonGenerator g = _factory.createGenerator(writer);
TREE_CODEC.writeTree(g, node);
g.close();
assertEquals(INPUT, writer.toString());
}

public void testSimpleMap() throws Exception
{
final String INPUT = "{\"a\":1,\"b\":true,\"c\":3}";
TreeNode node = treeJSON.treeFrom(INPUT);
assertTrue(node instanceof JrsObject);
assertEquals(3, node.size());
// actually, verify with write...
final StringWriter writer = new StringWriter();
final JsonGenerator g = _factory.createGenerator(writer);
TREE_CODEC.writeTree(g, node);
g.close();
assertEquals(INPUT, writer.toString());
}
public void testSimpleMap() throws Exception
{
final String INPUT = "{\"a\":1,\"b\":true,\"c\":3}";
TreeNode node = treeJSON.treeFrom(INPUT);
assertTrue(node instanceof JrsObject);
assertEquals(3, node.size());
// actually, verify with write...
final StringWriter writer = new StringWriter();
final JsonGenerator g = _factory.createGenerator(writer);
TREE_CODEC.writeTree(g, node);
g.close();
assertEquals(INPUT, writer.toString());
}

public void testSimpleMixed() throws Exception
{
final String INPUT = "{\"a\":[1,2,{\"b\":true},3],\"c\":3}";
TreeNode node = treeJSON.treeFrom(INPUT);
assertTrue(node instanceof JrsObject);
assertEquals(2, node.size());
TreeNode list = node.get("a");
assertTrue(list instanceof JrsArray);
public void testSimpleMixed() throws Exception
{
final String INPUT = "{\"a\":[1,2,{\"b\":true},3],\"c\":3}";
TreeNode node = treeJSON.treeFrom(INPUT);
assertTrue(node instanceof JrsObject);
assertEquals(2, node.size());
TreeNode list = node.get("a");
assertTrue(list instanceof JrsArray);

// actually, verify with write...
final StringWriter writer = new StringWriter();
final JsonGenerator g = _factory.createGenerator(writer);
TREE_CODEC.writeTree(g, node);
g.close();
assertEquals(INPUT, writer.toString());
}
// actually, verify with write...
final StringWriter writer = new StringWriter();
final JsonGenerator g = _factory.createGenerator(writer);
TREE_CODEC.writeTree(g, node);
g.close();
assertEquals(INPUT, writer.toString());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.fasterxml.jackson.jr.stree.failing;

import com.fasterxml.jackson.jr.ob.JSON;
import com.fasterxml.jackson.jr.ob.JSONObjectException;
import com.fasterxml.jackson.jr.stree.TestBase;

/**
* Tests for reading content using {@link JSON} with proper
* codec registration
*/
public class DupFieldNameInTree51Test extends TestBase
{
private final JSON treeJSON = jsonWithTreeCodec();

// [jackson-jr#51]: test dup keys for trees too
public void testFailOnDupMapKeys() throws Exception
{
JSON j = JSON.builder()
.enable(JSON.Feature.FAIL_ON_DUPLICATE_MAP_KEYS)
.build();
assertTrue(j.isEnabled(JSON.Feature.FAIL_ON_DUPLICATE_MAP_KEYS));
final String json = "{\"a\":1,\"b\":2,\"b\":3,\"c\":4}";
try {
/*TreeNode node =*/ treeJSON.treeFrom(json);
fail("Should not pass");
} catch (JSONObjectException e) {
verifyException(e, "Duplicate key");
}
}
}

0 comments on commit f6e9813

Please sign in to comment.