/** * Use {@link #isBoolean()} to check first, if required. */ public Boolean asBoolean() { return getBoolean(null, asJsonNode()); }
/** * Use {@link #isBoolean(String)} to check first, if required. */ public Boolean getBoolean(final String path) { return getBoolean(path, getNode(path)); }
@Test public void forNonExistent() throws JsonParseException, JsonMappingException, IOException { assertThat(jsonRepresentation.getBoolean("doesNotExist"), is(nullValue())); }
@Test public void happyCase() throws IOException { assertThat(jsonRepresentation.getBoolean("aBoolean"), is(true)); }
@Test public void forNonExistent() throws IOException { assertThat(jsonRepresentation.getBoolean("doesNotExist"), is(nullValue())); }
@Test public void forMultipartKey() throws JsonParseException, JsonMappingException, IOException { assertThat(jsonRepresentation.getBoolean("aSubMap.aBoolean"), is(true)); }
@Test public void getCollection() throws IOException { final JsonRepresentation flag = representation.getCollection("someCollection"); assertThat(flag, is(not(nullValue()))); assertThat(flag.getBoolean("value"), is(true)); }
@Test public void forList() throws IOException { try { jsonRepresentation.getBoolean("aSubList"); fail(); } catch (final IllegalArgumentException e) { assertThat(e.getMessage(), is("'aSubList' is not a boolean")); } }
@Test public void forMap() throws JsonParseException, JsonMappingException, IOException { try { jsonRepresentation.getBoolean("aSubMap"); fail(); } catch (final IllegalArgumentException e) { assertThat(e.getMessage(), is("'aSubMap' is not a boolean")); } }
@Test public void getCollection() throws JsonParseException, JsonMappingException, IOException { final JsonRepresentation flag = representation.getCollection("someCollection"); assertThat(flag, is(not(nullValue()))); assertThat(flag.getBoolean("value"), is(true)); }
@Test public void getProperty() throws IOException { final JsonRepresentation flag = representation.getProperty("flag"); assertThat(flag, is(not(nullValue()))); assertThat(flag.getBoolean("value"), is(true)); }
@Test public void forValueButNotABoolean() throws IOException { try { jsonRepresentation.getBoolean("aString"); fail(); } catch (final IllegalArgumentException e) { assertThat(e.getMessage(), is("'aString' is not a boolean")); } }
@Test public void forValueButNotABoolean() throws JsonParseException, JsonMappingException, IOException { try { jsonRepresentation.getBoolean("aString"); fail(); } catch (final IllegalArgumentException e) { assertThat(e.getMessage(), is("'aString' is not a boolean")); } }
@Test public void forMap() throws IOException { try { jsonRepresentation.getBoolean("aSubMap"); fail(); } catch (final IllegalArgumentException e) { assertThat(e.getMessage(), is("'aSubMap' is not a boolean")); } }
@Test public void forList() throws JsonParseException, JsonMappingException, IOException { try { jsonRepresentation.getBoolean("aSubList"); fail(); } catch (final IllegalArgumentException e) { assertThat(e.getMessage(), is("'aSubList' is not a boolean")); } }
@Test public void getProperty() throws JsonParseException, JsonMappingException, IOException { final JsonRepresentation flag = representation.getProperty("flag"); assertThat(flag, is(not(nullValue()))); assertThat(flag.getBoolean("value"), is(true)); }
@Test public void whenBooleanWrapper() throws Exception { allowingObjectSpecToReturnSpecIdFor(Boolean.class); allowingObjectAdapterToReturn(Boolean.TRUE); JsonValueEncoder.appendValueAndFormat(mockObjectSpec, mockObjectAdapter, representation, null); assertThat(representation.isBoolean("value"), is(true)); assertThat(representation.getBoolean("value"), is(Boolean.TRUE)); assertThat(representation.getString("format"), is(nullValue())); }
@Test public void whenBooleanPrimitive() throws Exception { allowingObjectSpecToReturnSpecIdFor(boolean.class); allowingObjectAdapterToReturn(true); JsonValueEncoder.appendValueAndFormat(mockObjectSpec, mockObjectAdapter, representation, null); assertThat(representation.isBoolean("value"), is(true)); assertThat(representation.getBoolean("value"), is(true)); assertThat(representation.getString("format"), is(nullValue())); }
@Test public void whenBooleanPrimitive() throws Exception { allowingObjectSpecToReturnSpecIdFor(boolean.class); allowingObjectAdapterToReturn(true); JsonValueEncoder.appendValueAndFormat(mockObjectSpec, mockObjectAdapter, representation, null, false); assertThat(representation.isBoolean("value"), is(true)); assertThat(representation.getBoolean("value"), is(true)); assertThat(representation.getString("format"), is(nullValue())); }
@Test public void whenBooleanWrapper() throws Exception { allowingObjectSpecToReturnSpecIdFor(Boolean.class); allowingObjectAdapterToReturn(Boolean.TRUE); JsonValueEncoder.appendValueAndFormat(mockObjectSpec, mockObjectAdapter, representation, null, false); assertThat(representation.isBoolean("value"), is(true)); assertThat(representation.getBoolean("value"), is(Boolean.TRUE)); assertThat(representation.getString("format"), is(nullValue())); }