Skip to content

Commit 8afbb0c

Browse files
committed
Refactor IntegrationTestsSupport.asDirectoryName(:Class) logic into descriptive methods.
Adds the asTimestampedDirectoryName(:Class) and asUniqueDirectoryName(:Class) methods to uniquely and temporally identify a forked JVM (child) process (test) working directory.
1 parent 63f4849 commit 8afbb0c

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

spring-data-geode-test/src/main/java/org/springframework/data/gemfire/tests/integration/IntegrationTestsSupport.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
import java.util.function.Supplier;
4141
import java.util.stream.Collectors;
4242

43+
import com.sun.istack.NotNull;
44+
4345
import org.junit.AfterClass;
4446
import org.junit.Before;
4547

@@ -512,11 +514,7 @@ public static void stopGemFireLocatorWaitOnStopEvent(long duration) {
512514
}
513515

514516
protected static @NonNull String asDirectoryName(@NonNull Class<?> type) {
515-
516-
String baseDirectoryName = String.format(DIRECTORY_NAME_FORMAT, asQualifiedDirectoryName(type),
517-
LocalDateTime.now().format(DateTimeFormatter.ofPattern(DATE_TIME_PATTERN)));
518-
519-
return baseDirectoryName.concat(File.separator).concat(UUID.randomUUID().toString());
517+
return asUniqueDirectoryName(type);
520518
}
521519

522520
private static @NonNull String asQualifiedDirectoryName(@NonNull Class<?> type) {
@@ -533,6 +531,15 @@ public static void stopGemFireLocatorWaitOnStopEvent(long duration) {
533531
return qualifiedDirectoryName;
534532
}
535533

534+
private static @NotNull String asTimestampedDirectoryName(@NonNull Class<?> type) {
535+
return String.format(DIRECTORY_NAME_FORMAT, asQualifiedDirectoryName(type),
536+
LocalDateTime.now().format(DateTimeFormatter.ofPattern(DATE_TIME_PATTERN)));
537+
}
538+
539+
private static @NotNull String asUniqueDirectoryName(@NonNull Class<?> type) {
540+
return String.format(DIRECTORY_NAME_FORMAT, asTimestampedDirectoryName(type), UUID.randomUUID());
541+
}
542+
536543
protected static @NonNull File createDirectory(@NonNull String pathname) {
537544
return createDirectory(new File(pathname));
538545
}

spring-data-geode-test/src/test/java/org/springframework/data/gemfire/tests/integration/IntegrationTestsSupportUnitTests.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
import static org.assertj.core.api.Assertions.assertThat;
1919

20-
import java.io.File;
2120
import java.time.LocalDateTime;
2221
import java.time.format.DateTimeFormatter;
2322

@@ -41,10 +40,9 @@ public void asDirectoryNameIsCorrect() {
4140
String directoryName = IntegrationTestsSupport.asDirectoryName(OuterType.InnerType.class);
4241

4342
assertThat(directoryName).isNotBlank();
44-
assertThat(directoryName).startsWith(String.format("%s.%s.%s-%s%s",
43+
assertThat(directoryName).matches(String.format("%s\\.%s\\.%s-%s-",
4544
IntegrationTestsSupportUnitTests.class.getSimpleName(), OuterType.class.getSimpleName(), OuterType.InnerType.class.getSimpleName(),
46-
DateTimeFormatter.ofPattern(IntegrationTestsSupport.DATE_TIME_PATTERN).format(now),
47-
File.separator));
45+
DateTimeFormatter.ofPattern(IntegrationTestsSupport.DATE_TIME_PATTERN).format(now)).concat("[\\w-]+"));
4846

4947
}
5048

0 commit comments

Comments
 (0)