Skip to content

Commit

Permalink
test showing behavior for #532
Browse files Browse the repository at this point in the history
  • Loading branch information
ryber committed Aug 20, 2024
1 parent f71b69f commit f2ef351
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions unirest-bdd-tests/src/test/java/BehaviorTests/AsObjectTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,34 @@ void canSetObjectMapperToFailOnUnknown() {
assertEquals(Arrays.asList(1,2,3), error.foo);
}

@Test
void parsingExceptions() {
MockServer.setStringResponse("hi im not json");

var ex = Unirest.get(MockServer.ERROR_RESPONSE)
.asObject(SomeTestClass.class)
.getParsingError()
.get();

assertThat(ex)
.isInstanceOf(UnirestParsingException.class)
.hasMessage("kong.unirest.core.UnirestException: com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'hi': was expecting (JSON String, Number, Array, Object or token 'null', 'true' or 'false')\n" +
" at [Source: REDACTED (`StreamReadFeature.INCLUDE_SOURCE_IN_LOCATION` disabled); line: 1, column: 3]");

var ex2 = Unirest.get(MockServer.ERROR_RESPONSE)
.asObject(new GenericType<SomeTestClass>() {})
.getParsingError()
.get();

assertThat(ex2)
.isInstanceOf(UnirestParsingException.class)
.hasMessage("kong.unirest.core.UnirestException: com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'hi': was expecting (JSON String, Number, Array, Object or token 'null', 'true' or 'false')\n" +
" at [Source: REDACTED (`StreamReadFeature.INCLUDE_SOURCE_IN_LOCATION` disabled); line: 1, column: 3]");

}

static class SomeTestClass {}

public static class Error {
public List<Integer> foo;
}
Expand Down

0 comments on commit f2ef351

Please sign in to comment.