@Test public void forJsonRepresentation() throws IOException { jsonRepresentation = new JsonRepresentation(readJson("map.json")); final Iterable<Entry<String, JsonRepresentation>> mapIterable = jsonRepresentation.mapIterable(); final Iterator<Entry<String, JsonRepresentation>> mapIterator = mapIterable.iterator(); for (int i = 0; i < jsonRepresentation.asJsonNode().size(); i++) { assertThat(mapIterator.hasNext(), is(true)); assertThat(mapIterator.next().getKey(), is(not(nullValue()))); } assertThat(mapIterator.hasNext(), is(false)); }
@Before public void setUp() throws Exception { jsonRepresentation = new JsonRepresentation(readJson("map.json")); }
@Before public void setUp() throws Exception { representation = new DomainObjectRepresentation(readJson("domainObjectRepresentation.json")); }
@Test public void forString() throws JsonParseException, JsonMappingException, IOException { jsonRepresentation = new JsonRepresentation(readJson("listOfStrings.json")); final Iterator<String> arrayIterator = jsonRepresentation.arrayIterator(String.class); assertThat(arrayIterator.hasNext(), is(true)); assertThat(arrayIterator.next(), is("a")); assertThat(arrayIterator.hasNext(), is(true)); assertThat(arrayIterator.next(), is("b")); assertThat(arrayIterator.hasNext(), is(true)); assertThat(arrayIterator.next(), is("c")); assertThat(arrayIterator.hasNext(), is(false)); }
@Test public void forString() throws IOException { jsonRepresentation = new JsonRepresentation(readJson("listOfStrings.json")); final Iterator<String> arrayIterator = jsonRepresentation.arrayIterator(String.class); assertThat(arrayIterator.hasNext(), is(true)); assertThat(arrayIterator.next(), is("a")); assertThat(arrayIterator.hasNext(), is(true)); assertThat(arrayIterator.next(), is("b")); assertThat(arrayIterator.hasNext(), is(true)); assertThat(arrayIterator.next(), is("c")); assertThat(arrayIterator.hasNext(), is(false)); }
@Test(expected = IllegalStateException.class) public void forList() throws IOException { jsonRepresentation = new JsonRepresentation(readJson("list.json")); jsonRepresentation.mapHas("aString"); }
@Test(expected = IllegalArgumentException.class) public void arraySetElementAt_forAttemptingToSetElementToArray() throws IOException { jsonRepresentation = new JsonRepresentation(readJson("list.json")); jsonRepresentation.arraySetElementAt(0, arrayRepr); }
@Test(expected = IndexOutOfBoundsException.class) public void arrayGet_outOfBounds() throws JsonParseException, JsonMappingException, IOException { jsonRepresentation = new JsonRepresentation(readJson("emptyList.json")); jsonRepresentation.arrayGet(0); }
@Test public void arraySetElementAt_happyCaseWhenSetElementToObject() throws JsonParseException, JsonMappingException, IOException { jsonRepresentation = new JsonRepresentation(readJson("list.json")); jsonRepresentation.arraySetElementAt(0, objectRepr); }
@Test(expected = IndexOutOfBoundsException.class) public void arraySetElementAt_outOfBounds() throws IOException { jsonRepresentation = new JsonRepresentation(readJson("emptyList.json")); jsonRepresentation.arraySetElementAt(0, objectRepr); }
@Test public void size_forEmptyList() throws IOException { jsonRepresentation = new JsonRepresentation(readJson("emptyList.json")); assertThat(jsonRepresentation.size(), is(0)); }
@Test(expected = IllegalStateException.class) public void forList() throws JsonParseException, JsonMappingException, IOException { jsonRepresentation = new JsonRepresentation(readJson("list.json")); jsonRepresentation.mapHas("aString"); }
@Test public void size_forEmptyMap() throws JsonParseException, JsonMappingException, IOException { jsonRepresentation = new JsonRepresentation(readJson("emptyMap.json")); assertThat(jsonRepresentation.size(), is(0)); }
@Test public void size_forNonEmptyMap() throws JsonParseException, JsonMappingException, IOException { jsonRepresentation = new JsonRepresentation(readJson("map.json")); assertThat(jsonRepresentation.size(), is(16)); }
@Test(expected = IndexOutOfBoundsException.class) public void arrayGet_outOfBounds() throws IOException { jsonRepresentation = new JsonRepresentation(readJson("emptyList.json")); jsonRepresentation.arrayGet(0); }
@Test(expected = IllegalStateException.class) public void size_forValue() throws IOException { jsonRepresentation = new JsonRepresentation(readJson("map.json")); final JsonRepresentation valueRepresentation = jsonRepresentation.getRepresentation("anInt"); valueRepresentation.size(); }
@Test(expected = IllegalStateException.class) public void size_forValue() throws JsonParseException, JsonMappingException, IOException { jsonRepresentation = new JsonRepresentation(readJson("map.json")); final JsonRepresentation valueRepresentation = jsonRepresentation.getRepresentation("anInt"); valueRepresentation.size(); }
@Test public void forMap() throws IOException { jsonRepresentation = new JsonRepresentation(readJson("map.json")); assertThat(jsonRepresentation.mapHas("aString"), is(true)); assertThat(jsonRepresentation.mapHas("aSubMap.anInt"), is(true)); assertThat(jsonRepresentation.mapHas("nonExistent"), is(false)); }
@Test public void forList() throws IOException { jsonRepresentation = new JsonRepresentation(readJson("list.json")); assertThat(jsonRepresentation.isArray(), is(true)); assertThat(jsonRepresentation.isMap(), is(false)); assertThat(jsonRepresentation.isValue(), is(false)); }
@Test(expected = IllegalStateException.class) public void arrayGet_forValue() throws IOException { jsonRepresentation = new JsonRepresentation(readJson("map.json")); final JsonRepresentation valueRepresentation = jsonRepresentation.getRepresentation("anInt"); valueRepresentation.arrayGet(0); }