Skip to content

Commit

Permalink
Enhance meta-annotation test case
Browse files Browse the repository at this point in the history
  • Loading branch information
scordio committed Jul 16, 2023
1 parent ae029a3 commit ea6d11d
Showing 1 changed file with 17 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1298,18 +1298,10 @@ static class FactoryWithAnnotatedElementNameAsPrefixTestCase {
@TempDir(factory = Factory.class)
private Path tempDir1;

private Path tempDir2;

@BeforeEach
void setUp(@TempDir(factory = Factory.class) Path tempDir2) {
this.tempDir2 = tempDir2;
}

@Test
void test(@TempDir(factory = Factory.class) Path tempDir3) {
void test(@TempDir(factory = Factory.class) Path tempDir2) {
assertThat(tempDir1.getFileName()).asString().startsWith("tempDir1");
assertThat(tempDir2.getFileName()).asString().startsWith("tempDir2");
assertThat(tempDir3.getFileName()).asString().startsWith("tempDir3");
}

private static class Factory implements TempDirFactory {
Expand All @@ -1330,24 +1322,16 @@ private static String getName(AnnotatedElement element) {

static class FactoryWithCustomMetaAnnotationTestCase {

@TempDirWithPrefix("field")
@TempDirForField
private Path tempDir1;

private Path tempDir2;

@BeforeEach
void beforeEach(@TempDirWithPrefix("beforeEach") Path tempDir2) {
this.tempDir2 = tempDir2;
}

@Test
void test(@TempDirWithPrefix("method") Path tempDir3) {
void test(@TempDirForParameter Path tempDir2) {
assertThat(tempDir1.getFileName()).asString().startsWith("field");
assertThat(tempDir2.getFileName()).asString().startsWith("beforeEach");
assertThat(tempDir3.getFileName()).asString().startsWith("method");
assertThat(tempDir2.getFileName()).asString().startsWith("parameter");
}

@Target({ ANNOTATION_TYPE, FIELD, PARAMETER })
@Target(ANNOTATION_TYPE)
@Retention(RUNTIME)
@TempDir(factory = FactoryWithCustomMetaAnnotationTestCase.Factory.class)
private @interface TempDirWithPrefix {
Expand All @@ -1356,6 +1340,18 @@ void test(@TempDirWithPrefix("method") Path tempDir3) {

}

@Target(FIELD)
@Retention(RUNTIME)
@TempDirWithPrefix("field")
private @interface TempDirForField {
}

@Target(PARAMETER)
@Retention(RUNTIME)
@TempDirWithPrefix("parameter")
private @interface TempDirForParameter {
}

private static class Factory implements TempDirFactory {

@Override
Expand Down

0 comments on commit ea6d11d

Please sign in to comment.