JOHNZON-378 JsonbCreator constructor and factory method exceptions tests
diff --git a/johnzon-jsonb/src/test/java/org/apache/johnzon/jsonb/JsonbBeanConstructorExceptionsTest.java b/johnzon-jsonb/src/test/java/org/apache/johnzon/jsonb/JsonbBeanConstructorExceptionsTest.java
index 2c797cb..a395df2 100644
--- a/johnzon-jsonb/src/test/java/org/apache/johnzon/jsonb/JsonbBeanConstructorExceptionsTest.java
+++ b/johnzon-jsonb/src/test/java/org/apache/johnzon/jsonb/JsonbBeanConstructorExceptionsTest.java
@@ -16,7 +16,6 @@
*/
package org.apache.johnzon.jsonb;
-import org.apache.johnzon.mapper.MapperException;
import org.junit.Test;
import javax.json.bind.JsonbException;
diff --git a/johnzon-jsonb/src/test/java/org/apache/johnzon/jsonb/JsonbBeanGetterUserExceptionsTest.java b/johnzon-jsonb/src/test/java/org/apache/johnzon/jsonb/JsonbBeanGetterUserExceptionsTest.java
index c6632bc..f3a77e0 100644
--- a/johnzon-jsonb/src/test/java/org/apache/johnzon/jsonb/JsonbBeanGetterUserExceptionsTest.java
+++ b/johnzon-jsonb/src/test/java/org/apache/johnzon/jsonb/JsonbBeanGetterUserExceptionsTest.java
@@ -19,8 +19,6 @@
import org.apache.johnzon.mapper.MapperException;
import org.junit.Test;
-import javax.json.bind.JsonbException;
-
public class JsonbBeanGetterUserExceptionsTest {
private static final RuntimeException USER_EXCEPTION = new RuntimeException("I am user, hear me roar");
diff --git a/johnzon-jsonb/src/test/java/org/apache/johnzon/jsonb/JsonbCreatorExceptionsTest.java b/johnzon-jsonb/src/test/java/org/apache/johnzon/jsonb/JsonbCreatorExceptionsTest.java
new file mode 100644
index 0000000..1500160
--- /dev/null
+++ b/johnzon-jsonb/src/test/java/org/apache/johnzon/jsonb/JsonbCreatorExceptionsTest.java
@@ -0,0 +1,82 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.johnzon.jsonb;
+
+import org.junit.Test;
+
+import javax.json.bind.JsonbException;
+import javax.json.bind.annotation.JsonbCreator;
+import javax.json.bind.annotation.JsonbProperty;
+
+public class JsonbCreatorExceptionsTest {
+
+ private static final RuntimeException CONSTRUCTOR_EXCEPTION = new RuntimeException("I am user, hear me roar");
+ private static final RuntimeException FACTORY_EXCEPTION = new RuntimeException("I am user, hear me roar");
+
+ @Test
+ public void constructor() {
+ ExceptionAsserts.fromJson("{ \"string\" : \"Supercalifragilisticexpialidocious\" }", Circle.class)
+ .assertInstanceOf(JsonbException.class)
+ .assertCauseChain(CONSTRUCTOR_EXCEPTION)
+ .assertMessage("Circle cannot be constructed to deserialize json object value: {\"string\":\"Supercali...\n" +
+ "java.lang.RuntimeException: I am user, hear me roar");
+ }
+
+
+ @Test
+ public void factory() {
+ ExceptionAsserts.fromJson("{ \"string\" : \"Supercalifragilisticexpialidocious\" }", Square.class)
+ .assertInstanceOf(JsonbException.class)
+ .assertCauseChain(FACTORY_EXCEPTION)
+ .assertMessage("Square cannot be constructed to deserialize json object value: {\"string\":\"Supercali...\n" +
+ "java.lang.RuntimeException: I am user, hear me roar");
+ }
+
+ public static class Circle {
+ private String string;
+
+ @JsonbCreator
+ public Circle(@JsonbProperty("string") final String string) {
+ throw CONSTRUCTOR_EXCEPTION;
+ }
+
+ public String getString() {
+ return string;
+ }
+
+ public void setString(final String string) {
+ this.string = string;
+ }
+ }
+
+ public static class Square {
+ private String string;
+
+ public String getString() {
+ return string;
+ }
+
+ public void setString(final String string) {
+ this.string = string;
+ }
+
+ @JsonbCreator
+ public static Square square(@JsonbProperty("string") final String string) {
+ throw FACTORY_EXCEPTION;
+ }
+ }
+}