Skip to content

Commit

Permalink
Test improvement wrt #2113
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Sep 10, 2019
1 parent d1a213e commit b571885
Showing 1 changed file with 8 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ public class JDKNumberLeniencyTest extends BaseMapTest
final ObjectMapper VANILLA_MAPPER = sharedMapper();

final ObjectMapper STRICT_MAPPER = jsonMapperBuilder()
.defaultLeniency(false)
.disable(MapperFeature.ALLOW_COERCION_OF_SCALARS)
// .defaultLeniency(false)
.build();

public void testBooleanLeniencyInts() throws Exception
Expand All @@ -19,23 +20,19 @@ public void testBooleanLeniencyInts() throws Exception
VANILLA_MAPPER.readValue("{\"b\" : 3}", BooleanWrapper.class).b);

// But not with strict handling, first by global settings
/*
_verifyCoercionFailure(STRICT_MAPPER, "0", Boolean.class);
_verifyCoercionFailure(STRICT_MAPPER, "{\"b\" : 1}", BooleanWrapper.class);
*/
_verifyBooleanCoercionFailure(STRICT_MAPPER, "0", Boolean.class);
_verifyBooleanCoercionFailure(STRICT_MAPPER, "{\"b\" : 1}", BooleanWrapper.class);
}

protected void _verifyCoercionFailure(ObjectMapper mapper, String json, Class<?> type)
protected void _verifyBooleanCoercionFailure(ObjectMapper mapper, String json, Class<?> type)
throws Exception
{
try {
VANILLA_MAPPER.readValue("1", Boolean.class);
mapper.readValue(json, type);
fail("Should not allow read in strict mode");
} catch (MismatchedInputException e) {
verifyException(e, "foo");
verifyException(e, "Cannot coerce");
verifyException(e, "for type `java.lang.Boolean`");
}
}

// protected ObjectMapper _
}

0 comments on commit b571885

Please sign in to comment.