From 4f44fd6f9ac45d9346c03cb6fea492720cd5f3fe Mon Sep 17 00:00:00 2001 From: "Kim, Joo Hyuk" Date: Sun, 19 Jan 2025 19:45:17 +0900 Subject: [PATCH 1/5] Add failure test util where needed --- .../failure/JacksonTestFailureExpected.java | 37 ++++++++++++++++ ...JacksonTestFailureExpectedInterceptor.java | 43 +++++++++++++++++++ .../JacksonTestShouldFailException.java | 18 ++++++++ .../failure/JacksonTestFailureExpected.java | 37 ++++++++++++++++ ...JacksonTestFailureExpectedInterceptor.java | 43 +++++++++++++++++++ .../JacksonTestShouldFailException.java | 18 ++++++++ .../failure/JacksonTestFailureExpected.java | 37 ++++++++++++++++ ...JacksonTestFailureExpectedInterceptor.java | 43 +++++++++++++++++++ .../JacksonTestShouldFailException.java | 18 ++++++++ .../failure/JacksonTestFailureExpected.java | 37 ++++++++++++++++ ...JacksonTestFailureExpectedInterceptor.java | 43 +++++++++++++++++++ .../JacksonTestShouldFailException.java | 18 ++++++++ .../failure/JacksonTestFailureExpected.java | 37 ++++++++++++++++ ...JacksonTestFailureExpectedInterceptor.java | 43 +++++++++++++++++++ .../JacksonTestShouldFailException.java | 18 ++++++++ .../failure/JacksonTestFailureExpected.java | 37 ++++++++++++++++ ...JacksonTestFailureExpectedInterceptor.java | 43 +++++++++++++++++++ .../JacksonTestShouldFailException.java | 18 ++++++++ 18 files changed, 588 insertions(+) create mode 100644 afterburner/src/test/java/com/fasterxml/jackson/module/afterburner/util/failure/JacksonTestFailureExpected.java create mode 100644 afterburner/src/test/java/com/fasterxml/jackson/module/afterburner/util/failure/JacksonTestFailureExpectedInterceptor.java create mode 100644 afterburner/src/test/java/com/fasterxml/jackson/module/afterburner/util/failure/JacksonTestShouldFailException.java create mode 100644 android-record/src/test/java/com/fasterxml/jackson/module/androidrecord/testutil/failure/JacksonTestFailureExpected.java create mode 100644 android-record/src/test/java/com/fasterxml/jackson/module/androidrecord/testutil/failure/JacksonTestFailureExpectedInterceptor.java create mode 100644 android-record/src/test/java/com/fasterxml/jackson/module/androidrecord/testutil/failure/JacksonTestShouldFailException.java create mode 100644 blackbird/src/test/java/com/fasterxml/jackson/module/blackbird/testutil/failure/JacksonTestFailureExpected.java create mode 100644 blackbird/src/test/java/com/fasterxml/jackson/module/blackbird/testutil/failure/JacksonTestFailureExpectedInterceptor.java create mode 100644 blackbird/src/test/java/com/fasterxml/jackson/module/blackbird/testutil/failure/JacksonTestShouldFailException.java create mode 100644 jakarta-xmlbind/src/test/java/com/fasterxml/jackson/module/jakarta/xmlbind/testutil/failure/JacksonTestFailureExpected.java create mode 100644 jakarta-xmlbind/src/test/java/com/fasterxml/jackson/module/jakarta/xmlbind/testutil/failure/JacksonTestFailureExpectedInterceptor.java create mode 100644 jakarta-xmlbind/src/test/java/com/fasterxml/jackson/module/jakarta/xmlbind/testutil/failure/JacksonTestShouldFailException.java create mode 100644 jaxb/src/test/java/com/fasterxml/jackson/module/jaxb/testutil/failure/JacksonTestFailureExpected.java create mode 100644 jaxb/src/test/java/com/fasterxml/jackson/module/jaxb/testutil/failure/JacksonTestFailureExpectedInterceptor.java create mode 100644 jaxb/src/test/java/com/fasterxml/jackson/module/jaxb/testutil/failure/JacksonTestShouldFailException.java create mode 100644 paranamer/src/test/java/com/fasterxml/jackson/module/paranamer/testutil/failure/JacksonTestFailureExpected.java create mode 100644 paranamer/src/test/java/com/fasterxml/jackson/module/paranamer/testutil/failure/JacksonTestFailureExpectedInterceptor.java create mode 100644 paranamer/src/test/java/com/fasterxml/jackson/module/paranamer/testutil/failure/JacksonTestShouldFailException.java diff --git a/afterburner/src/test/java/com/fasterxml/jackson/module/afterburner/util/failure/JacksonTestFailureExpected.java b/afterburner/src/test/java/com/fasterxml/jackson/module/afterburner/util/failure/JacksonTestFailureExpected.java new file mode 100644 index 00000000..20a2d37c --- /dev/null +++ b/afterburner/src/test/java/com/fasterxml/jackson/module/afterburner/util/failure/JacksonTestFailureExpected.java @@ -0,0 +1,37 @@ +package com.fasterxml.jackson.module.afterburner.util.failure; + +import java.lang.annotation.*; + +import org.junit.jupiter.api.extension.ExtendWith; + +/** + *

+ * Annotation used to indicate that a JUnit-5 based tests method is expected to fail. + * + *

+ * When a test method is annotated with {@code @JacksonTestFailureExpected}, the + * {@link JacksonTestFailureExpectedInterceptor} will intercept the test execution. + * If the test passes, which is an unexpected behavior, the interceptor will throw an exception to fail the test, + * indicating that the test was expected to fail but didn't. + *

+ * + *

Usage Example:

+ * + *

+ *
+ *     @Test
+ *     @JacksonTestFailureExpected
+ *     public void testFeatureNotYetImplemented() {
+ *         // Test code that is expected to fail
+ *     }
+ * }
+ * 
+ * + *

+ * + * @since 2.19 + */ +@Target({ElementType.METHOD}) +@Retention(RetentionPolicy.RUNTIME) +@ExtendWith(JacksonTestFailureExpectedInterceptor.class) +public @interface JacksonTestFailureExpected { } diff --git a/afterburner/src/test/java/com/fasterxml/jackson/module/afterburner/util/failure/JacksonTestFailureExpectedInterceptor.java b/afterburner/src/test/java/com/fasterxml/jackson/module/afterburner/util/failure/JacksonTestFailureExpectedInterceptor.java new file mode 100644 index 00000000..e07526ca --- /dev/null +++ b/afterburner/src/test/java/com/fasterxml/jackson/module/afterburner/util/failure/JacksonTestFailureExpectedInterceptor.java @@ -0,0 +1,43 @@ +package com.fasterxml.jackson.module.afterburner.util.failure; + +import java.lang.reflect.Method; + +import org.junit.jupiter.api.extension.*; + +/** + * Custom {@link InvocationInterceptor} that intercepts test method invocation. + * To pass the test ***only if*** test fails with an exception, and fail the test otherwise. + * + * @since 2.19 + */ +public class JacksonTestFailureExpectedInterceptor + implements InvocationInterceptor +{ + @Override + public void interceptTestMethod(Invocation invocation, + ReflectiveInvocationContext invocationContext, ExtensionContext extensionContext) + throws Throwable + { + try { + invocation.proceed(); + } catch (Throwable t) { + // do-nothing, we do expect an exception + return; + } + handleUnexpectePassingTest(invocationContext); + } + + private void handleUnexpectePassingTest(ReflectiveInvocationContext invocationContext) { + // Collect information we need + Object targetClass = invocationContext.getTargetClass(); + Object testMethod = invocationContext.getExecutable().getName(); + //List arguments = invocationContext.getArguments(); + + // Create message + String message = String.format("Test method %s.%s() passed, but should have failed", targetClass, testMethod); + + // throw exception + throw new JacksonTestShouldFailException(message); + } + +} diff --git a/afterburner/src/test/java/com/fasterxml/jackson/module/afterburner/util/failure/JacksonTestShouldFailException.java b/afterburner/src/test/java/com/fasterxml/jackson/module/afterburner/util/failure/JacksonTestShouldFailException.java new file mode 100644 index 00000000..f2d73e14 --- /dev/null +++ b/afterburner/src/test/java/com/fasterxml/jackson/module/afterburner/util/failure/JacksonTestShouldFailException.java @@ -0,0 +1,18 @@ +package com.fasterxml.jackson.module.afterburner.util.failure; + +/** + * Exception used to alert that a test is passing, but should be failing. + * + * WARNING : This only for test code, and should never be thrown from production code. + * + * @since 2.19 + */ +public class JacksonTestShouldFailException + extends RuntimeException +{ + private static final long serialVersionUID = 1L; + + public JacksonTestShouldFailException(String msg) { + super(msg); + } +} diff --git a/android-record/src/test/java/com/fasterxml/jackson/module/androidrecord/testutil/failure/JacksonTestFailureExpected.java b/android-record/src/test/java/com/fasterxml/jackson/module/androidrecord/testutil/failure/JacksonTestFailureExpected.java new file mode 100644 index 00000000..a354a4f8 --- /dev/null +++ b/android-record/src/test/java/com/fasterxml/jackson/module/androidrecord/testutil/failure/JacksonTestFailureExpected.java @@ -0,0 +1,37 @@ +package com.fasterxml.jackson.module.androidrecord.testutil.failure; + +import java.lang.annotation.*; + +import org.junit.jupiter.api.extension.ExtendWith; + +/** + *

+ * Annotation used to indicate that a JUnit-5 based tests method is expected to fail. + * + *

+ * When a test method is annotated with {@code @JacksonTestFailureExpected}, the + * {@link JacksonTestFailureExpectedInterceptor} will intercept the test execution. + * If the test passes, which is an unexpected behavior, the interceptor will throw an exception to fail the test, + * indicating that the test was expected to fail but didn't. + *

+ * + *

Usage Example:

+ * + *

+ *
+ *     @Test
+ *     @JacksonTestFailureExpected
+ *     public void testFeatureNotYetImplemented() {
+ *         // Test code that is expected to fail
+ *     }
+ * }
+ * 
+ * + *

+ * + * @since 2.19 + */ +@Target({ElementType.METHOD}) +@Retention(RetentionPolicy.RUNTIME) +@ExtendWith(JacksonTestFailureExpectedInterceptor.class) +public @interface JacksonTestFailureExpected { } diff --git a/android-record/src/test/java/com/fasterxml/jackson/module/androidrecord/testutil/failure/JacksonTestFailureExpectedInterceptor.java b/android-record/src/test/java/com/fasterxml/jackson/module/androidrecord/testutil/failure/JacksonTestFailureExpectedInterceptor.java new file mode 100644 index 00000000..4c6ee833 --- /dev/null +++ b/android-record/src/test/java/com/fasterxml/jackson/module/androidrecord/testutil/failure/JacksonTestFailureExpectedInterceptor.java @@ -0,0 +1,43 @@ +package com.fasterxml.jackson.module.androidrecord.testutil.failure; + +import java.lang.reflect.Method; + +import org.junit.jupiter.api.extension.*; + +/** + * Custom {@link InvocationInterceptor} that intercepts test method invocation. + * To pass the test ***only if*** test fails with an exception, and fail the test otherwise. + * + * @since 2.19 + */ +public class JacksonTestFailureExpectedInterceptor + implements InvocationInterceptor +{ + @Override + public void interceptTestMethod(Invocation invocation, + ReflectiveInvocationContext invocationContext, ExtensionContext extensionContext) + throws Throwable + { + try { + invocation.proceed(); + } catch (Throwable t) { + // do-nothing, we do expect an exception + return; + } + handleUnexpectePassingTest(invocationContext); + } + + private void handleUnexpectePassingTest(ReflectiveInvocationContext invocationContext) { + // Collect information we need + Object targetClass = invocationContext.getTargetClass(); + Object testMethod = invocationContext.getExecutable().getName(); + //List arguments = invocationContext.getArguments(); + + // Create message + String message = String.format("Test method %s.%s() passed, but should have failed", targetClass, testMethod); + + // throw exception + throw new JacksonTestShouldFailException(message); + } + +} diff --git a/android-record/src/test/java/com/fasterxml/jackson/module/androidrecord/testutil/failure/JacksonTestShouldFailException.java b/android-record/src/test/java/com/fasterxml/jackson/module/androidrecord/testutil/failure/JacksonTestShouldFailException.java new file mode 100644 index 00000000..193fee9f --- /dev/null +++ b/android-record/src/test/java/com/fasterxml/jackson/module/androidrecord/testutil/failure/JacksonTestShouldFailException.java @@ -0,0 +1,18 @@ +package com.fasterxml.jackson.module.androidrecord.testutil.failure; + +/** + * Exception used to alert that a test is passing, but should be failing. + * + * WARNING : This only for test code, and should never be thrown from production code. + * + * @since 2.19 + */ +public class JacksonTestShouldFailException + extends RuntimeException +{ + private static final long serialVersionUID = 1L; + + public JacksonTestShouldFailException(String msg) { + super(msg); + } +} diff --git a/blackbird/src/test/java/com/fasterxml/jackson/module/blackbird/testutil/failure/JacksonTestFailureExpected.java b/blackbird/src/test/java/com/fasterxml/jackson/module/blackbird/testutil/failure/JacksonTestFailureExpected.java new file mode 100644 index 00000000..520b3d57 --- /dev/null +++ b/blackbird/src/test/java/com/fasterxml/jackson/module/blackbird/testutil/failure/JacksonTestFailureExpected.java @@ -0,0 +1,37 @@ +package com.fasterxml.jackson.module.blackbird.testutil.failure; + +import java.lang.annotation.*; + +import org.junit.jupiter.api.extension.ExtendWith; + +/** + *

+ * Annotation used to indicate that a JUnit-5 based tests method is expected to fail. + * + *

+ * When a test method is annotated with {@code @JacksonTestFailureExpected}, the + * {@link JacksonTestFailureExpectedInterceptor} will intercept the test execution. + * If the test passes, which is an unexpected behavior, the interceptor will throw an exception to fail the test, + * indicating that the test was expected to fail but didn't. + *

+ * + *

Usage Example:

+ * + *

+ *
+ *     @Test
+ *     @JacksonTestFailureExpected
+ *     public void testFeatureNotYetImplemented() {
+ *         // Test code that is expected to fail
+ *     }
+ * }
+ * 
+ * + *

+ * + * @since 2.19 + */ +@Target({ElementType.METHOD}) +@Retention(RetentionPolicy.RUNTIME) +@ExtendWith(JacksonTestFailureExpectedInterceptor.class) +public @interface JacksonTestFailureExpected { } diff --git a/blackbird/src/test/java/com/fasterxml/jackson/module/blackbird/testutil/failure/JacksonTestFailureExpectedInterceptor.java b/blackbird/src/test/java/com/fasterxml/jackson/module/blackbird/testutil/failure/JacksonTestFailureExpectedInterceptor.java new file mode 100644 index 00000000..adcd8c07 --- /dev/null +++ b/blackbird/src/test/java/com/fasterxml/jackson/module/blackbird/testutil/failure/JacksonTestFailureExpectedInterceptor.java @@ -0,0 +1,43 @@ +package com.fasterxml.jackson.module.blackbird.testutil.failure; + +import java.lang.reflect.Method; + +import org.junit.jupiter.api.extension.*; + +/** + * Custom {@link InvocationInterceptor} that intercepts test method invocation. + * To pass the test ***only if*** test fails with an exception, and fail the test otherwise. + * + * @since 2.19 + */ +public class JacksonTestFailureExpectedInterceptor + implements InvocationInterceptor +{ + @Override + public void interceptTestMethod(Invocation invocation, + ReflectiveInvocationContext invocationContext, ExtensionContext extensionContext) + throws Throwable + { + try { + invocation.proceed(); + } catch (Throwable t) { + // do-nothing, we do expect an exception + return; + } + handleUnexpectePassingTest(invocationContext); + } + + private void handleUnexpectePassingTest(ReflectiveInvocationContext invocationContext) { + // Collect information we need + Object targetClass = invocationContext.getTargetClass(); + Object testMethod = invocationContext.getExecutable().getName(); + //List arguments = invocationContext.getArguments(); + + // Create message + String message = String.format("Test method %s.%s() passed, but should have failed", targetClass, testMethod); + + // throw exception + throw new JacksonTestShouldFailException(message); + } + +} diff --git a/blackbird/src/test/java/com/fasterxml/jackson/module/blackbird/testutil/failure/JacksonTestShouldFailException.java b/blackbird/src/test/java/com/fasterxml/jackson/module/blackbird/testutil/failure/JacksonTestShouldFailException.java new file mode 100644 index 00000000..a8f1ebd4 --- /dev/null +++ b/blackbird/src/test/java/com/fasterxml/jackson/module/blackbird/testutil/failure/JacksonTestShouldFailException.java @@ -0,0 +1,18 @@ +package com.fasterxml.jackson.module.blackbird.testutil.failure; + +/** + * Exception used to alert that a test is passing, but should be failing. + * + * WARNING : This only for test code, and should never be thrown from production code. + * + * @since 2.19 + */ +public class JacksonTestShouldFailException + extends RuntimeException +{ + private static final long serialVersionUID = 1L; + + public JacksonTestShouldFailException(String msg) { + super(msg); + } +} diff --git a/jakarta-xmlbind/src/test/java/com/fasterxml/jackson/module/jakarta/xmlbind/testutil/failure/JacksonTestFailureExpected.java b/jakarta-xmlbind/src/test/java/com/fasterxml/jackson/module/jakarta/xmlbind/testutil/failure/JacksonTestFailureExpected.java new file mode 100644 index 00000000..f489f999 --- /dev/null +++ b/jakarta-xmlbind/src/test/java/com/fasterxml/jackson/module/jakarta/xmlbind/testutil/failure/JacksonTestFailureExpected.java @@ -0,0 +1,37 @@ +package com.fasterxml.jackson.module.jakarta.xmlbind.testutil.failure; + +import java.lang.annotation.*; + +import org.junit.jupiter.api.extension.ExtendWith; + +/** + *

+ * Annotation used to indicate that a JUnit-5 based tests method is expected to fail. + * + *

+ * When a test method is annotated with {@code @JacksonTestFailureExpected}, the + * {@link JacksonTestFailureExpectedInterceptor} will intercept the test execution. + * If the test passes, which is an unexpected behavior, the interceptor will throw an exception to fail the test, + * indicating that the test was expected to fail but didn't. + *

+ * + *

Usage Example:

+ * + *

+ *
+ *     @Test
+ *     @JacksonTestFailureExpected
+ *     public void testFeatureNotYetImplemented() {
+ *         // Test code that is expected to fail
+ *     }
+ * }
+ * 
+ * + *

+ * + * @since 2.19 + */ +@Target({ElementType.METHOD}) +@Retention(RetentionPolicy.RUNTIME) +@ExtendWith(JacksonTestFailureExpectedInterceptor.class) +public @interface JacksonTestFailureExpected { } diff --git a/jakarta-xmlbind/src/test/java/com/fasterxml/jackson/module/jakarta/xmlbind/testutil/failure/JacksonTestFailureExpectedInterceptor.java b/jakarta-xmlbind/src/test/java/com/fasterxml/jackson/module/jakarta/xmlbind/testutil/failure/JacksonTestFailureExpectedInterceptor.java new file mode 100644 index 00000000..b23aa827 --- /dev/null +++ b/jakarta-xmlbind/src/test/java/com/fasterxml/jackson/module/jakarta/xmlbind/testutil/failure/JacksonTestFailureExpectedInterceptor.java @@ -0,0 +1,43 @@ +package com.fasterxml.jackson.module.jakarta.xmlbind.testutil.failure; + +import java.lang.reflect.Method; + +import org.junit.jupiter.api.extension.*; + +/** + * Custom {@link InvocationInterceptor} that intercepts test method invocation. + * To pass the test ***only if*** test fails with an exception, and fail the test otherwise. + * + * @since 2.19 + */ +public class JacksonTestFailureExpectedInterceptor + implements InvocationInterceptor +{ + @Override + public void interceptTestMethod(Invocation invocation, + ReflectiveInvocationContext invocationContext, ExtensionContext extensionContext) + throws Throwable + { + try { + invocation.proceed(); + } catch (Throwable t) { + // do-nothing, we do expect an exception + return; + } + handleUnexpectePassingTest(invocationContext); + } + + private void handleUnexpectePassingTest(ReflectiveInvocationContext invocationContext) { + // Collect information we need + Object targetClass = invocationContext.getTargetClass(); + Object testMethod = invocationContext.getExecutable().getName(); + //List arguments = invocationContext.getArguments(); + + // Create message + String message = String.format("Test method %s.%s() passed, but should have failed", targetClass, testMethod); + + // throw exception + throw new JacksonTestShouldFailException(message); + } + +} diff --git a/jakarta-xmlbind/src/test/java/com/fasterxml/jackson/module/jakarta/xmlbind/testutil/failure/JacksonTestShouldFailException.java b/jakarta-xmlbind/src/test/java/com/fasterxml/jackson/module/jakarta/xmlbind/testutil/failure/JacksonTestShouldFailException.java new file mode 100644 index 00000000..855b7cc6 --- /dev/null +++ b/jakarta-xmlbind/src/test/java/com/fasterxml/jackson/module/jakarta/xmlbind/testutil/failure/JacksonTestShouldFailException.java @@ -0,0 +1,18 @@ +package com.fasterxml.jackson.module.jakarta.xmlbind.testutil.failure; + +/** + * Exception used to alert that a test is passing, but should be failing. + * + * WARNING : This only for test code, and should never be thrown from production code. + * + * @since 2.19 + */ +public class JacksonTestShouldFailException + extends RuntimeException +{ + private static final long serialVersionUID = 1L; + + public JacksonTestShouldFailException(String msg) { + super(msg); + } +} diff --git a/jaxb/src/test/java/com/fasterxml/jackson/module/jaxb/testutil/failure/JacksonTestFailureExpected.java b/jaxb/src/test/java/com/fasterxml/jackson/module/jaxb/testutil/failure/JacksonTestFailureExpected.java new file mode 100644 index 00000000..849fd744 --- /dev/null +++ b/jaxb/src/test/java/com/fasterxml/jackson/module/jaxb/testutil/failure/JacksonTestFailureExpected.java @@ -0,0 +1,37 @@ +package com.fasterxml.jackson.module.jaxb.testutil.failure; + +import java.lang.annotation.*; + +import org.junit.jupiter.api.extension.ExtendWith; + +/** + *

+ * Annotation used to indicate that a JUnit-5 based tests method is expected to fail. + * + *

+ * When a test method is annotated with {@code @JacksonTestFailureExpected}, the + * {@link JacksonTestFailureExpectedInterceptor} will intercept the test execution. + * If the test passes, which is an unexpected behavior, the interceptor will throw an exception to fail the test, + * indicating that the test was expected to fail but didn't. + *

+ * + *

Usage Example:

+ * + *

+ *
+ *     @Test
+ *     @JacksonTestFailureExpected
+ *     public void testFeatureNotYetImplemented() {
+ *         // Test code that is expected to fail
+ *     }
+ * }
+ * 
+ * + *

+ * + * @since 2.19 + */ +@Target({ElementType.METHOD}) +@Retention(RetentionPolicy.RUNTIME) +@ExtendWith(JacksonTestFailureExpectedInterceptor.class) +public @interface JacksonTestFailureExpected { } diff --git a/jaxb/src/test/java/com/fasterxml/jackson/module/jaxb/testutil/failure/JacksonTestFailureExpectedInterceptor.java b/jaxb/src/test/java/com/fasterxml/jackson/module/jaxb/testutil/failure/JacksonTestFailureExpectedInterceptor.java new file mode 100644 index 00000000..6b4308f0 --- /dev/null +++ b/jaxb/src/test/java/com/fasterxml/jackson/module/jaxb/testutil/failure/JacksonTestFailureExpectedInterceptor.java @@ -0,0 +1,43 @@ +package com.fasterxml.jackson.module.jaxb.testutil.failure; + +import java.lang.reflect.Method; + +import org.junit.jupiter.api.extension.*; + +/** + * Custom {@link InvocationInterceptor} that intercepts test method invocation. + * To pass the test ***only if*** test fails with an exception, and fail the test otherwise. + * + * @since 2.19 + */ +public class JacksonTestFailureExpectedInterceptor + implements InvocationInterceptor +{ + @Override + public void interceptTestMethod(Invocation invocation, + ReflectiveInvocationContext invocationContext, ExtensionContext extensionContext) + throws Throwable + { + try { + invocation.proceed(); + } catch (Throwable t) { + // do-nothing, we do expect an exception + return; + } + handleUnexpectePassingTest(invocationContext); + } + + private void handleUnexpectePassingTest(ReflectiveInvocationContext invocationContext) { + // Collect information we need + Object targetClass = invocationContext.getTargetClass(); + Object testMethod = invocationContext.getExecutable().getName(); + //List arguments = invocationContext.getArguments(); + + // Create message + String message = String.format("Test method %s.%s() passed, but should have failed", targetClass, testMethod); + + // throw exception + throw new JacksonTestShouldFailException(message); + } + +} diff --git a/jaxb/src/test/java/com/fasterxml/jackson/module/jaxb/testutil/failure/JacksonTestShouldFailException.java b/jaxb/src/test/java/com/fasterxml/jackson/module/jaxb/testutil/failure/JacksonTestShouldFailException.java new file mode 100644 index 00000000..e259aecd --- /dev/null +++ b/jaxb/src/test/java/com/fasterxml/jackson/module/jaxb/testutil/failure/JacksonTestShouldFailException.java @@ -0,0 +1,18 @@ +package com.fasterxml.jackson.module.jaxb.testutil.failure; + +/** + * Exception used to alert that a test is passing, but should be failing. + * + * WARNING : This only for test code, and should never be thrown from production code. + * + * @since 2.19 + */ +public class JacksonTestShouldFailException + extends RuntimeException +{ + private static final long serialVersionUID = 1L; + + public JacksonTestShouldFailException(String msg) { + super(msg); + } +} diff --git a/paranamer/src/test/java/com/fasterxml/jackson/module/paranamer/testutil/failure/JacksonTestFailureExpected.java b/paranamer/src/test/java/com/fasterxml/jackson/module/paranamer/testutil/failure/JacksonTestFailureExpected.java new file mode 100644 index 00000000..764c7ca3 --- /dev/null +++ b/paranamer/src/test/java/com/fasterxml/jackson/module/paranamer/testutil/failure/JacksonTestFailureExpected.java @@ -0,0 +1,37 @@ +package com.fasterxml.jackson.module.paranamer.testutil.failure; + +import java.lang.annotation.*; + +import org.junit.jupiter.api.extension.ExtendWith; + +/** + *

+ * Annotation used to indicate that a JUnit-5 based tests method is expected to fail. + * + *

+ * When a test method is annotated with {@code @JacksonTestFailureExpected}, the + * {@link JacksonTestFailureExpectedInterceptor} will intercept the test execution. + * If the test passes, which is an unexpected behavior, the interceptor will throw an exception to fail the test, + * indicating that the test was expected to fail but didn't. + *

+ * + *

Usage Example:

+ * + *

+ *
+ *     @Test
+ *     @JacksonTestFailureExpected
+ *     public void testFeatureNotYetImplemented() {
+ *         // Test code that is expected to fail
+ *     }
+ * }
+ * 
+ * + *

+ * + * @since 2.19 + */ +@Target({ElementType.METHOD}) +@Retention(RetentionPolicy.RUNTIME) +@ExtendWith(JacksonTestFailureExpectedInterceptor.class) +public @interface JacksonTestFailureExpected { } diff --git a/paranamer/src/test/java/com/fasterxml/jackson/module/paranamer/testutil/failure/JacksonTestFailureExpectedInterceptor.java b/paranamer/src/test/java/com/fasterxml/jackson/module/paranamer/testutil/failure/JacksonTestFailureExpectedInterceptor.java new file mode 100644 index 00000000..3ead7da0 --- /dev/null +++ b/paranamer/src/test/java/com/fasterxml/jackson/module/paranamer/testutil/failure/JacksonTestFailureExpectedInterceptor.java @@ -0,0 +1,43 @@ +package com.fasterxml.jackson.module.paranamer.testutil.failure; + +import java.lang.reflect.Method; + +import org.junit.jupiter.api.extension.*; + +/** + * Custom {@link InvocationInterceptor} that intercepts test method invocation. + * To pass the test ***only if*** test fails with an exception, and fail the test otherwise. + * + * @since 2.19 + */ +public class JacksonTestFailureExpectedInterceptor + implements InvocationInterceptor +{ + @Override + public void interceptTestMethod(Invocation invocation, + ReflectiveInvocationContext invocationContext, ExtensionContext extensionContext) + throws Throwable + { + try { + invocation.proceed(); + } catch (Throwable t) { + // do-nothing, we do expect an exception + return; + } + handleUnexpectePassingTest(invocationContext); + } + + private void handleUnexpectePassingTest(ReflectiveInvocationContext invocationContext) { + // Collect information we need + Object targetClass = invocationContext.getTargetClass(); + Object testMethod = invocationContext.getExecutable().getName(); + //List arguments = invocationContext.getArguments(); + + // Create message + String message = String.format("Test method %s.%s() passed, but should have failed", targetClass, testMethod); + + // throw exception + throw new JacksonTestShouldFailException(message); + } + +} diff --git a/paranamer/src/test/java/com/fasterxml/jackson/module/paranamer/testutil/failure/JacksonTestShouldFailException.java b/paranamer/src/test/java/com/fasterxml/jackson/module/paranamer/testutil/failure/JacksonTestShouldFailException.java new file mode 100644 index 00000000..4a54eeb1 --- /dev/null +++ b/paranamer/src/test/java/com/fasterxml/jackson/module/paranamer/testutil/failure/JacksonTestShouldFailException.java @@ -0,0 +1,18 @@ +package com.fasterxml.jackson.module.paranamer.testutil.failure; + +/** + * Exception used to alert that a test is passing, but should be failing. + * + * WARNING : This only for test code, and should never be thrown from production code. + * + * @since 2.19 + */ +public class JacksonTestShouldFailException + extends RuntimeException +{ + private static final long serialVersionUID = 1L; + + public JacksonTestShouldFailException(String msg) { + super(msg); + } +} From 10c7cdf4c077028a995e96f67dbe61fff1f79b92 Mon Sep 17 00:00:00 2001 From: "Kim, Joo Hyuk" Date: Sun, 19 Jan 2025 19:52:15 +0900 Subject: [PATCH 2/5] Move `failing` tests to `tofix` --- .../AfterburnerModuleJDKSerializability97Test.java | 4 +++- .../{failing => tofix}/RecordBasicsFailingTest.java | 4 +++- .../{failing => tofix}/RecordCreatorsFailingTest.java | 4 +++- .../blackbird/{failing => tofix}/TestClassloaders.java | 4 +++- .../module/jakarta/xmlbind/failing/TestUnwrapping.java | 2 ++ .../jackson/module/jakarta/xmlbind/failing/TestXmlID3.java | 2 ++ .../jackson/module/jaxb/{failing => tofix}/TestEnums256.java | 4 +++- .../module/jaxb/{failing => tofix}/TestUnwrapping.java | 4 +++- .../jackson/module/jaxb/{failing => tofix}/TestXmlID3.java | 4 +++- .../{failing => tofix}/TestCreatorWithNamingStrategy.java | 4 +++- pom.xml | 5 ----- 11 files changed, 28 insertions(+), 13 deletions(-) rename afterburner/src/test/java/com/fasterxml/jackson/module/afterburner/{failing => tofix}/AfterburnerModuleJDKSerializability97Test.java (92%) rename android-record/src/test/java/com/fasterxml/jackson/module/androidrecord/{failing => tofix}/RecordBasicsFailingTest.java (90%) rename android-record/src/test/java/com/fasterxml/jackson/module/androidrecord/{failing => tofix}/RecordCreatorsFailingTest.java (91%) rename blackbird/src/test/java/com/fasterxml/jackson/module/blackbird/{failing => tofix}/TestClassloaders.java (93%) rename jaxb/src/test/java/com/fasterxml/jackson/module/jaxb/{failing => tofix}/TestEnums256.java (88%) rename jaxb/src/test/java/com/fasterxml/jackson/module/jaxb/{failing => tofix}/TestUnwrapping.java (92%) rename jaxb/src/test/java/com/fasterxml/jackson/module/jaxb/{failing => tofix}/TestXmlID3.java (92%) rename paranamer/src/test/java/com/fasterxml/jackson/module/paranamer/{failing => tofix}/TestCreatorWithNamingStrategy.java (90%) diff --git a/afterburner/src/test/java/com/fasterxml/jackson/module/afterburner/failing/AfterburnerModuleJDKSerializability97Test.java b/afterburner/src/test/java/com/fasterxml/jackson/module/afterburner/tofix/AfterburnerModuleJDKSerializability97Test.java similarity index 92% rename from afterburner/src/test/java/com/fasterxml/jackson/module/afterburner/failing/AfterburnerModuleJDKSerializability97Test.java rename to afterburner/src/test/java/com/fasterxml/jackson/module/afterburner/tofix/AfterburnerModuleJDKSerializability97Test.java index c0bc9896..6e46e3df 100644 --- a/afterburner/src/test/java/com/fasterxml/jackson/module/afterburner/failing/AfterburnerModuleJDKSerializability97Test.java +++ b/afterburner/src/test/java/com/fasterxml/jackson/module/afterburner/tofix/AfterburnerModuleJDKSerializability97Test.java @@ -1,4 +1,4 @@ -package com.fasterxml.jackson.module.afterburner.failing; +package com.fasterxml.jackson.module.afterburner.tofix; import java.io.*; @@ -6,6 +6,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.module.afterburner.AfterburnerTestBase; +import com.fasterxml.jackson.module.afterburner.util.failure.JacksonTestFailureExpected; import static org.junit.jupiter.api.Assertions.*; @@ -16,6 +17,7 @@ static class Point { } // But also test that after light use, ser/deser works + @JacksonTestFailureExpected @Test public void testMapperAfterUse() throws Exception { diff --git a/android-record/src/test/java/com/fasterxml/jackson/module/androidrecord/failing/RecordBasicsFailingTest.java b/android-record/src/test/java/com/fasterxml/jackson/module/androidrecord/tofix/RecordBasicsFailingTest.java similarity index 90% rename from android-record/src/test/java/com/fasterxml/jackson/module/androidrecord/failing/RecordBasicsFailingTest.java rename to android-record/src/test/java/com/fasterxml/jackson/module/androidrecord/tofix/RecordBasicsFailingTest.java index e9a34305..0516b026 100644 --- a/android-record/src/test/java/com/fasterxml/jackson/module/androidrecord/failing/RecordBasicsFailingTest.java +++ b/android-record/src/test/java/com/fasterxml/jackson/module/androidrecord/tofix/RecordBasicsFailingTest.java @@ -1,4 +1,4 @@ -package com.fasterxml.jackson.module.androidrecord.failing; +package com.fasterxml.jackson.module.androidrecord.tofix; import org.junit.jupiter.api.Test; @@ -9,6 +9,7 @@ import com.fasterxml.jackson.databind.*; import com.fasterxml.jackson.module.androidrecord.BaseMapTest; import com.fasterxml.jackson.module.androidrecord.RecordBasicsTest; +import com.fasterxml.jackson.module.androidrecord.testutil.failure.JacksonTestFailureExpected; import static org.junit.jupiter.api.Assertions.fail; @@ -45,6 +46,7 @@ public String name() { * * @see RecordBasicsTest#testDeserializeConstructorInjectRecord() */ + @JacksonTestFailureExpected @Test public void testDeserializeHeaderInjectRecord_WillFail() throws Exception { MAPPER.setInjectableValues(new InjectableValues.Std().addValue(String.class, "Bob")); diff --git a/android-record/src/test/java/com/fasterxml/jackson/module/androidrecord/failing/RecordCreatorsFailingTest.java b/android-record/src/test/java/com/fasterxml/jackson/module/androidrecord/tofix/RecordCreatorsFailingTest.java similarity index 91% rename from android-record/src/test/java/com/fasterxml/jackson/module/androidrecord/failing/RecordCreatorsFailingTest.java rename to android-record/src/test/java/com/fasterxml/jackson/module/androidrecord/tofix/RecordCreatorsFailingTest.java index 96bb8eb7..ee015b88 100644 --- a/android-record/src/test/java/com/fasterxml/jackson/module/androidrecord/failing/RecordCreatorsFailingTest.java +++ b/android-record/src/test/java/com/fasterxml/jackson/module/androidrecord/tofix/RecordCreatorsFailingTest.java @@ -1,4 +1,4 @@ -package com.fasterxml.jackson.module.androidrecord.failing; +package com.fasterxml.jackson.module.androidrecord.tofix; import org.junit.jupiter.api.Test; @@ -11,6 +11,7 @@ import com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException; import com.fasterxml.jackson.module.androidrecord.BaseMapTest; +import com.fasterxml.jackson.module.androidrecord.testutil.failure.JacksonTestFailureExpected; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.fail; @@ -50,6 +51,7 @@ public RecordWithAltCtor(@JsonProperty("id") int id) { */ // Fails: Implicit canonical constructor still works too + @JacksonTestFailureExpected @Test public void testDeserializeWithAltCtor() throws Exception { RecordWithAltCtor value = MAPPER.readValue("{\"id\":2812}", diff --git a/blackbird/src/test/java/com/fasterxml/jackson/module/blackbird/failing/TestClassloaders.java b/blackbird/src/test/java/com/fasterxml/jackson/module/blackbird/tofix/TestClassloaders.java similarity index 93% rename from blackbird/src/test/java/com/fasterxml/jackson/module/blackbird/failing/TestClassloaders.java rename to blackbird/src/test/java/com/fasterxml/jackson/module/blackbird/tofix/TestClassloaders.java index 8d78954c..9640d4b8 100644 --- a/blackbird/src/test/java/com/fasterxml/jackson/module/blackbird/failing/TestClassloaders.java +++ b/blackbird/src/test/java/com/fasterxml/jackson/module/blackbird/tofix/TestClassloaders.java @@ -1,4 +1,4 @@ -package com.fasterxml.jackson.module.blackbird.failing; +package com.fasterxml.jackson.module.blackbird.tofix; import java.io.ByteArrayOutputStream; import java.io.InputStream; @@ -8,6 +8,7 @@ import com.fasterxml.jackson.module.blackbird.BlackbirdTestBase; import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.module.blackbird.testutil.failure.JacksonTestFailureExpected; import static org.junit.jupiter.api.Assertions.*; @@ -19,6 +20,7 @@ public class TestClassloaders extends BlackbirdTestBase // Note: this test always passes in Java 8, even if the issue is not fixed, // so it is duplicated in jackson-jdk11-compat-test for now + @JacksonTestFailureExpected @Test public void testLoadInChildClassloader() throws Exception { TestLoader loader = new TestLoader(getClass().getClassLoader()); diff --git a/jakarta-xmlbind/src/test/java/com/fasterxml/jackson/module/jakarta/xmlbind/failing/TestUnwrapping.java b/jakarta-xmlbind/src/test/java/com/fasterxml/jackson/module/jakarta/xmlbind/failing/TestUnwrapping.java index 1b6e2a2f..693a34ec 100644 --- a/jakarta-xmlbind/src/test/java/com/fasterxml/jackson/module/jakarta/xmlbind/failing/TestUnwrapping.java +++ b/jakarta-xmlbind/src/test/java/com/fasterxml/jackson/module/jakarta/xmlbind/failing/TestUnwrapping.java @@ -12,6 +12,7 @@ import com.fasterxml.jackson.module.jakarta.xmlbind.JakartaXmlBindAnnotationIntrospector; import com.fasterxml.jackson.module.jakarta.xmlbind.ModuleTestBase; +import com.fasterxml.jackson.module.jakarta.xmlbind.testutil.failure.JacksonTestFailureExpected; import static org.junit.jupiter.api.Assertions.*; @@ -57,6 +58,7 @@ public B(String type) { */ // not asserting anything + @JacksonTestFailureExpected @Test public void testXmlElementAndXmlElementRefs() throws Exception { diff --git a/jakarta-xmlbind/src/test/java/com/fasterxml/jackson/module/jakarta/xmlbind/failing/TestXmlID3.java b/jakarta-xmlbind/src/test/java/com/fasterxml/jackson/module/jakarta/xmlbind/failing/TestXmlID3.java index b3fa1632..bbac0aee 100644 --- a/jakarta-xmlbind/src/test/java/com/fasterxml/jackson/module/jakarta/xmlbind/failing/TestXmlID3.java +++ b/jakarta-xmlbind/src/test/java/com/fasterxml/jackson/module/jakarta/xmlbind/failing/TestXmlID3.java @@ -11,6 +11,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.module.jakarta.xmlbind.ModuleTestBase; +import com.fasterxml.jackson.module.jakarta.xmlbind.testutil.failure.JacksonTestFailureExpected; import static org.junit.jupiter.api.Assertions.*; @@ -50,6 +51,7 @@ static class HasIDList public HasID getParent() { return parent; } } + @JacksonTestFailureExpected @Test public void testIssue46() throws Exception { diff --git a/jaxb/src/test/java/com/fasterxml/jackson/module/jaxb/failing/TestEnums256.java b/jaxb/src/test/java/com/fasterxml/jackson/module/jaxb/tofix/TestEnums256.java similarity index 88% rename from jaxb/src/test/java/com/fasterxml/jackson/module/jaxb/failing/TestEnums256.java rename to jaxb/src/test/java/com/fasterxml/jackson/module/jaxb/tofix/TestEnums256.java index 20e418fe..6f0bb67c 100644 --- a/jaxb/src/test/java/com/fasterxml/jackson/module/jaxb/failing/TestEnums256.java +++ b/jaxb/src/test/java/com/fasterxml/jackson/module/jaxb/tofix/TestEnums256.java @@ -1,4 +1,4 @@ -package com.fasterxml.jackson.module.jaxb.failing; +package com.fasterxml.jackson.module.jaxb.tofix; import javax.xml.bind.annotation.*; import javax.xml.bind.annotation.adapters.*; @@ -7,6 +7,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.module.jaxb.BaseJaxbTest; +import com.fasterxml.jackson.module.jaxb.testutil.failure.JacksonTestFailureExpected; import static org.junit.jupiter.api.Assertions.*; @@ -44,6 +45,7 @@ public enum Code { private final ObjectMapper MAPPER = getJaxbMapper(); // [modules-base#256] + @JacksonTestFailureExpected @Test public void testEnumSerialize256() throws Exception { diff --git a/jaxb/src/test/java/com/fasterxml/jackson/module/jaxb/failing/TestUnwrapping.java b/jaxb/src/test/java/com/fasterxml/jackson/module/jaxb/tofix/TestUnwrapping.java similarity index 92% rename from jaxb/src/test/java/com/fasterxml/jackson/module/jaxb/failing/TestUnwrapping.java rename to jaxb/src/test/java/com/fasterxml/jackson/module/jaxb/tofix/TestUnwrapping.java index d6f7e138..d45d9d72 100644 --- a/jaxb/src/test/java/com/fasterxml/jackson/module/jaxb/failing/TestUnwrapping.java +++ b/jaxb/src/test/java/com/fasterxml/jackson/module/jaxb/tofix/TestUnwrapping.java @@ -1,4 +1,4 @@ -package com.fasterxml.jackson.module.jaxb.failing; +package com.fasterxml.jackson.module.jaxb.tofix; import javax.xml.bind.annotation.*; @@ -10,6 +10,7 @@ import com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector; import com.fasterxml.jackson.module.jaxb.BaseJaxbTest; import com.fasterxml.jackson.module.jaxb.JaxbAnnotationIntrospector; +import com.fasterxml.jackson.module.jaxb.testutil.failure.JacksonTestFailureExpected; import static org.junit.jupiter.api.Assertions.*; @@ -55,6 +56,7 @@ public B(String type) { */ // not asserting anything + @JacksonTestFailureExpected @Test public void testXmlElementAndXmlElementRefs() throws Exception { diff --git a/jaxb/src/test/java/com/fasterxml/jackson/module/jaxb/failing/TestXmlID3.java b/jaxb/src/test/java/com/fasterxml/jackson/module/jaxb/tofix/TestXmlID3.java similarity index 92% rename from jaxb/src/test/java/com/fasterxml/jackson/module/jaxb/failing/TestXmlID3.java rename to jaxb/src/test/java/com/fasterxml/jackson/module/jaxb/tofix/TestXmlID3.java index 4cb0414d..7bf5824f 100644 --- a/jaxb/src/test/java/com/fasterxml/jackson/module/jaxb/failing/TestXmlID3.java +++ b/jaxb/src/test/java/com/fasterxml/jackson/module/jaxb/tofix/TestXmlID3.java @@ -1,4 +1,4 @@ -package com.fasterxml.jackson.module.jaxb.failing; +package com.fasterxml.jackson.module.jaxb.tofix; import java.util.Arrays; import java.util.List; @@ -10,6 +10,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.module.jaxb.BaseJaxbTest; +import com.fasterxml.jackson.module.jaxb.testutil.failure.JacksonTestFailureExpected; import static org.junit.jupiter.api.Assertions.*; @@ -49,6 +50,7 @@ static class HasIDList public HasID getParent() { return parent; } } + @JacksonTestFailureExpected @Test public void testIssue46() throws Exception { diff --git a/paranamer/src/test/java/com/fasterxml/jackson/module/paranamer/failing/TestCreatorWithNamingStrategy.java b/paranamer/src/test/java/com/fasterxml/jackson/module/paranamer/tofix/TestCreatorWithNamingStrategy.java similarity index 90% rename from paranamer/src/test/java/com/fasterxml/jackson/module/paranamer/failing/TestCreatorWithNamingStrategy.java rename to paranamer/src/test/java/com/fasterxml/jackson/module/paranamer/tofix/TestCreatorWithNamingStrategy.java index 8584b9a8..86139ae2 100644 --- a/paranamer/src/test/java/com/fasterxml/jackson/module/paranamer/failing/TestCreatorWithNamingStrategy.java +++ b/paranamer/src/test/java/com/fasterxml/jackson/module/paranamer/tofix/TestCreatorWithNamingStrategy.java @@ -1,4 +1,4 @@ -package com.fasterxml.jackson.module.paranamer.failing; +package com.fasterxml.jackson.module.paranamer.tofix; import org.junit.jupiter.api.Test; @@ -7,6 +7,7 @@ import com.fasterxml.jackson.databind.PropertyNamingStrategies; import com.fasterxml.jackson.module.paranamer.ParanamerModule; import com.fasterxml.jackson.module.paranamer.ModuleTestBase; +import com.fasterxml.jackson.module.paranamer.testutil.failure.JacksonTestFailureExpected; import static org.junit.jupiter.api.Assertions.*; @@ -40,6 +41,7 @@ public static StaticStringCreatorBean parse(String delimited) .registerModule(new ParanamerModule()) .setPropertyNamingStrategy(PropertyNamingStrategies.UPPER_CAMEL_CASE); + @JacksonTestFailureExpected @Test public void testStaticStringCreator() throws Exception { diff --git a/pom.xml b/pom.xml index 5485fd6e..762f4d98 100644 --- a/pom.xml +++ b/pom.xml @@ -115,11 +115,6 @@ not datatype, data format, or JAX-RS provider modules. org.apache.maven.plugins maven-surefire-plugin - - - com/fasterxml/jackson/**/failing/*.java - - From e7134a8b6bbab39ac6073b5832fb8745ad2fdb92 Mon Sep 17 00:00:00 2001 From: "Kim, Joo Hyuk" Date: Sun, 19 Jan 2025 19:55:27 +0900 Subject: [PATCH 3/5] Move one test out of tofix --- .../module/blackbird/{tofix => }/TestClassloaders.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) rename blackbird/src/test/java/com/fasterxml/jackson/module/blackbird/{tofix => }/TestClassloaders.java (91%) diff --git a/blackbird/src/test/java/com/fasterxml/jackson/module/blackbird/tofix/TestClassloaders.java b/blackbird/src/test/java/com/fasterxml/jackson/module/blackbird/TestClassloaders.java similarity index 91% rename from blackbird/src/test/java/com/fasterxml/jackson/module/blackbird/tofix/TestClassloaders.java rename to blackbird/src/test/java/com/fasterxml/jackson/module/blackbird/TestClassloaders.java index 9640d4b8..86713ffa 100644 --- a/blackbird/src/test/java/com/fasterxml/jackson/module/blackbird/tofix/TestClassloaders.java +++ b/blackbird/src/test/java/com/fasterxml/jackson/module/blackbird/TestClassloaders.java @@ -1,4 +1,4 @@ -package com.fasterxml.jackson.module.blackbird.tofix; +package com.fasterxml.jackson.module.blackbird; import java.io.ByteArrayOutputStream; import java.io.InputStream; @@ -6,9 +6,7 @@ import org.junit.jupiter.api.Test; -import com.fasterxml.jackson.module.blackbird.BlackbirdTestBase; import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.module.blackbird.testutil.failure.JacksonTestFailureExpected; import static org.junit.jupiter.api.Assertions.*; @@ -20,7 +18,6 @@ public class TestClassloaders extends BlackbirdTestBase // Note: this test always passes in Java 8, even if the issue is not fixed, // so it is duplicated in jackson-jdk11-compat-test for now - @JacksonTestFailureExpected @Test public void testLoadInChildClassloader() throws Exception { TestLoader loader = new TestLoader(getClass().getClassLoader()); From d3f00ec884dac327fb69754bcda49c88f6873285 Mon Sep 17 00:00:00 2001 From: "Kim, Joo Hyuk" Date: Sun, 19 Jan 2025 19:55:45 +0900 Subject: [PATCH 4/5] Clean up more --- .../failure/JacksonTestFailureExpected.java | 37 ---------------- ...JacksonTestFailureExpectedInterceptor.java | 43 ------------------- .../JacksonTestShouldFailException.java | 18 -------- 3 files changed, 98 deletions(-) delete mode 100644 blackbird/src/test/java/com/fasterxml/jackson/module/blackbird/testutil/failure/JacksonTestFailureExpected.java delete mode 100644 blackbird/src/test/java/com/fasterxml/jackson/module/blackbird/testutil/failure/JacksonTestFailureExpectedInterceptor.java delete mode 100644 blackbird/src/test/java/com/fasterxml/jackson/module/blackbird/testutil/failure/JacksonTestShouldFailException.java diff --git a/blackbird/src/test/java/com/fasterxml/jackson/module/blackbird/testutil/failure/JacksonTestFailureExpected.java b/blackbird/src/test/java/com/fasterxml/jackson/module/blackbird/testutil/failure/JacksonTestFailureExpected.java deleted file mode 100644 index 520b3d57..00000000 --- a/blackbird/src/test/java/com/fasterxml/jackson/module/blackbird/testutil/failure/JacksonTestFailureExpected.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.fasterxml.jackson.module.blackbird.testutil.failure; - -import java.lang.annotation.*; - -import org.junit.jupiter.api.extension.ExtendWith; - -/** - *

- * Annotation used to indicate that a JUnit-5 based tests method is expected to fail. - * - *

- * When a test method is annotated with {@code @JacksonTestFailureExpected}, the - * {@link JacksonTestFailureExpectedInterceptor} will intercept the test execution. - * If the test passes, which is an unexpected behavior, the interceptor will throw an exception to fail the test, - * indicating that the test was expected to fail but didn't. - *

- * - *

Usage Example:

- * - *

- *
- *     @Test
- *     @JacksonTestFailureExpected
- *     public void testFeatureNotYetImplemented() {
- *         // Test code that is expected to fail
- *     }
- * }
- * 
- * - *

- * - * @since 2.19 - */ -@Target({ElementType.METHOD}) -@Retention(RetentionPolicy.RUNTIME) -@ExtendWith(JacksonTestFailureExpectedInterceptor.class) -public @interface JacksonTestFailureExpected { } diff --git a/blackbird/src/test/java/com/fasterxml/jackson/module/blackbird/testutil/failure/JacksonTestFailureExpectedInterceptor.java b/blackbird/src/test/java/com/fasterxml/jackson/module/blackbird/testutil/failure/JacksonTestFailureExpectedInterceptor.java deleted file mode 100644 index adcd8c07..00000000 --- a/blackbird/src/test/java/com/fasterxml/jackson/module/blackbird/testutil/failure/JacksonTestFailureExpectedInterceptor.java +++ /dev/null @@ -1,43 +0,0 @@ -package com.fasterxml.jackson.module.blackbird.testutil.failure; - -import java.lang.reflect.Method; - -import org.junit.jupiter.api.extension.*; - -/** - * Custom {@link InvocationInterceptor} that intercepts test method invocation. - * To pass the test ***only if*** test fails with an exception, and fail the test otherwise. - * - * @since 2.19 - */ -public class JacksonTestFailureExpectedInterceptor - implements InvocationInterceptor -{ - @Override - public void interceptTestMethod(Invocation invocation, - ReflectiveInvocationContext invocationContext, ExtensionContext extensionContext) - throws Throwable - { - try { - invocation.proceed(); - } catch (Throwable t) { - // do-nothing, we do expect an exception - return; - } - handleUnexpectePassingTest(invocationContext); - } - - private void handleUnexpectePassingTest(ReflectiveInvocationContext invocationContext) { - // Collect information we need - Object targetClass = invocationContext.getTargetClass(); - Object testMethod = invocationContext.getExecutable().getName(); - //List arguments = invocationContext.getArguments(); - - // Create message - String message = String.format("Test method %s.%s() passed, but should have failed", targetClass, testMethod); - - // throw exception - throw new JacksonTestShouldFailException(message); - } - -} diff --git a/blackbird/src/test/java/com/fasterxml/jackson/module/blackbird/testutil/failure/JacksonTestShouldFailException.java b/blackbird/src/test/java/com/fasterxml/jackson/module/blackbird/testutil/failure/JacksonTestShouldFailException.java deleted file mode 100644 index a8f1ebd4..00000000 --- a/blackbird/src/test/java/com/fasterxml/jackson/module/blackbird/testutil/failure/JacksonTestShouldFailException.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.fasterxml.jackson.module.blackbird.testutil.failure; - -/** - * Exception used to alert that a test is passing, but should be failing. - * - * WARNING : This only for test code, and should never be thrown from production code. - * - * @since 2.19 - */ -public class JacksonTestShouldFailException - extends RuntimeException -{ - private static final long serialVersionUID = 1L; - - public JacksonTestShouldFailException(String msg) { - super(msg); - } -} From 83fc8fc4cd6d97bdb214994f4fad7f8020a26b2c Mon Sep 17 00:00:00 2001 From: "Kim, Joo Hyuk" Date: Sun, 19 Jan 2025 20:04:46 +0900 Subject: [PATCH 5/5] Another cleaning of now-passing tests --- ...va => TestCreatorWithNamingStrategy2.java} | 8 +--- .../failure/JacksonTestFailureExpected.java | 37 ---------------- ...JacksonTestFailureExpectedInterceptor.java | 43 ------------------- .../JacksonTestShouldFailException.java | 18 -------- 4 files changed, 2 insertions(+), 104 deletions(-) rename paranamer/src/test/java/com/fasterxml/jackson/module/paranamer/{tofix/TestCreatorWithNamingStrategy.java => TestCreatorWithNamingStrategy2.java} (81%) delete mode 100644 paranamer/src/test/java/com/fasterxml/jackson/module/paranamer/testutil/failure/JacksonTestFailureExpected.java delete mode 100644 paranamer/src/test/java/com/fasterxml/jackson/module/paranamer/testutil/failure/JacksonTestFailureExpectedInterceptor.java delete mode 100644 paranamer/src/test/java/com/fasterxml/jackson/module/paranamer/testutil/failure/JacksonTestShouldFailException.java diff --git a/paranamer/src/test/java/com/fasterxml/jackson/module/paranamer/tofix/TestCreatorWithNamingStrategy.java b/paranamer/src/test/java/com/fasterxml/jackson/module/paranamer/TestCreatorWithNamingStrategy2.java similarity index 81% rename from paranamer/src/test/java/com/fasterxml/jackson/module/paranamer/tofix/TestCreatorWithNamingStrategy.java rename to paranamer/src/test/java/com/fasterxml/jackson/module/paranamer/TestCreatorWithNamingStrategy2.java index 86139ae2..9d2c4cd3 100644 --- a/paranamer/src/test/java/com/fasterxml/jackson/module/paranamer/tofix/TestCreatorWithNamingStrategy.java +++ b/paranamer/src/test/java/com/fasterxml/jackson/module/paranamer/TestCreatorWithNamingStrategy2.java @@ -1,17 +1,14 @@ -package com.fasterxml.jackson.module.paranamer.tofix; +package com.fasterxml.jackson.module.paranamer; import org.junit.jupiter.api.Test; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.PropertyNamingStrategies; -import com.fasterxml.jackson.module.paranamer.ParanamerModule; -import com.fasterxml.jackson.module.paranamer.ModuleTestBase; -import com.fasterxml.jackson.module.paranamer.testutil.failure.JacksonTestFailureExpected; import static org.junit.jupiter.api.Assertions.*; -public class TestCreatorWithNamingStrategy +public class TestCreatorWithNamingStrategy2 extends ModuleTestBase { static class StaticStringCreatorBean @@ -41,7 +38,6 @@ public static StaticStringCreatorBean parse(String delimited) .registerModule(new ParanamerModule()) .setPropertyNamingStrategy(PropertyNamingStrategies.UPPER_CAMEL_CASE); - @JacksonTestFailureExpected @Test public void testStaticStringCreator() throws Exception { diff --git a/paranamer/src/test/java/com/fasterxml/jackson/module/paranamer/testutil/failure/JacksonTestFailureExpected.java b/paranamer/src/test/java/com/fasterxml/jackson/module/paranamer/testutil/failure/JacksonTestFailureExpected.java deleted file mode 100644 index 764c7ca3..00000000 --- a/paranamer/src/test/java/com/fasterxml/jackson/module/paranamer/testutil/failure/JacksonTestFailureExpected.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.fasterxml.jackson.module.paranamer.testutil.failure; - -import java.lang.annotation.*; - -import org.junit.jupiter.api.extension.ExtendWith; - -/** - *

- * Annotation used to indicate that a JUnit-5 based tests method is expected to fail. - * - *

- * When a test method is annotated with {@code @JacksonTestFailureExpected}, the - * {@link JacksonTestFailureExpectedInterceptor} will intercept the test execution. - * If the test passes, which is an unexpected behavior, the interceptor will throw an exception to fail the test, - * indicating that the test was expected to fail but didn't. - *

- * - *

Usage Example:

- * - *

- *
- *     @Test
- *     @JacksonTestFailureExpected
- *     public void testFeatureNotYetImplemented() {
- *         // Test code that is expected to fail
- *     }
- * }
- * 
- * - *

- * - * @since 2.19 - */ -@Target({ElementType.METHOD}) -@Retention(RetentionPolicy.RUNTIME) -@ExtendWith(JacksonTestFailureExpectedInterceptor.class) -public @interface JacksonTestFailureExpected { } diff --git a/paranamer/src/test/java/com/fasterxml/jackson/module/paranamer/testutil/failure/JacksonTestFailureExpectedInterceptor.java b/paranamer/src/test/java/com/fasterxml/jackson/module/paranamer/testutil/failure/JacksonTestFailureExpectedInterceptor.java deleted file mode 100644 index 3ead7da0..00000000 --- a/paranamer/src/test/java/com/fasterxml/jackson/module/paranamer/testutil/failure/JacksonTestFailureExpectedInterceptor.java +++ /dev/null @@ -1,43 +0,0 @@ -package com.fasterxml.jackson.module.paranamer.testutil.failure; - -import java.lang.reflect.Method; - -import org.junit.jupiter.api.extension.*; - -/** - * Custom {@link InvocationInterceptor} that intercepts test method invocation. - * To pass the test ***only if*** test fails with an exception, and fail the test otherwise. - * - * @since 2.19 - */ -public class JacksonTestFailureExpectedInterceptor - implements InvocationInterceptor -{ - @Override - public void interceptTestMethod(Invocation invocation, - ReflectiveInvocationContext invocationContext, ExtensionContext extensionContext) - throws Throwable - { - try { - invocation.proceed(); - } catch (Throwable t) { - // do-nothing, we do expect an exception - return; - } - handleUnexpectePassingTest(invocationContext); - } - - private void handleUnexpectePassingTest(ReflectiveInvocationContext invocationContext) { - // Collect information we need - Object targetClass = invocationContext.getTargetClass(); - Object testMethod = invocationContext.getExecutable().getName(); - //List arguments = invocationContext.getArguments(); - - // Create message - String message = String.format("Test method %s.%s() passed, but should have failed", targetClass, testMethod); - - // throw exception - throw new JacksonTestShouldFailException(message); - } - -} diff --git a/paranamer/src/test/java/com/fasterxml/jackson/module/paranamer/testutil/failure/JacksonTestShouldFailException.java b/paranamer/src/test/java/com/fasterxml/jackson/module/paranamer/testutil/failure/JacksonTestShouldFailException.java deleted file mode 100644 index 4a54eeb1..00000000 --- a/paranamer/src/test/java/com/fasterxml/jackson/module/paranamer/testutil/failure/JacksonTestShouldFailException.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.fasterxml.jackson.module.paranamer.testutil.failure; - -/** - * Exception used to alert that a test is passing, but should be failing. - * - * WARNING : This only for test code, and should never be thrown from production code. - * - * @since 2.19 - */ -public class JacksonTestShouldFailException - extends RuntimeException -{ - private static final long serialVersionUID = 1L; - - public JacksonTestShouldFailException(String msg) { - super(msg); - } -}