JOHNZON-376 Mapper API Bean getter user exceptions tests
diff --git a/johnzon-mapper/src/test/java/org/apache/johnzon/mapper/ExceptionAsserts.java b/johnzon-mapper/src/test/java/org/apache/johnzon/mapper/ExceptionAsserts.java
index d858718..abaf530 100644
--- a/johnzon-mapper/src/test/java/org/apache/johnzon/mapper/ExceptionAsserts.java
+++ b/johnzon-mapper/src/test/java/org/apache/johnzon/mapper/ExceptionAsserts.java
@@ -16,6 +16,8 @@
*/
package org.apache.johnzon.mapper;
+import java.io.ByteArrayOutputStream;
+
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
@@ -77,4 +79,12 @@
}
});
}
+
+ public static ExceptionAsserts fromMapperWriteObject(final Object object) {
+ return from(() -> {
+ try (final Mapper mapper = new MapperBuilder().setSnippetMaxLength(20).build()) {
+ mapper.writeObject(object, new ByteArrayOutputStream());
+ }
+ });
+ }
}
diff --git a/johnzon-mapper/src/test/java/org/apache/johnzon/mapper/MapperBeanGetterUserExceptionsTest.java b/johnzon-mapper/src/test/java/org/apache/johnzon/mapper/MapperBeanGetterUserExceptionsTest.java
new file mode 100644
index 0000000..57b620f
--- /dev/null
+++ b/johnzon-mapper/src/test/java/org/apache/johnzon/mapper/MapperBeanGetterUserExceptionsTest.java
@@ -0,0 +1,45 @@
+/*
+ * 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.mapper;
+
+import org.junit.Test;
+
+public class MapperBeanGetterUserExceptionsTest {
+
+ private static final RuntimeException USER_EXCEPTION = new RuntimeException("I am user, hear me roar");
+
+ @Test
+ public void object() {
+ ExceptionAsserts.fromMapperWriteObject(new Widget())
+ .assertInstanceOf(MapperException.class)
+ .assertMessage("Error calling public java.lang.String org.apache.johnzon.mapper.MapperBeanGetter" +
+ "UserExceptionsTest$Widget.getString()")
+ .assertCauseChain(USER_EXCEPTION);
+ }
+
+ public static class Widget {
+ private String string;
+
+ public String getString() {
+ throw USER_EXCEPTION;
+ }
+
+ public void setString(final String string) {
+ this.string = string;
+ }
+ }
+}