Refactor IntegrationTestsSupportUnitTests.asDirectoryNameIsCorrect() test case method to be more resilient to temporal-based test failures.

Previously, the test case method could fail based on a race condition involving a timestamp in the (test) working directory name.
This commit is contained in:
John Blum
2022-10-17 12:43:11 -07:00
parent 10a84f1ef8
commit cc18aa1949

View File

@@ -17,9 +17,6 @@ package org.springframework.data.gemfire.tests.integration;
import static org.assertj.core.api.Assertions.assertThat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import org.junit.Test;
/**
@@ -35,15 +32,16 @@ public class IntegrationTestsSupportUnitTests {
@Test
public void asDirectoryNameIsCorrect() {
LocalDateTime now = LocalDateTime.now();
String directoryName = IntegrationTestsSupport.asDirectoryName(OuterType.InnerType.class);
assertThat(directoryName).isNotBlank();
assertThat(directoryName).matches(String.format("%s\\.%s\\.%s-%s-",
IntegrationTestsSupportUnitTests.class.getSimpleName(), OuterType.class.getSimpleName(), OuterType.InnerType.class.getSimpleName(),
DateTimeFormatter.ofPattern(IntegrationTestsSupport.DATE_TIME_PATTERN).format(now)).concat("[\\w-]+"));
Object[] args = {
IntegrationTestsSupportUnitTests.class.getSimpleName(),
OuterType.class.getSimpleName(),
OuterType.InnerType.class.getSimpleName()
};
assertThat(directoryName).isNotBlank();
assertThat(directoryName).matches(String.format("%s\\.%s\\.%s", args).concat("[\\w-]+"));
}
interface OuterType {