-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make sure that test callbacks always work on the proper test method
Fixes: #10623
- Loading branch information
Showing
4 changed files
with
105 additions
and
6 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
integration-tests/main/src/test/java/io/quarkus/it/main/QuarkusTestCallbacksTestCase.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,30 @@ | ||
package io.quarkus.it.main; | ||
|
||
import static java.lang.annotation.ElementType.METHOD; | ||
import static java.lang.annotation.RetentionPolicy.RUNTIME; | ||
|
||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.Target; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import io.quarkus.test.junit.QuarkusTest; | ||
|
||
/** | ||
* The purpose of this test is simply to ensure that {@link SimpleAnnotationCheckerBeforeEachCallback} | ||
* can read {@code @TestAnnotation} without issue | ||
*/ | ||
@QuarkusTest | ||
public class QuarkusTestCallbacksTestCase { | ||
|
||
@Test | ||
@TestAnnotation | ||
public void testTestMethodHasAnnotation() { | ||
|
||
} | ||
|
||
@Target({ METHOD }) | ||
@Retention(RUNTIME) | ||
public @interface TestAnnotation { | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
...ests/main/src/test/java/io/quarkus/it/main/SimpleAnnotationCheckerBeforeEachCallback.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,30 @@ | ||
package io.quarkus.it.main; | ||
|
||
import java.lang.reflect.Method; | ||
|
||
import io.quarkus.test.junit.callback.QuarkusTestBeforeEachCallback; | ||
import io.quarkus.test.junit.callback.QuarkusTestMethodContext; | ||
|
||
public class SimpleAnnotationCheckerBeforeEachCallback implements QuarkusTestBeforeEachCallback { | ||
|
||
@Override | ||
public void beforeEach(QuarkusTestMethodContext context) { | ||
// make sure that this comes into play only for the test we care about | ||
|
||
Method testMethod = context.getTestMethod(); | ||
if (!testMethod.getDeclaringClass().getName().endsWith("QuarkusTestCallbacksTestCase")) { | ||
return; | ||
} | ||
|
||
if (!testMethod.getName().equals("testTestMethodHasAnnotation")) { | ||
return; | ||
} | ||
|
||
QuarkusTestCallbacksTestCase.TestAnnotation annotation = testMethod | ||
.getAnnotation(QuarkusTestCallbacksTestCase.TestAnnotation.class); | ||
if (annotation == null) { | ||
throw new IllegalStateException( | ||
"Expected to find annotation @TestAnnotation on method test method testTestMethodHasAnnotation"); | ||
} | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
.../resources/META-INF/services/io.quarkus.test.junit.callback.QuarkusTestBeforeEachCallback
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 @@ | ||
io.quarkus.it.main.SimpleAnnotationCheckerBeforeEachCallback |
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