/** * Use {@link #isInt()} to check first, if required. */ public Integer asInt() { return getInt(null, asJsonNode()); }
/** * Use {@link #isInt(String)} to check first, if required. */ public Integer getInt(final String path) { final JsonNode node = getNode(path); return getInt(path, node); }
@Test public void forNonExistent() throws JsonParseException, JsonMappingException, IOException { assertThat(jsonRepresentation.getInt("doesNotExist"), is(nullValue())); }
@Test public void happyCase() throws IOException { assertThat(jsonRepresentation.getInt("anInt"), is(123)); }
@Test public void happyCase() throws JsonParseException, JsonMappingException, IOException { assertThat(jsonRepresentation.getInt("anInt"), is(123)); }
@Test public void forMultipartKey() throws JsonParseException, JsonMappingException, IOException { assertThat(jsonRepresentation.getInt("aSubMap.anInt"), is(456)); }
@Test public void forMap() throws IOException { try { jsonRepresentation.getInt("aSubMap"); fail(); } catch (final IllegalArgumentException e) { assertThat(e.getMessage(), is("'aSubMap' is not an int")); } }
@Test public void forList() throws IOException { try { jsonRepresentation.getInt("aSubList"); fail(); } catch (final IllegalArgumentException e) { assertThat(e.getMessage(), is("'aSubList' is not an int")); } }
@Test public void forValueButNotAnInt() throws JsonParseException, JsonMappingException, IOException { try { jsonRepresentation.getInt("aString"); fail(); } catch (final IllegalArgumentException e) { assertThat(e.getMessage(), is("'aString' is not an int")); } }
@Test public void forValueButNotAnInt() throws IOException { try { jsonRepresentation.getInt("aString"); fail(); } catch (final IllegalArgumentException e) { assertThat(e.getMessage(), is("'aString' is not an int")); } }
@Test public void forMap() throws JsonParseException, JsonMappingException, IOException { try { jsonRepresentation.getInt("aSubMap"); fail(); } catch (final IllegalArgumentException e) { assertThat(e.getMessage(), is("'aSubMap' is not an int")); } }
@Test public void forList() throws JsonParseException, JsonMappingException, IOException { try { jsonRepresentation.getInt("aSubList"); fail(); } catch (final IllegalArgumentException e) { assertThat(e.getMessage(), is("'aSubList' is not an int")); } }
@Test public void putInt_multipart() throws IOException { jsonRepresentation.mapPut("a.b", 456); assertThat(jsonRepresentation.getInt("a.b"), is(456)); }
@Test public void putInt() throws IOException { jsonRepresentation.mapPut("a", 123); assertThat(jsonRepresentation.getInt("a"), is(123)); }
@Test public void putInt() throws JsonParseException, JsonMappingException, IOException { jsonRepresentation.mapPut("a", 123); assertThat(jsonRepresentation.getInt("a"), is(123)); }
@Test public void putInt_multipart() throws JsonParseException, JsonMappingException, IOException { jsonRepresentation.mapPut("a.b", 456); assertThat(jsonRepresentation.getInt("a.b"), is(456)); }
@Test public void whenIntWrapper() throws Exception { allowingObjectSpecToReturnSpecIdFor(Integer.class); allowingObjectAdapterToReturn(Integer.valueOf(12345678)); JsonValueEncoder.appendValueAndFormat(mockObjectSpec, mockObjectAdapter, representation, null, false); assertThat(representation.isIntegralNumber("value"), is(true)); assertThat(representation.getInt("value"), is(Integer.valueOf(12345678))); assertThat(representation.getString("format"), is("int")); assertThat(representation.getString("extensions.x-isis-format"), is("int")); }
@Test public void whenIntWrapper() throws Exception { allowingObjectSpecToReturnSpecIdFor(Integer.class); allowingObjectAdapterToReturn(Integer.valueOf(12345678)); JsonValueEncoder.appendValueAndFormat(mockObjectSpec, mockObjectAdapter, representation, null); assertThat(representation.isIntegralNumber("value"), is(true)); assertThat(representation.getInt("value"), is(Integer.valueOf(12345678))); assertThat(representation.getString("format"), is("int")); assertThat(representation.getString("extensions.x-isis-format"), is("int")); }
@Test public void whenIntPrimitive() throws Exception { allowingObjectSpecToReturnSpecIdFor(int.class); allowingObjectAdapterToReturn(12345678); JsonValueEncoder.appendValueAndFormat(mockObjectSpec, mockObjectAdapter, representation, null); assertThat(representation.isIntegralNumber("value"), is(true)); assertThat(representation.getInt("value"), is(12345678)); assertThat(representation.getString("format"), is("int")); assertThat(representation.getString("extensions.x-isis-format"), is("int")); }
@Test public void whenIntPrimitive() throws Exception { allowingObjectSpecToReturnSpecIdFor(int.class); allowingObjectAdapterToReturn(12345678); JsonValueEncoder.appendValueAndFormat(mockObjectSpec, mockObjectAdapter, representation, null, false); assertThat(representation.isIntegralNumber("value"), is(true)); assertThat(representation.getInt("value"), is(12345678)); assertThat(representation.getString("format"), is("int")); assertThat(representation.getString("extensions.x-isis-format"), is("int")); }