/** * Use {@link #isBigInteger(String)} to check first, if required. */ public BigInteger getBigInteger(final String path) { return getBigInteger(path, (String)null); }
@Test public void forNonExistent() throws IOException { assertThat(jsonRepresentation.getBigInteger("doesNotExist"), is(nullValue())); }
@Test public void happyCaseForFormatJustFits() throws JsonParseException, JsonMappingException, IOException { assertThat(jsonRepresentation.getBigInteger("aBigInteger", "big-integer(20)"), is(new BigInteger("12345678901234567890"))); }
@Test public void invalidFormattedFromPathButOverridden() throws IOException { assertThat(jsonRepresentation.getBigInteger("yetAnotherSubMap.anInvalidFormattedBigInteger.value", "big-integer(3)"), is(new BigInteger("123"))); }
@Test public void forMultipartKey() throws IOException { assertThat(jsonRepresentation.getBigInteger("aSubMap.aBigInteger"), is(new BigInteger("12345678901234567890"))); }
@Test public void invalidFormattedFromPathButOverridden() throws JsonParseException, JsonMappingException, IOException { assertThat(jsonRepresentation.getBigInteger("yetAnotherSubMap.anInvalidFormattedBigInteger.value", "big-integer(3)"), is(new BigInteger("123"))); }
@Test public void happyCase() throws IOException { assertThat(jsonRepresentation.getBigInteger("aBigInteger"), is(new BigInteger("12345678901234567890"))); }
@Test public void validFormattedFromPath() throws IOException { assertThat(jsonRepresentation.getBigInteger("yetAnotherSubMap.aFormattedBigInteger.value"), is(new BigInteger("123"))); }
@Test public void invalidFormat() throws JsonParseException, JsonMappingException, IOException { expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("Value '12345678901234567890' larger than that allowed by format 'big-integer(19)'"); assertThat(jsonRepresentation.getBigInteger("aBigInteger", "big-integer(19)"), is(new BigInteger("12345678901234567890"))); }
@Test public void invalidFormat() throws IOException { expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("Value '12345678901234567890' larger than that allowed by format 'big-integer(19)'"); assertThat(jsonRepresentation.getBigInteger("aBigInteger", "big-integer(19)"), is(new BigInteger("12345678901234567890"))); }
@Test public void forNonParseableString() throws IOException { expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("'aString' is not a biginteger"); jsonRepresentation.getBigInteger("aString"); }
@Test public void invalidFormattedFromPath() throws JsonParseException, JsonMappingException, IOException { expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("Value '123' larger than that allowed by format 'big-integer(2)'"); jsonRepresentation.getBigInteger("yetAnotherSubMap.anInvalidFormattedBigInteger.value"); }
@Test public void forList() throws JsonParseException, JsonMappingException, IOException { expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("'aSubList' is not a biginteger"); jsonRepresentation.getBigInteger("aSubList"); }
@Test public void invalidFormattedFromPath() throws IOException { expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("Value '123' larger than that allowed by format 'big-integer(2)'"); jsonRepresentation.getBigInteger("yetAnotherSubMap.anInvalidFormattedBigInteger.value"); }
@Test public void forMap() throws JsonParseException, JsonMappingException, IOException { expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("'aSubMap' is not a biginteger"); jsonRepresentation.getBigInteger("aSubMap"); }
@Test public void forMap() throws IOException { expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("'aSubMap' is not a biginteger"); jsonRepresentation.getBigInteger("aSubMap"); }
@Test public void forList() throws IOException { expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("'aSubList' is not a biginteger"); jsonRepresentation.getBigInteger("aSubList"); }
@Test public void forNonParseableString() throws JsonParseException, JsonMappingException, IOException { expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("'aString' is not a biginteger"); jsonRepresentation.getBigInteger("aString"); }
@Test public void whenBigInteger() throws Exception { allowingObjectSpecToReturnSpecIdFor(BigInteger.class); allowingObjectAdapterToReturn(new BigInteger("12345678901234567890")); JsonValueEncoder.appendValueAndFormat(mockObjectSpec, mockObjectAdapter, representation, "big-integer(22)", false); assertThat(representation.isString("value"), is(true)); assertThat(representation.isBigInteger("value"), is(true)); assertThat(representation.getBigInteger("value"), is(new BigInteger("12345678901234567890"))); assertThat(representation.getString("format"), is("big-integer(22)")); assertThat(representation.getString("extensions.x-isis-format"), is("javamathbiginteger")); }
@Test public void whenBigInteger() throws Exception { allowingObjectSpecToReturnSpecIdFor(BigInteger.class); allowingObjectAdapterToReturn(new BigInteger("12345678901234567890")); JsonValueEncoder.appendValueAndFormat(mockObjectSpec, mockObjectAdapter, representation, "big-integer(22)"); assertThat(representation.isString("value"), is(true)); assertThat(representation.isBigInteger("value"), is(true)); assertThat(representation.getBigInteger("value"), is(new BigInteger("12345678901234567890"))); assertThat(representation.getString("format"), is("big-integer(22)")); assertThat(representation.getString("extensions.x-isis-format"), is("javamathbiginteger")); }