Skip to content

Commit 64038e1

Browse files
IO-475: Address all review comments from Grigory
1 parent 318c919 commit 64038e1

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

src/main/java/org/apache/commons/io/FilenameUtils.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
*/
1717
package org.apache.commons.io;
1818

19-
import java.io.Console;
2019
import java.io.File;
2120
import java.util.ArrayDeque;
2221
import java.util.ArrayList;
@@ -931,7 +930,6 @@ public static int getPrefixLength(final String fileName) {
931930
if (!isSeparator(ch0) || !isSeparator(ch1)) {
932931
return isSeparator(ch0) ? 1 : 0;
933932
}
934-
935933
// UNC path: //hostname or //hostname/...
936934
int posUnix = fileName.indexOf(UNIX_NAME_SEPARATOR, 2);
937935
int posWin = fileName.indexOf(WINDOWS_NAME_SEPARATOR, 2);
@@ -1696,3 +1694,4 @@ public FilenameUtils() {
16961694
// empty
16971695
}
16981696
}
1697+

src/test/java/org/apache/commons/io/FilenameUtilsTest.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,31 +70,31 @@ public void setUp() throws Exception {
7070
+ " as the parent directory does not exist");
7171
}
7272
try (BufferedOutputStream output3 =
73-
new BufferedOutputStream(Files.newOutputStream(testFile1))) {
73+
new BufferedOutputStream(Files.newOutputStream(testFile1))) {
7474
TestUtils.generateTestData(output3, testFile1Size);
7575
}
7676
if (!Files.exists(testFile2.getParent())) {
7777
throw new IOException("Cannot create file " + testFile2
7878
+ " as the parent directory does not exist");
7979
}
8080
try (BufferedOutputStream output2 =
81-
new BufferedOutputStream(Files.newOutputStream(testFile2))) {
81+
new BufferedOutputStream(Files.newOutputStream(testFile2))) {
8282
TestUtils.generateTestData(output2, testFile2Size);
8383
}
8484
if (!Files.exists(testFile1.getParent())) {
8585
throw new IOException("Cannot create file " + testFile1
8686
+ " as the parent directory does not exist");
8787
}
8888
try (BufferedOutputStream output1 =
89-
new BufferedOutputStream(Files.newOutputStream(testFile1))) {
89+
new BufferedOutputStream(Files.newOutputStream(testFile1))) {
9090
TestUtils.generateTestData(output1, testFile1Size);
9191
}
9292
if (!Files.exists(testFile2.getParent())) {
9393
throw new IOException("Cannot create file " + testFile2
9494
+ " as the parent directory does not exist");
9595
}
9696
try (BufferedOutputStream output =
97-
new BufferedOutputStream(Files.newOutputStream(testFile2))) {
97+
new BufferedOutputStream(Files.newOutputStream(testFile2))) {
9898
TestUtils.generateTestData(output, testFile2Size);
9999
}
100100
}
@@ -274,6 +274,7 @@ void testGetFullPath() {
274274
assertNull(FilenameUtils.getFullPath("1:"));
275275
assertNull(FilenameUtils.getFullPath("1:a"));
276276
assertNull(FilenameUtils.getFullPath("///a/b/c.txt"));
277+
assertEquals("//a", FilenameUtils.getFullPath("//a"));
277278

278279
assertEquals("", FilenameUtils.getFullPath(""));
279280

@@ -286,7 +287,6 @@ void testGetFullPath() {
286287

287288
assertEquals("C:/", FilenameUtils.getFullPath("C:/"));
288289
assertEquals("//server/", FilenameUtils.getFullPath("//server/"));
289-
assertEquals("//server", FilenameUtils.getFullPath("//server"));
290290
assertEquals("~/", FilenameUtils.getFullPath("~"));
291291
assertEquals("~/", FilenameUtils.getFullPath("~/"));
292292
assertEquals("~user/", FilenameUtils.getFullPath("~user"));
@@ -407,12 +407,12 @@ void testGetPath() {
407407
assertNull(FilenameUtils.getPath("1:"));
408408
assertNull(FilenameUtils.getPath("1:a"));
409409
assertNull(FilenameUtils.getPath("///a/b/c.txt"));
410+
assertEquals("",FilenameUtils.getPath("//a"));
410411

411412
assertEquals("", FilenameUtils.getPath(""));
412413
assertEquals("", FilenameUtils.getPath(DRIVE_C));
413414
assertEquals("", FilenameUtils.getPath("C:/"));
414415
assertEquals("", FilenameUtils.getPath("//server/"));
415-
assertEquals("",FilenameUtils.getPath("//server"));
416416
assertEquals("", FilenameUtils.getPath("~"));
417417
assertEquals("", FilenameUtils.getPath("~/"));
418418
assertEquals("", FilenameUtils.getPath("~user"));
@@ -923,7 +923,7 @@ void testNormalize() {
923923
assertEquals(SEP + SEP + "1::" + SEP + "a" + SEP + "b" + SEP + "c.txt", FilenameUtils.normalize("\\\\1::\\a\\b\\c.txt"));
924924
assertEquals(SEP + SEP + "server.example.org" + SEP + "a" + SEP + "b" + SEP + "c.txt", FilenameUtils.normalize("\\\\server.example.org\\a\\b\\c.txt"));
925925
assertEquals(SEP + SEP + "server.sub.example.org" + SEP + "a" + SEP + "b" + SEP + "c.txt",
926-
FilenameUtils.normalize("\\\\server.sub.example.org\\a\\b\\c.txt"));
926+
FilenameUtils.normalize("\\\\server.sub.example.org\\a\\b\\c.txt"));
927927
assertEquals(SEP + SEP + "server." + SEP + "a" + SEP + "b" + SEP + "c.txt", FilenameUtils.normalize("\\\\server.\\a\\b\\c.txt"));
928928
assertEquals(SEP + SEP + "1::127.0.0.1" + SEP + "a" + SEP + "b" + SEP + "c.txt", FilenameUtils.normalize("\\\\1::127.0.0.1\\a\\b\\c.txt"));
929929

@@ -1211,4 +1211,5 @@ void testSeparatorsToWindows() {
12111211
assertEquals("\\a\\b\\c", FilenameUtils.separatorsToWindows("/a/b/c"));
12121212
assertEquals("D:\\a\\b\\c", FilenameUtils.separatorsToWindows("D:/a/b/c"));
12131213
}
1214+
12141215
}

0 commit comments

Comments
 (0)