JAVA-12359 Committing Test Cases for Colon and Slash Characters
This commit is contained in:
parent
675e33fbab
commit
08a2c27339
|
@ -26,6 +26,9 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||||
public class StringFilenameValidationUnitTest {
|
public class StringFilenameValidationUnitTest {
|
||||||
|
|
||||||
private static final String CORRECT_FILENAME_PATTERN = "baeldung.txt";
|
private static final String CORRECT_FILENAME_PATTERN = "baeldung.txt";
|
||||||
|
private static final String FILENAME_WITH_COLON = "bael:dung.txt";
|
||||||
|
private static final String FILENAME_WITH_FORWARD_SLASH = "bael/dung.txt";
|
||||||
|
private static final String FILENAME_WITH_BACKWARD_SLASH = "bael\\dung.txt";
|
||||||
|
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
@MethodSource("correctAlphanumericFilenamesProvider")
|
@MethodSource("correctAlphanumericFilenamesProvider")
|
||||||
|
@ -92,6 +95,26 @@ public class StringFilenameValidationUnitTest {
|
||||||
assertThat(validateStringFilenameUsingContains(filename)).isFalse();
|
assertThat(validateStringFilenameUsingContains(filename)).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@EnabledOnOs(OS.WINDOWS)
|
||||||
|
public void givenFilenameStringWithInvalidColonWindowsCharAndIsWindows_thenNIO2FailsIOSucceed()
|
||||||
|
throws IOException {
|
||||||
|
assertThat(validateStringFilenameUsingIO(FILENAME_WITH_COLON)).isTrue();
|
||||||
|
assertThatThrownBy(() -> validateStringFilenameUsingNIO2(FILENAME_WITH_COLON))
|
||||||
|
.isInstanceOf(InvalidPathException.class).hasMessageContaining("Illegal char");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@EnabledOnOs(OS.WINDOWS)
|
||||||
|
public void givenFilenameStringWithInvalidSlashWindowsCharAndIsWindows_thenIOFailsNIO2Succeed() {
|
||||||
|
assertThatThrownBy(() -> validateStringFilenameUsingIO(FILENAME_WITH_FORWARD_SLASH))
|
||||||
|
.isInstanceOf(IOException.class).hasMessageContaining("The system cannot find the path specified");
|
||||||
|
assertThatThrownBy(() -> validateStringFilenameUsingIO(FILENAME_WITH_BACKWARD_SLASH))
|
||||||
|
.isInstanceOf(IOException.class).hasMessageContaining("The system cannot find the path specified");
|
||||||
|
assertThat(validateStringFilenameUsingNIO2(FILENAME_WITH_FORWARD_SLASH)).isTrue();
|
||||||
|
assertThat(validateStringFilenameUsingNIO2(FILENAME_WITH_BACKWARD_SLASH)).isTrue();
|
||||||
|
}
|
||||||
|
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
@EnabledOnOs({OS.LINUX, OS.MAC})
|
@EnabledOnOs({OS.LINUX, OS.MAC})
|
||||||
@MethodSource("filenamesWithInvalidUnixChars")
|
@MethodSource("filenamesWithInvalidUnixChars")
|
||||||
|
|
Loading…
Reference in New Issue