/** * Use {@link #isDouble(String)} to check first, if required. */ public Double getDouble(final String path) { final JsonNode node = getNode(path); return getDouble(path, node); }
/** * Use {@link #isDouble()} to check first, if required. */ public Double asDouble() { return getDouble(null, asJsonNode()); }
@Test public void forNonExistent() throws IOException { assertThat(jsonRepresentation.getDouble("doesNotExist"), is(nullValue())); }
@Test public void forNonExistent() throws JsonParseException, JsonMappingException, IOException { assertThat(jsonRepresentation.getDouble("doesNotExist"), is(nullValue())); }
@Test public void forMultipartKey() throws IOException { assertThat(jsonRepresentation.getDouble("aSubMap.aDouble"), is(12345678901234534.4567)); }
@Test public void forMultipartKey() throws JsonParseException, JsonMappingException, IOException { assertThat(jsonRepresentation.getDouble("aSubMap.aDouble"), is(12345678901234534.4567)); }
@Test public void happyCase() throws IOException { assertThat(jsonRepresentation.getDouble("aDouble"), is(12345678901234534.3242)); }
@Test public void happyCase() throws JsonParseException, JsonMappingException, IOException { assertThat(jsonRepresentation.getDouble("aDouble"), is(12345678901234534.3242)); }
@Test public void forValueButNotAnLong() throws JsonParseException, JsonMappingException, IOException { try { jsonRepresentation.getDouble("aString"); fail(); } catch (final IllegalArgumentException e) { assertThat(e.getMessage(), is("'aString' is not a double")); } }
@Test public void forMap() throws IOException { try { jsonRepresentation.getDouble("aSubMap"); fail(); } catch (final IllegalArgumentException e) { assertThat(e.getMessage(), is("'aSubMap' is not a double")); } }
@Test public void forMap() throws JsonParseException, JsonMappingException, IOException { try { jsonRepresentation.getDouble("aSubMap"); fail(); } catch (final IllegalArgumentException e) { assertThat(e.getMessage(), is("'aSubMap' is not a double")); } }
@Test public void forList() throws JsonParseException, JsonMappingException, IOException { try { jsonRepresentation.getDouble("aSubList"); fail(); } catch (final IllegalArgumentException e) { assertThat(e.getMessage(), is("'aSubList' is not a double")); } }
@Test public void forValueButNotAnLong() throws IOException { try { jsonRepresentation.getDouble("aString"); fail(); } catch (final IllegalArgumentException e) { assertThat(e.getMessage(), is("'aString' is not a double")); } }
@Test public void forList() throws IOException { try { jsonRepresentation.getDouble("aSubList"); fail(); } catch (final IllegalArgumentException e) { assertThat(e.getMessage(), is("'aSubList' is not a double")); } }
@Test public void whenDoubleWrapper() throws Exception { allowingObjectSpecToReturnSpecIdFor(Double.class); allowingObjectAdapterToReturn(Double.valueOf(12345.6789)); JsonValueEncoder.appendValueAndFormat(mockObjectSpec, mockObjectAdapter, representation, null, false); assertThat(representation.isDecimal("value"), is(true)); assertThat(representation.getDouble("value"), is(Double.valueOf(12345.6789))); assertThat(representation.getString("format"), is("decimal")); assertThat(representation.getString("extensions.x-isis-format"), is("double")); }
@Test public void whenDoubleWrapper() throws Exception { allowingObjectSpecToReturnSpecIdFor(Double.class); allowingObjectAdapterToReturn(Double.valueOf(12345.6789)); JsonValueEncoder.appendValueAndFormat(mockObjectSpec, mockObjectAdapter, representation, null); assertThat(representation.isDecimal("value"), is(true)); assertThat(representation.getDouble("value"), is(Double.valueOf(12345.6789))); assertThat(representation.getString("format"), is("decimal")); assertThat(representation.getString("extensions.x-isis-format"), is("double")); }
@Test public void whenDoublePrimitive() throws Exception { allowingObjectSpecToReturnSpecIdFor(double.class); allowingObjectAdapterToReturn(12345.6789); JsonValueEncoder.appendValueAndFormat(mockObjectSpec, mockObjectAdapter, representation, null); assertThat(representation.isDecimal("value"), is(true)); assertThat(representation.getDouble("value"), is(12345.6789)); assertThat(representation.getString("format"), is("decimal")); assertThat(representation.getString("extensions.x-isis-format"), is("double")); }
@Test public void whenDoublePrimitive() throws Exception { allowingObjectSpecToReturnSpecIdFor(double.class); allowingObjectAdapterToReturn(12345.6789); JsonValueEncoder.appendValueAndFormat(mockObjectSpec, mockObjectAdapter, representation, null, false); assertThat(representation.isDecimal("value"), is(true)); assertThat(representation.getDouble("value"), is(12345.6789)); assertThat(representation.getString("format"), is("decimal")); assertThat(representation.getString("extensions.x-isis-format"), is("double")); }