Skip to content

Commit 526d72c

Browse files
committed
Merge branch '2.19'
2 parents ee6e748 + 744595e commit 526d72c

File tree

5 files changed

+103
-10
lines changed

5 files changed

+103
-10
lines changed

pom.xml

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ alternative support for serializing POJOs as XML and deserializing XML as pojos.
9292
<artifactId>junit</artifactId>
9393
<scope>test</scope>
9494
</dependency>
95-
<!-- 11-Jan-2025, joohyukkim: JSTEP-10, part 1, migrate to JUnit5 -->
96-
<!--
95+
96+
<!-- 11-Jan-2025, joohyukkim: For JSTEP-10, migrate to JUnit5 -->
9797
<dependency>
9898
<groupId>org.junit.jupiter</groupId>
9999
<artifactId>junit-jupiter</artifactId>
@@ -104,12 +104,6 @@ alternative support for serializing POJOs as XML and deserializing XML as pojos.
104104
<artifactId>junit-jupiter-api</artifactId>
105105
<scope>test</scope>
106106
</dependency>
107-
<dependency>
108-
<groupId>org.assertj</groupId>
109-
<artifactId>assertj-core</artifactId>
110-
<scope>test</scope>
111-
</dependency>
112-
-->
113107

114108
<!-- Jakarta XMLBind (nee javax/jaxb( annotation introspector is needed BUT ONLY
115109
for tests (starting 2.13: previously compile/runtime)

src/test/java/module-info.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212

1313
// Then test dependencies
1414
requires junit;
15-
//requires org.junit.jupiter.api;
16-
//requires org.junit.jupiter.params;
15+
requires org.junit.jupiter.api;
16+
requires org.junit.jupiter.params;
1717

1818
requires com.ctc.wstx; // woodstox
1919
requires jakarta.xml.bind; // Jakarta-binding
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package tools.jackson.dataformat.xml.testutil.failure;
2+
3+
import java.lang.annotation.*;
4+
5+
import org.junit.jupiter.api.extension.ExtendWith;
6+
7+
/**
8+
* <p>
9+
* Annotation used to indicate that a JUnit-5 based tests method is expected to fail.
10+
*
11+
* <p>
12+
* When a test method is annotated with {@code @JacksonTestFailureExpected}, the
13+
* {@link JacksonTestFailureExpectedInterceptor} will intercept the test execution.
14+
* If the test passes, which is an unexpected behavior, the interceptor will throw an exception to fail the test,
15+
* indicating that the test was expected to fail but didn't.
16+
* </p>
17+
*
18+
* <h3>Usage Example:</h3>
19+
*
20+
* <pre><code>
21+
*
22+
* &#64;Test
23+
* &#64;JacksonTestFailureExpected
24+
* @Test
25+
public void testFeatureNotYetImplemented() {
26+
* // Test code that is expected to fail
27+
* }
28+
* }
29+
* </code></pre>
30+
*
31+
* <p>
32+
*
33+
* @since 2.19
34+
*/
35+
@Target({ElementType.METHOD})
36+
@Retention(RetentionPolicy.RUNTIME)
37+
@ExtendWith(JacksonTestFailureExpectedInterceptor.class)
38+
public @interface JacksonTestFailureExpected { }
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package tools.jackson.dataformat.xml.testutil.failure;
2+
3+
import java.lang.reflect.Method;
4+
5+
import org.junit.jupiter.api.extension.*;
6+
7+
/**
8+
* Custom {@link InvocationInterceptor} that intercepts test method invocation.
9+
* To pass the test ***only if*** test fails with an exception, and fail the test otherwise.
10+
*
11+
* @since 2.19
12+
*/
13+
public class JacksonTestFailureExpectedInterceptor
14+
implements InvocationInterceptor
15+
{
16+
@Override
17+
public void interceptTestMethod(Invocation<Void> invocation,
18+
ReflectiveInvocationContext<Method> invocationContext, ExtensionContext extensionContext)
19+
throws Throwable
20+
{
21+
try {
22+
invocation.proceed();
23+
} catch (Throwable t) {
24+
// do-nothing, we do expect an exception
25+
return;
26+
}
27+
handleUnexpectePassingTest(invocationContext);
28+
}
29+
30+
private void handleUnexpectePassingTest(ReflectiveInvocationContext<Method> invocationContext) {
31+
// Collect information we need
32+
Object targetClass = invocationContext.getTargetClass();
33+
Object testMethod = invocationContext.getExecutable().getName();
34+
//List<Object> arguments = invocationContext.getArguments();
35+
36+
// Create message
37+
String message = String.format("Test method %s.%s() passed, but should have failed", targetClass, testMethod);
38+
39+
// throw exception
40+
throw new JacksonTestShouldFailException(message);
41+
}
42+
43+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package tools.jackson.dataformat.xml.testutil.failure;
2+
3+
/**
4+
* Exception used to alert that a test is passing, but should be failing.
5+
*
6+
* WARNING : This only for test code, and should never be thrown from production code.
7+
*
8+
* @since 2.19
9+
*/
10+
public class JacksonTestShouldFailException
11+
extends RuntimeException
12+
{
13+
private static final long serialVersionUID = 1L;
14+
15+
public JacksonTestShouldFailException(String msg) {
16+
super(msg);
17+
}
18+
}

0 commit comments

Comments
 (0)