-
-
Notifications
You must be signed in to change notification settings - Fork 138
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ JSTEP-10 ] Add test dependencies (#548)
- Loading branch information
1 parent
163f423
commit 26b5e2a
Showing
16 changed files
with
507 additions
and
1 deletion.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
...va/com/fasterxml/jackson/dataformat/avro/testutil/failure/JacksonTestFailureExpected.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.fasterxml.jackson.dataformat.avro.testutil.failure; | ||
|
||
import java.lang.annotation.*; | ||
|
||
import org.junit.jupiter.api.extension.ExtendWith; | ||
|
||
/** | ||
* <p> | ||
* Annotation used to indicate that a JUnit-5 based tests method is expected to fail. | ||
* | ||
* <p> | ||
* 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. | ||
* </p> | ||
* | ||
* <h3>Usage Example:</h3> | ||
* | ||
* <pre><code> | ||
* | ||
* @Test | ||
* @JacksonTestFailureExpected | ||
* @Test | ||
public void testFeatureNotYetImplemented() { | ||
* // Test code that is expected to fail | ||
* } | ||
* } | ||
* </code></pre> | ||
* | ||
* <p> | ||
* | ||
* @since 2.19 | ||
*/ | ||
@Target({ElementType.METHOD}) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@ExtendWith(JacksonTestFailureExpectedInterceptor.class) | ||
public @interface JacksonTestFailureExpected { } |
43 changes: 43 additions & 0 deletions
43
...erxml/jackson/dataformat/avro/testutil/failure/JacksonTestFailureExpectedInterceptor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.fasterxml.jackson.dataformat.avro.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<Void> invocation, | ||
ReflectiveInvocationContext<Method> 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<Method> invocationContext) { | ||
// Collect information we need | ||
Object targetClass = invocationContext.getTargetClass(); | ||
Object testMethod = invocationContext.getExecutable().getName(); | ||
//List<Object> 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); | ||
} | ||
|
||
} |
18 changes: 18 additions & 0 deletions
18
...om/fasterxml/jackson/dataformat/avro/testutil/failure/JacksonTestShouldFailException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.fasterxml.jackson.dataformat.avro.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); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
...va/com/fasterxml/jackson/dataformat/cbor/testutil/failure/JacksonTestFailureExpected.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.fasterxml.jackson.dataformat.cbor.testutil.failure; | ||
|
||
import java.lang.annotation.*; | ||
|
||
import org.junit.jupiter.api.extension.ExtendWith; | ||
|
||
/** | ||
* <p> | ||
* Annotation used to indicate that a JUnit-5 based tests method is expected to fail. | ||
* | ||
* <p> | ||
* 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. | ||
* </p> | ||
* | ||
* <h3>Usage Example:</h3> | ||
* | ||
* <pre><code> | ||
* | ||
* @Test | ||
* @JacksonTestFailureExpected | ||
* @Test | ||
public void testFeatureNotYetImplemented() { | ||
* // Test code that is expected to fail | ||
* } | ||
* } | ||
* </code></pre> | ||
* | ||
* <p> | ||
* | ||
* @since 2.19 | ||
*/ | ||
@Target({ElementType.METHOD}) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@ExtendWith(JacksonTestFailureExpectedInterceptor.class) | ||
public @interface JacksonTestFailureExpected { } |
43 changes: 43 additions & 0 deletions
43
...erxml/jackson/dataformat/cbor/testutil/failure/JacksonTestFailureExpectedInterceptor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.fasterxml.jackson.dataformat.cbor.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<Void> invocation, | ||
ReflectiveInvocationContext<Method> 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<Method> invocationContext) { | ||
// Collect information we need | ||
Object targetClass = invocationContext.getTargetClass(); | ||
Object testMethod = invocationContext.getExecutable().getName(); | ||
//List<Object> 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); | ||
} | ||
|
||
} |
18 changes: 18 additions & 0 deletions
18
...om/fasterxml/jackson/dataformat/cbor/testutil/failure/JacksonTestShouldFailException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.fasterxml.jackson.dataformat.cbor.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); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
...ava/com/fasterxml/jackson/dataformat/ion/testutil/failure/JacksonTestFailureExpected.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.fasterxml.jackson.dataformat.ion.testutil.failure; | ||
|
||
import java.lang.annotation.*; | ||
|
||
import org.junit.jupiter.api.extension.ExtendWith; | ||
|
||
/** | ||
* <p> | ||
* Annotation used to indicate that a JUnit-5 based tests method is expected to fail. | ||
* | ||
* <p> | ||
* 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. | ||
* </p> | ||
* | ||
* <h3>Usage Example:</h3> | ||
* | ||
* <pre><code> | ||
* | ||
* @Test | ||
* @JacksonTestFailureExpected | ||
* @Test | ||
public void testFeatureNotYetImplemented() { | ||
* // Test code that is expected to fail | ||
* } | ||
* } | ||
* </code></pre> | ||
* | ||
* <p> | ||
* | ||
* @since 2.19 | ||
*/ | ||
@Target({ElementType.METHOD}) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@ExtendWith(JacksonTestFailureExpectedInterceptor.class) | ||
public @interface JacksonTestFailureExpected { } |
43 changes: 43 additions & 0 deletions
43
...terxml/jackson/dataformat/ion/testutil/failure/JacksonTestFailureExpectedInterceptor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.fasterxml.jackson.dataformat.ion.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<Void> invocation, | ||
ReflectiveInvocationContext<Method> 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<Method> invocationContext) { | ||
// Collect information we need | ||
Object targetClass = invocationContext.getTargetClass(); | ||
Object testMethod = invocationContext.getExecutable().getName(); | ||
//List<Object> 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); | ||
} | ||
|
||
} |
18 changes: 18 additions & 0 deletions
18
...com/fasterxml/jackson/dataformat/ion/testutil/failure/JacksonTestShouldFailException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.fasterxml.jackson.dataformat.ion.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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
...om/fasterxml/jackson/dataformat/protobuf/testutil/failure/JacksonTestFailureExpected.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.fasterxml.jackson.dataformat.protobuf.testutil.failure; | ||
|
||
import java.lang.annotation.*; | ||
|
||
import org.junit.jupiter.api.extension.ExtendWith; | ||
|
||
/** | ||
* <p> | ||
* Annotation used to indicate that a JUnit-5 based tests method is expected to fail. | ||
* | ||
* <p> | ||
* 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. | ||
* </p> | ||
* | ||
* <h3>Usage Example:</h3> | ||
* | ||
* <pre><code> | ||
* | ||
* @Test | ||
* @JacksonTestFailureExpected | ||
* @Test | ||
public void testFeatureNotYetImplemented() { | ||
* // Test code that is expected to fail | ||
* } | ||
* } | ||
* </code></pre> | ||
* | ||
* <p> | ||
* | ||
* @since 2.19 | ||
*/ | ||
@Target({ElementType.METHOD}) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@ExtendWith(JacksonTestFailureExpectedInterceptor.class) | ||
public @interface JacksonTestFailureExpected { } |
Oops, something went wrong.