diff --git a/core-java-modules/core-java-string-operations-3/src/main/java/com/baeldung/stringfilenamevalidaiton/StringFilenameValidationUtils.java b/core-java-modules/core-java-string-operations-3/src/main/java/com/baeldung/stringfilenamevalidaiton/StringFilenameValidationUtils.java index f79d01e0c2..6721d52d35 100644 --- a/core-java-modules/core-java-string-operations-3/src/main/java/com/baeldung/stringfilenamevalidaiton/StringFilenameValidationUtils.java +++ b/core-java-modules/core-java-string-operations-3/src/main/java/com/baeldung/stringfilenamevalidaiton/StringFilenameValidationUtils.java @@ -7,7 +7,7 @@ import java.util.Arrays; public class StringFilenameValidationUtils { - public static final Character[] INVALID_WINDOWS_SPECIFIC_CHARS = {'"', '*', ':', '<', '>', '?', '\\', '|'}; + public static final Character[] INVALID_WINDOWS_SPECIFIC_CHARS = {'"', '*', '<', '>', '?', '|'}; public static final Character[] INVALID_UNIX_SPECIFIC_CHARS = {'\000'}; public static final String REGEX_PATTERN = "^[A-za-z0-9.]{1,255}$"; diff --git a/core-java-modules/core-java-string-operations-3/src/test/java/com/baeldung/stringfilenamevalidaiton/StringFilenameValidationUnitTest.java b/core-java-modules/core-java-string-operations-3/src/test/java/com/baeldung/stringfilenamevalidaiton/StringFilenameValidationUnitTest.java index 36b69c2094..3e79458a7c 100644 --- a/core-java-modules/core-java-string-operations-3/src/test/java/com/baeldung/stringfilenamevalidaiton/StringFilenameValidationUnitTest.java +++ b/core-java-modules/core-java-string-operations-3/src/test/java/com/baeldung/stringfilenamevalidaiton/StringFilenameValidationUnitTest.java @@ -82,16 +82,12 @@ public class StringFilenameValidationUnitTest { @MethodSource("filenamesWithInvalidWindowsChars") public void givenFilenameStringWithInvalidWindowsCharAndIsWindows_whenValidateUsingIO_thenRaiseException( String filename) { - if (!filename.contains(":")) { - assertThatThrownBy(() -> validateStringFilenameUsingIO(filename)).isInstanceOf(IOException.class) - .extracting(Throwable::getMessage, InstanceOfAssertFactories.STRING) - .containsAnyOf("The system cannot find the path specifie", - "The filename, directory name, or volume label syntax is incorrect"); - if (!filename.contains("\\")) { - assertThatThrownBy(() -> validateStringFilenameUsingNIO2(filename)) - .isInstanceOf(InvalidPathException.class).hasMessageContaining("Illegal char"); - } - } + assertThatThrownBy(() -> validateStringFilenameUsingIO(filename)).isInstanceOf(IOException.class) + .extracting(Throwable::getMessage, InstanceOfAssertFactories.STRING) + .containsAnyOf("The system cannot find the path specified", + "The filename, directory name, or volume label syntax is incorrect"); + assertThatThrownBy(() -> validateStringFilenameUsingNIO2(filename)).isInstanceOf(InvalidPathException.class) + .hasMessageContaining("Illegal char"); assertThat(validateStringFilenameUsingContains(filename)).isFalse(); }