Skip to content

Commit

Permalink
Apply code review
Browse files Browse the repository at this point in the history
  • Loading branch information
scordio committed Jul 16, 2023
1 parent e56a054 commit b878c90
Showing 1 changed file with 11 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -363,9 +363,9 @@ void supportsFactoryWithAnnotatedElementNameAsPrefix() {
}

@Test
@DisplayName("that uses custom annotation")
void supportsFactoryWithCustomAnnotation() {
executeTestsForClass(FactoryWithCustomAnnotationTestCase.class).testEvents()//
@DisplayName("that uses custom meta-annotation")
void supportsFactoryWithCustomMetaAnnotation() {
executeTestsForClass(FactoryWithCustomMetaAnnotationTestCase.class).testEvents()//
.assertStatistics(stats -> stats.started(1).succeeded(1));
}

Expand Down Expand Up @@ -1328,29 +1328,29 @@ private static String getName(AnnotatedElement element) {

}

static class FactoryWithCustomAnnotationTestCase {
static class FactoryWithCustomMetaAnnotationTestCase {

@Prefix("field")
@TempDir(factory = Factory.class)
@CustomTempDir("field")
private Path tempDir1;

private Path tempDir2;

@BeforeEach
void beforeEach(@Prefix("beforeEach") @TempDir(factory = Factory.class) Path tempDir2) {
void beforeEach(@CustomTempDir("beforeEach") Path tempDir2) {
this.tempDir2 = tempDir2;
}

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

@Target({ ANNOTATION_TYPE, FIELD, PARAMETER })
@Retention(RUNTIME)
private @interface Prefix {
@TempDir(factory = FactoryWithCustomMetaAnnotationTestCase.Factory.class)
private @interface CustomTempDir {

String value();

Expand All @@ -1361,7 +1361,8 @@ private static class Factory implements TempDirFactory {
@Override
public Path createTempDirectory(AnnotatedElementContext elementContext, ExtensionContext extensionContext)
throws Exception {
String prefix = elementContext.findAnnotation(Prefix.class).map(Prefix::value).orElseThrow();
String prefix = elementContext.findAnnotation(CustomTempDir.class).map(
CustomTempDir::value).orElseThrow();
return Files.createTempDirectory(prefix);
}

Expand Down

0 comments on commit b878c90

Please sign in to comment.