aboutsummaryrefslogtreecommitdiff
path: root/src/test/java/com/fasterxml
diff options
context:
space:
mode:
authorTatu Saloranta <tatu.saloranta@iki.fi>2016-10-16 13:42:12 -0700
committerTatu Saloranta <tatu.saloranta@iki.fi>2016-10-16 13:42:12 -0700
commited41686017166371e2661024709be0528fab3241 (patch)
treee0d252fc6eb3faafd1ce3ea6379976c33d4699db /src/test/java/com/fasterxml
parent6163141d99c2e8a2178c1a7eb2bab7191886f1ca (diff)
downloadjackson-databind-ed41686017166371e2661024709be0528fab3241.tar.gz
Fix #1414
Diffstat (limited to 'src/test/java/com/fasterxml')
-rw-r--r--src/test/java/com/fasterxml/jackson/databind/creators/MultiArgConstructorTest.java5
-rw-r--r--src/test/java/com/fasterxml/jackson/databind/creators/TestValueInstantiator.java20
-rw-r--r--src/test/java/com/fasterxml/jackson/databind/exc/DeserExceptionTypeTest.java (renamed from src/test/java/com/fasterxml/jackson/databind/exc/TestExceptionHandling.java)53
-rw-r--r--src/test/java/com/fasterxml/jackson/databind/exc/ExceptionSerializationTest.java6
-rw-r--r--src/test/java/com/fasterxml/jackson/databind/filter/ProblemHandlerTest.java9
-rw-r--r--src/test/java/com/fasterxml/jackson/databind/module/TestSimpleModule.java16
6 files changed, 60 insertions, 49 deletions
diff --git a/src/test/java/com/fasterxml/jackson/databind/creators/MultiArgConstructorTest.java b/src/test/java/com/fasterxml/jackson/databind/creators/MultiArgConstructorTest.java
index 883457c60..eb3bd21a9 100644
--- a/src/test/java/com/fasterxml/jackson/databind/creators/MultiArgConstructorTest.java
+++ b/src/test/java/com/fasterxml/jackson/databind/creators/MultiArgConstructorTest.java
@@ -4,6 +4,7 @@ import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.PropertyAccessor;
import com.fasterxml.jackson.databind.*;
+import com.fasterxml.jackson.databind.exc.InvalidDefinitionException;
import com.fasterxml.jackson.databind.introspect.AnnotatedMember;
import com.fasterxml.jackson.databind.introspect.AnnotatedParameter;
import com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector;
@@ -97,8 +98,8 @@ public class MultiArgConstructorTest extends BaseMapTest
/*MultiArgCtorBean bean =*/ mapper.readValue(aposToQuotes("{'b':13, 'a':-99}"),
MultiArgCtorBean.class);
fail("Should not have passed");
- } catch (JsonMappingException e) {
- verifyException(e, "No suitable constructor");
+ } catch (InvalidDefinitionException e) {
+ verifyException(e, "no Creators");
}
}
}
diff --git a/src/test/java/com/fasterxml/jackson/databind/creators/TestValueInstantiator.java b/src/test/java/com/fasterxml/jackson/databind/creators/TestValueInstantiator.java
index c5de7e5a5..fd0feb70e 100644
--- a/src/test/java/com/fasterxml/jackson/databind/creators/TestValueInstantiator.java
+++ b/src/test/java/com/fasterxml/jackson/databind/creators/TestValueInstantiator.java
@@ -9,7 +9,7 @@ import com.fasterxml.jackson.core.Version;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.annotation.JsonValueInstantiator;
import com.fasterxml.jackson.databind.deser.*;
-import com.fasterxml.jackson.databind.exc.InputMismatchException;
+import com.fasterxml.jackson.databind.exc.InvalidDefinitionException;
import com.fasterxml.jackson.databind.introspect.AnnotatedWithParams;
import com.fasterxml.jackson.databind.module.SimpleModule;
import com.fasterxml.jackson.databind.type.TypeFactory;
@@ -22,7 +22,7 @@ public class TestValueInstantiator extends BaseMapTest
static class MyBean
{
String _secret;
-
+
public MyBean(String s, boolean bogus) {
_secret = s;
}
@@ -31,16 +31,16 @@ public class TestValueInstantiator extends BaseMapTest
static class MysteryBean
{
Object value;
-
+
public MysteryBean(Object v) { value = v; }
}
-
+
static class CreatorBean
{
String _secret;
public String value;
-
+
protected CreatorBean(String s) {
_secret = s;
}
@@ -590,9 +590,9 @@ public class TestValueInstantiator extends BaseMapTest
fail("Should not succeed");
} catch (JsonMappingException e) {
verifyException(e, "Can not construct instance of");
- verifyException(e, "missing default constructor");
- // as per [databind#1404], is input-side, not definition problem
- assertEquals(InputMismatchException.class, e.getClass());
+ verifyException(e, "no Creators");
+ // as per [databind#1414], is definition problem
+ assertEquals(InvalidDefinitionException.class, e.getClass());
}
}
@@ -606,8 +606,8 @@ public class TestValueInstantiator extends BaseMapTest
} catch (JsonMappingException e) {
verifyException(e, "Can not construct instance of");
verifyException(e, "no String-argument constructor/factory");
- // as per [databind#1404], is input-side, not definition problem
- assertEquals(InputMismatchException.class, e.getClass());
+ // as per [databind#1414], is definition problem
+ assertEquals(InvalidDefinitionException.class, e.getClass());
}
}
}
diff --git a/src/test/java/com/fasterxml/jackson/databind/exc/TestExceptionHandling.java b/src/test/java/com/fasterxml/jackson/databind/exc/DeserExceptionTypeTest.java
index 35a6224b4..6b5f79aff 100644
--- a/src/test/java/com/fasterxml/jackson/databind/exc/TestExceptionHandling.java
+++ b/src/test/java/com/fasterxml/jackson/databind/exc/DeserExceptionTypeTest.java
@@ -9,27 +9,39 @@ import com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException;
/**
* Unit test for verifying that exceptions are properly handled (caught,
- * re-thrown or wrapped, depending)
- * with Object deserialization.
+ * re-thrown or wrapped, depending) with Object deserialization,
+ * including using concrete subtypes of {@link JsonMappingException}
+ * (or, for low-level parsing, {@link JsonParseException}).
*/
-public class TestExceptionHandling
+public class DeserExceptionTypeTest
extends BaseMapTest
{
static class Bean {
public String propX;
}
+ // Class that has no applicable creators and thus can not be instantiated;
+ // definition problem
+ static class NoCreatorsBean {
+ public int x;
+
+ // Constructor that is not detectable as Creator
+ public NoCreatorsBean(boolean foo, int foo2) { }
+ }
+
/*
/**********************************************************
/* Test methods
/**********************************************************
*/
+ private final ObjectMapper MAPPER = new ObjectMapper();
+
public void testHandlingOfUnrecognized() throws Exception
{
UnrecognizedPropertyException exc = null;
try {
- new ObjectMapper().readValue("{\"bar\":3}", Bean.class);
+ MAPPER.readValue("{\"bar\":3}", Bean.class);
} catch (UnrecognizedPropertyException e) {
exc = e;
}
@@ -49,9 +61,8 @@ public class TestExceptionHandling
*/
public void testExceptionWithEmpty() throws Exception
{
- ObjectMapper mapper = new ObjectMapper();
try {
- Object result = mapper.readValue(" ", Object.class);
+ Object result = MAPPER.readValue(" ", Object.class);
fail("Expected an exception, but got result value: "+result);
} catch (Exception e) {
verifyException(e, InputMismatchException.class, "No content");
@@ -63,12 +74,10 @@ public class TestExceptionHandling
throws Exception
{
BrokenStringReader r = new BrokenStringReader("[ 1, ", "TEST");
- JsonFactory f = new JsonFactory();
- JsonParser jp = f.createParser(r);
- ObjectMapper mapper = new ObjectMapper();
+ JsonParser p = MAPPER.getFactory().createParser(r);
try {
@SuppressWarnings("unused")
- Object ob = mapper.readValue(jp, Object.class);
+ Object ob = MAPPER.readValue(p, Object.class);
fail("Should have gotten an exception");
} catch (IOException e) {
/* For "bona fide" IO problems (due to low-level problem,
@@ -80,27 +89,35 @@ public class TestExceptionHandling
public void testExceptionWithEOF() throws Exception
{
- StringReader r = new StringReader(" 3");
- JsonFactory f = new JsonFactory();
- JsonParser jp = f.createParser(r);
- ObjectMapper mapper = new ObjectMapper();
+ JsonParser p = MAPPER.getFactory().createParser(" 3");
- Integer I = mapper.readValue(jp, Integer.class);
+ Integer I = MAPPER.readValue(p, Integer.class);
assertEquals(3, I.intValue());
// and then end-of-input...
try {
- I = mapper.readValue(jp, Integer.class);
+ I = MAPPER.readValue(p, Integer.class);
fail("Should have gotten an exception");
} catch (IOException e) {
verifyException(e, InputMismatchException.class, "No content");
}
// also: should have no current token after end-of-input
- JsonToken t = jp.getCurrentToken();
+ JsonToken t = p.getCurrentToken();
if (t != null) {
fail("Expected current token to be null after end-of-stream, was: "+t);
}
- jp.close();
+ p.close();
+ }
+
+ // [databind#1414]
+ public void testExceptionForNoCreators() throws Exception
+ {
+ try {
+ NoCreatorsBean b = MAPPER.readValue("{}", NoCreatorsBean.class);
+ fail("Should not succeed, got: "+b);
+ } catch (JsonMappingException e) {
+ verifyException(e, InvalidDefinitionException.class, "no Creators");
+ }
}
/*
diff --git a/src/test/java/com/fasterxml/jackson/databind/exc/ExceptionSerializationTest.java b/src/test/java/com/fasterxml/jackson/databind/exc/ExceptionSerializationTest.java
index e562aa265..0ab9a6bd1 100644
--- a/src/test/java/com/fasterxml/jackson/databind/exc/ExceptionSerializationTest.java
+++ b/src/test/java/com/fasterxml/jackson/databind/exc/ExceptionSerializationTest.java
@@ -120,15 +120,15 @@ public class ExceptionSerializationTest
MAPPER.readValue( "{ \"val\": \"foo\" }", NoSerdeConstructor.class );
fail("Should not pass");
} catch (JsonMappingException e0) {
- verifyException(e0, "no suitable constructor");
+ verifyException(e0, "can not deserialize from Object");
e = e0;
}
// but should be able to serialize new exception we got
String json = MAPPER.writeValueAsString(e);
JsonNode root = MAPPER.readTree(json);
String msg = root.path("message").asText();
- String MATCH = "no suitable constructor";
- if (!msg.contains(MATCH)) {
+ String MATCH = "can not construct instance";
+ if (!msg.toLowerCase().contains(MATCH)) {
fail("Exception should contain '"+MATCH+"', does not: '"+msg+"'");
}
}
diff --git a/src/test/java/com/fasterxml/jackson/databind/filter/ProblemHandlerTest.java b/src/test/java/com/fasterxml/jackson/databind/filter/ProblemHandlerTest.java
index f213843c5..3a3cb1070 100644
--- a/src/test/java/com/fasterxml/jackson/databind/filter/ProblemHandlerTest.java
+++ b/src/test/java/com/fasterxml/jackson/databind/filter/ProblemHandlerTest.java
@@ -8,6 +8,7 @@ import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonToken;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.deser.DeserializationProblemHandler;
+import com.fasterxml.jackson.databind.deser.ValueInstantiator;
import com.fasterxml.jackson.databind.exc.InvalidTypeIdException;
import com.fasterxml.jackson.databind.jsontype.TypeIdResolver;
@@ -107,10 +108,10 @@ public class ProblemHandlerTest extends BaseMapTest
public MissingInstantiationHandler(Object v0) {
value = v0;
}
-
+
@Override
public Object handleMissingInstantiator(DeserializationContext ctxt,
- Class<?> instClass, JsonParser p, String msg)
+ Class<?> instClass, ValueInstantiator inst, JsonParser p, String msg)
throws IOException
{
p.skipChildren();
@@ -122,11 +123,11 @@ public class ProblemHandlerTest extends BaseMapTest
extends DeserializationProblemHandler
{
protected final Object value;
-
+
public WeirdTokenHandler(Object v) {
value = v;
}
-
+
@Override
public Object handleUnexpectedToken(DeserializationContext ctxt,
Class<?> targetType, JsonToken t, JsonParser p,
diff --git a/src/test/java/com/fasterxml/jackson/databind/module/TestSimpleModule.java b/src/test/java/com/fasterxml/jackson/databind/module/TestSimpleModule.java
index 375b41c80..7ec164927 100644
--- a/src/test/java/com/fasterxml/jackson/databind/module/TestSimpleModule.java
+++ b/src/test/java/com/fasterxml/jackson/databind/module/TestSimpleModule.java
@@ -17,12 +17,6 @@ import com.fasterxml.jackson.databind.ser.std.StdSerializer;
@SuppressWarnings("serial")
public class TestSimpleModule extends BaseMapTest
{
- /*
- /**********************************************************
- /* Helper classes; simple beans and their handlers
- /**********************************************************
- */
-
/**
* Trivial bean that requires custom serializer and deserializer
*/
@@ -210,7 +204,8 @@ public class TestSimpleModule extends BaseMapTest
mapper.readValue("{\"str\":\"ab\",\"num\":2}", CustomBean.class);
fail("Should have caused an exception");
} catch (IOException e) {
- verifyException(e, "No suitable constructor found");
+ verifyException(e, "Can not construct");
+ verifyException(e, "no creators");
}
}
@@ -275,8 +270,7 @@ public class TestSimpleModule extends BaseMapTest
SimpleEnum result = mapper.readValue(quote("a"), SimpleEnum.class);
assertSame(SimpleEnum.A, result);
}
-
- // Simple verification of [JACKSON-455]
+
public void testMultipleModules() throws Exception
{
MySimpleModule mod1 = new MySimpleModule("test1", Version.unknownVersion());
@@ -307,8 +301,7 @@ public class TestSimpleModule extends BaseMapTest
/* Unit tests; other
/**********************************************************
*/
-
- // [JACKSON-644]: ability to register mix-ins
+
public void testMixIns() throws Exception
{
SimpleModule module = new SimpleModule("test", Version.unknownVersion());
@@ -322,7 +315,6 @@ public class TestSimpleModule extends BaseMapTest
assertEquals(Integer.valueOf(2), props.get("b"));
}
- // [JACKSON-686]
public void testAccessToMapper() throws Exception
{
ContextVerifierModule module = new ContextVerifierModule();