diff options
author | Tatu Saloranta <tatu.saloranta@iki.fi> | 2020-06-18 17:46:05 -0700 |
---|---|---|
committer | Tatu Saloranta <tatu.saloranta@iki.fi> | 2020-06-18 17:46:05 -0700 |
commit | fc029426c63e78ae33b8155f8b2f5708313b2c7d (patch) | |
tree | 4a1af4e40cf8a549847b6ddc19a7bc13dcf95b01 /src/test/java/com/fasterxml/jackson | |
parent | cb393fcb504014939ce901774362f5da40d767bc (diff) | |
download | jackson-databind-fc029426c63e78ae33b8155f8b2f5708313b2c7d.tar.gz |
test cleanup
Diffstat (limited to 'src/test/java/com/fasterxml/jackson')
-rw-r--r-- | src/test/java/com/fasterxml/jackson/databind/struct/UnwrapSingleArrayScalarsTest.java | 100 |
1 files changed, 44 insertions, 56 deletions
diff --git a/src/test/java/com/fasterxml/jackson/databind/struct/UnwrapSingleArrayScalarsTest.java b/src/test/java/com/fasterxml/jackson/databind/struct/UnwrapSingleArrayScalarsTest.java index 37c3ebcaa..c2220f9b3 100644 --- a/src/test/java/com/fasterxml/jackson/databind/struct/UnwrapSingleArrayScalarsTest.java +++ b/src/test/java/com/fasterxml/jackson/databind/struct/UnwrapSingleArrayScalarsTest.java @@ -72,141 +72,138 @@ public class UnwrapSingleArrayScalarsTest extends BaseMapTest final byte byteTest = (byte) 43; final char charTest = 'c'; - final ObjectMapper mapper = new ObjectMapper(); - mapper.enable(DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS); - - final int intValue = mapper.readValue(asArray(intTest), Integer.TYPE); + final int intValue = UNWRAPPING_READER.readValue(asArray(intTest), Integer.TYPE); assertEquals(intTest, intValue); - final Integer integerWrapperValue = mapper.readValue(asArray(Integer.valueOf(intTest)), Integer.class); + final Integer integerWrapperValue = UNWRAPPING_READER.readValue(asArray(Integer.valueOf(intTest)), Integer.class); assertEquals(Integer.valueOf(intTest), integerWrapperValue); - final double doubleValue = mapper.readValue(asArray(doubleTest), Double.class); + final double doubleValue = UNWRAPPING_READER.readValue(asArray(doubleTest), Double.class); assertEquals(doubleTest, doubleValue); - final Double doubleWrapperValue = mapper.readValue(asArray(Double.valueOf(doubleTest)), Double.class); + final Double doubleWrapperValue = UNWRAPPING_READER.readValue(asArray(Double.valueOf(doubleTest)), Double.class); assertEquals(Double.valueOf(doubleTest), doubleWrapperValue); - final long longValue = mapper.readValue(asArray(longTest), Long.TYPE); + final long longValue = UNWRAPPING_READER.readValue(asArray(longTest), Long.TYPE); assertEquals(longTest, longValue); - final Long longWrapperValue = mapper.readValue(asArray(Long.valueOf(longTest)), Long.class); + final Long longWrapperValue = UNWRAPPING_READER.readValue(asArray(Long.valueOf(longTest)), Long.class); assertEquals(Long.valueOf(longTest), longWrapperValue); - final short shortValue = mapper.readValue(asArray(shortTest), Short.TYPE); + final short shortValue = UNWRAPPING_READER.readValue(asArray(shortTest), Short.TYPE); assertEquals(shortTest, shortValue); - final Short shortWrapperValue = mapper.readValue(asArray(Short.valueOf(shortTest)), Short.class); + final Short shortWrapperValue = UNWRAPPING_READER.readValue(asArray(Short.valueOf(shortTest)), Short.class); assertEquals(Short.valueOf(shortTest), shortWrapperValue); - final float floatValue = mapper.readValue(asArray(floatTest), Float.TYPE); + final float floatValue = UNWRAPPING_READER.readValue(asArray(floatTest), Float.TYPE); assertEquals(floatTest, floatValue); - final Float floatWrapperValue = mapper.readValue(asArray(Float.valueOf(floatTest)), Float.class); + final Float floatWrapperValue = UNWRAPPING_READER.readValue(asArray(Float.valueOf(floatTest)), Float.class); assertEquals(Float.valueOf(floatTest), floatWrapperValue); - final byte byteValue = mapper.readValue(asArray(byteTest), Byte.TYPE); + final byte byteValue = UNWRAPPING_READER.readValue(asArray(byteTest), Byte.TYPE); assertEquals(byteTest, byteValue); - final Byte byteWrapperValue = mapper.readValue(asArray(Byte.valueOf(byteTest)), Byte.class); + final Byte byteWrapperValue = UNWRAPPING_READER.readValue(asArray(Byte.valueOf(byteTest)), Byte.class); assertEquals(Byte.valueOf(byteTest), byteWrapperValue); - final char charValue = mapper.readValue(asArray(quote(String.valueOf(charTest))), Character.TYPE); + final char charValue = UNWRAPPING_READER.readValue(asArray(quote(String.valueOf(charTest))), Character.TYPE); assertEquals(charTest, charValue); - final Character charWrapperValue = mapper.readValue(asArray(quote(String.valueOf(charTest))), Character.class); + final Character charWrapperValue = UNWRAPPING_READER.readValue(asArray(quote(String.valueOf(charTest))), Character.class); assertEquals(Character.valueOf(charTest), charWrapperValue); - final boolean booleanTrueValue = mapper.readValue(asArray(true), Boolean.TYPE); + final boolean booleanTrueValue = UNWRAPPING_READER.readValue(asArray(true), Boolean.TYPE); assertTrue(booleanTrueValue); - final boolean booleanFalseValue = mapper.readValue(asArray(false), Boolean.TYPE); + final boolean booleanFalseValue = UNWRAPPING_READER.readValue(asArray(false), Boolean.TYPE); assertFalse(booleanFalseValue); - final Boolean booleanWrapperTrueValue = mapper.readValue(asArray(Boolean.valueOf(true)), Boolean.class); + final Boolean booleanWrapperTrueValue = UNWRAPPING_READER.readValue(asArray(Boolean.valueOf(true)), Boolean.class); assertEquals(Boolean.TRUE, booleanWrapperTrueValue); } public void testSingleElementArrayDisabled() throws Exception { try { NO_UNWRAPPING_READER.readValue("[42]", Integer.class); - fail("Single value array didn't throw an exception when DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS is disabled"); + fail("Single value array didn't throw an exception"); } catch (MismatchedInputException exp) { //Exception was thrown correctly } try { NO_UNWRAPPING_READER.readValue("[42]", Integer.TYPE); - fail("Single value array didn't throw an exception when DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS is disabled"); + fail("Single value array didn't throw an exception"); } catch (MismatchedInputException exp) { //Exception was thrown correctly } try { NO_UNWRAPPING_READER.readValue("[42342342342342]", Long.class); - fail("Single value array didn't throw an exception when DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS is disabled"); + fail("Single value array didn't throw an exception"); } catch (MismatchedInputException exp) { //Exception was thrown correctly } try { NO_UNWRAPPING_READER.readValue("[42342342342342342]", Long.TYPE); - fail("Single value array didn't throw an exception when DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS is disabled"); + fail("Single value array didn't throw an exception"); } catch (MismatchedInputException exp) { //Exception was thrown correctly } try { NO_UNWRAPPING_READER.readValue("[42]", Short.class); - fail("Single value array didn't throw an exception when DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS is disabled"); + fail("Single value array didn't throw an exception"); } catch (MismatchedInputException exp) { //Exception was thrown correctly } try { NO_UNWRAPPING_READER.readValue("[42]", Short.TYPE); - fail("Single value array didn't throw an exception when DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS is disabled"); + fail("Single value array didn't throw an exception"); } catch (MismatchedInputException exp) { //Exception was thrown correctly } try { NO_UNWRAPPING_READER.readValue("[327.2323]", Float.class); - fail("Single value array didn't throw an exception when DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS is disabled"); + fail("Single value array didn't throw an exception"); } catch (MismatchedInputException exp) { //Exception was thrown correctly } try { NO_UNWRAPPING_READER.readValue("[82.81902]", Float.TYPE); - fail("Single value array didn't throw an exception when DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS is disabled"); + fail("Single value array didn't throw an exception"); } catch (MismatchedInputException exp) { //Exception was thrown correctly } try { NO_UNWRAPPING_READER.readValue("[22]", Byte.class); - fail("Single value array didn't throw an exception when DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS is disabled"); + fail("Single value array didn't throw an exception"); } catch (MismatchedInputException exp) { //Exception was thrown correctly } try { NO_UNWRAPPING_READER.readValue("[22]", Byte.TYPE); - fail("Single value array didn't throw an exception when DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS is disabled"); + fail("Single value array didn't throw an exception"); } catch (MismatchedInputException exp) { //Exception was thrown correctly } try { NO_UNWRAPPING_READER.readValue("['d']", Character.class); - fail("Single value array didn't throw an exception when DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS is disabled"); + fail("Single value array didn't throw an exception"); } catch (MismatchedInputException exp) { //Exception was thrown correctly } try { NO_UNWRAPPING_READER.readValue("['d']", Character.TYPE); - fail("Single value array didn't throw an exception when DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS is disabled"); + fail("Single value array didn't throw an exception"); } catch (MismatchedInputException exp) { //Exception was thrown correctly } try { NO_UNWRAPPING_READER.readValue("[true]", Boolean.class); - fail("Single value array didn't throw an exception when DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS is disabled"); + fail("Single value array didn't throw an exception"); } catch (MismatchedInputException exp) { //Exception was thrown correctly } try { NO_UNWRAPPING_READER.readValue("[true]", Boolean.TYPE); - fail("Single value array didn't throw an exception when DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS is disabled"); + fail("Single value array didn't throw an exception"); } catch (MismatchedInputException exp) { //Exception was thrown correctly } @@ -288,27 +285,23 @@ public class UnwrapSingleArrayScalarsTest extends BaseMapTest public void testBigInteger() throws Exception { - final ObjectMapper mapper = objectMapper(); - mapper.disable(DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS); - BigInteger value = new BigInteger("-1234567890123456789012345567809"); - BigInteger result = mapper.readValue(value.toString(), BigInteger.class); + BigInteger result = NO_UNWRAPPING_READER.readValue(value.toString(), BigInteger.class); assertEquals(value, result); try { - mapper.readValue("[" + value.toString() + "]", BigInteger.class); + NO_UNWRAPPING_READER.readValue("[" + value.toString() + "]", BigInteger.class); fail("Exception was not thrown when attempting to read a single value array of BigInteger when UNWRAP_SINGLE_VALUE_ARRAYS feature is disabled"); } catch (MismatchedInputException exp) { verifyException(exp, "Cannot deserialize"); verifyException(exp, "out of START_ARRAY"); } - - mapper.enable(DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS); - result = mapper.readValue("[" + value.toString() + "]", BigInteger.class); + + result = UNWRAPPING_READER.readValue("[" + value.toString() + "]", BigInteger.class); assertEquals(value, result); try { - mapper.readValue("[" + value.toString() + "," + value.toString() + "]", BigInteger.class); + UNWRAPPING_READER.readValue("[" + value.toString() + "," + value.toString() + "]", BigInteger.class); fail("Exception was not thrown when attempting to read a multi-value array of BigInteger when UNWRAP_SINGLE_VALUE_ARRAYS feature is enabled"); } catch (MismatchedInputException exp) { verifyException(exp, "Attempted to unwrap"); @@ -317,15 +310,13 @@ public class UnwrapSingleArrayScalarsTest extends BaseMapTest public void testClassAsArray() throws Exception { - Class<?> result = MAPPER - .readerFor(Class.class) - .with(DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS) + Class<?> result = UNWRAPPING_READER + .forType(Class.class) .readValue(quote(String.class.getName())); assertEquals(String.class, result); try { - MAPPER.readerFor(Class.class) - .without(DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS) + NO_UNWRAPPING_READER.forType(Class.class) .readValue("[" + quote(String.class.getName()) + "]"); fail("Did not throw exception when UNWRAP_SINGLE_VALUE_ARRAYS feature was disabled and attempted to read a Class array containing one element"); } catch (MismatchedInputException e) { @@ -334,18 +325,16 @@ public class UnwrapSingleArrayScalarsTest extends BaseMapTest _verifyMultiValueArrayFail("[" + quote(Object.class.getName()) + "," + quote(Object.class.getName()) +"]", Class.class); - result = MAPPER.readerFor(Class.class) - .with(DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS) + result = UNWRAPPING_READER.forType(Class.class) .readValue("[" + quote(String.class.getName()) + "]"); assertEquals(String.class, result); } public void testURIAsArray() throws Exception { - final ObjectReader reader = MAPPER.readerFor(URI.class); final URI value = new URI("http://foo.com"); try { - reader.without(DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS) + NO_UNWRAPPING_READER.forType(URI.class) .readValue("[\""+value.toString()+"\"]"); fail("Did not throw exception for single value array when UNWRAP_SINGLE_VALUE_ARRAYS is disabled"); } catch (MismatchedInputException e) { @@ -357,18 +346,17 @@ public class UnwrapSingleArrayScalarsTest extends BaseMapTest public void testUUIDAsArray() throws Exception { - final ObjectReader reader = MAPPER.readerFor(UUID.class); final String uuidStr = "76e6d183-5f68-4afa-b94a-922c1fdb83f8"; UUID uuid = UUID.fromString(uuidStr); try { NO_UNWRAPPING_READER.forType(UUID.class) .readValue("[" + quote(uuidStr) + "]"); - fail("Exception was not thrown when UNWRAP_SINGLE_VALUE_ARRAYS is disabled and attempted to read a single value array as a single element"); + fail("Exception was not thrown as expected"); } catch (MismatchedInputException e) { verifyException(e, "out of START_ARRAY token"); } assertEquals(uuid, - reader.with(DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS) + UNWRAPPING_READER.forType(UUID.class) .readValue("[" + quote(uuidStr) + "]")); _verifyMultiValueArrayFail("[" + quote(uuidStr) + "," + quote(uuidStr) + "]", UUID.class); } @@ -382,7 +370,7 @@ public class UnwrapSingleArrayScalarsTest extends BaseMapTest private void _verifyMultiValueArrayFail(String input, Class<?> type) throws IOException { try { UNWRAPPING_READER.forType(type).readValue(input); - fail("Single value array didn't throw an exception when DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS is disabled"); + fail("Single value array didn't throw an exception"); } catch (MismatchedInputException e) { verifyException(e, "Attempted to unwrap"); } |