@@ -63,7 +63,7 @@ class FileSystemTest {
6363 /** A single Unicode character that encodes to 3 UTF-8 bytes. */
6464 private static final String CHAR_UTF8_3B = "★" ;
6565
66- /** A single Unicode codepoint that encodes to 2 UTF-16 code units and 4 UTF-8 bytes. */
66+ /** A single Unicode code point that encodes to 2 UTF-16 code units and 4 UTF-8 bytes. */
6767 private static final String CHAR_UTF8_4B = "😀" ;
6868
6969 /**
@@ -94,28 +94,28 @@ class FileSystemTest {
9494 + "\uD83D \uDC66 \uD83C \uDFFC \u200D \uD83E \uDDB3 " ;
9595
9696 /** File name of 255 bytes and 255 UTF-16 code units. */
97- private static final String FILE_NAME_255BYTES_UTF8_1B = repeat (CHAR_UTF8_1B , 255 );
97+ private static final String FILE_NAME_255_BYTES_UTF8_1B = repeat (CHAR_UTF8_1B , 255 );
9898
9999 /** File name of 255 bytes and 128 UTF-16 code units. */
100- private static final String FILE_NAME_255BYTES_UTF8_2B = repeat (CHAR_UTF8_2B , 127 ) + CHAR_UTF8_1B ;
100+ private static final String FILE_NAME_255_BYTES_UTF8_2B = repeat (CHAR_UTF8_2B , 127 ) + CHAR_UTF8_1B ;
101101
102102 /** File name of 255 bytes and 85 UTF-16 code units. */
103- private static final String FILE_NAME_255BYTES_UTF8_3B = repeat (CHAR_UTF8_3B , 85 );
103+ private static final String FILE_NAME_255_BYTES_UTF8_3B = repeat (CHAR_UTF8_3B , 85 );
104104
105105 /** File name of 255 bytes and 64 UTF-16 code units. */
106- private static final String FILE_NAME_255BYTES_UTF8_4B = repeat (CHAR_UTF8_4B , 63 ) + CHAR_UTF8_3B ;
106+ private static final String FILE_NAME_255_BYTES_UTF8_4B = repeat (CHAR_UTF8_4B , 63 ) + CHAR_UTF8_3B ;
107107
108108 /** File name of 255 bytes and 255 UTF-16 code units. */
109- private static final String FILE_NAME_255CHARS_UTF8_1B = FILE_NAME_255BYTES_UTF8_1B ;
109+ private static final String FILE_NAME_255_CHARS_UTF8_1B = FILE_NAME_255_BYTES_UTF8_1B ;
110110
111111 /** File name of 510 bytes and 255 UTF-16 code units. */
112- private static final String FILE_NAME_255CHARS_UTF8_2B = repeat (CHAR_UTF8_2B , 255 );
112+ private static final String FILE_NAME_255_CHARS_UTF8_2B = repeat (CHAR_UTF8_2B , 255 );
113113
114114 /** File name of 765 bytes and 255 UTF-16 code units. */
115- private static final String FILE_NAME_255CHARS_UTF8_3B = repeat (CHAR_UTF8_3B , 255 );
115+ private static final String FILE_NAME_255_CHARS_UTF8_3B = repeat (CHAR_UTF8_3B , 255 );
116116
117117 /** File name of 511 bytes and 255 UTF-16 code units. */
118- private static final String FILE_NAME_255CHARS_UTF8_4B = repeat (CHAR_UTF8_4B , 127 ) + CHAR_UTF8_3B ;
118+ private static final String FILE_NAME_255_CHARS_UTF8_4B = repeat (CHAR_UTF8_4B , 127 ) + CHAR_UTF8_3B ;
119119
120120 private static void createAndDelete (final Path tempDir , final String fileName ) throws IOException {
121121 final Path filePath = tempDir .resolve (fileName );
@@ -131,26 +131,26 @@ private static void createAndDelete(final Path tempDir, final String fileName) t
131131
132132 static Stream <Arguments > testIsLegalName_Length () {
133133 return Stream .of (
134- Arguments .of (FileSystem .GENERIC , repeat (FILE_NAME_255BYTES_UTF8_1B , 4 ), UTF_8 ),
135- Arguments .of (FileSystem .GENERIC , repeat (FILE_NAME_255BYTES_UTF8_2B , 4 ), UTF_8 ),
136- Arguments .of (FileSystem .GENERIC , repeat (FILE_NAME_255BYTES_UTF8_3B , 4 ), UTF_8 ),
137- Arguments .of (FileSystem .GENERIC , repeat (FILE_NAME_255BYTES_UTF8_4B , 4 ), UTF_8 ),
138- Arguments .of (FileSystem .LINUX , FILE_NAME_255BYTES_UTF8_1B , UTF_8 ),
139- Arguments .of (FileSystem .LINUX , FILE_NAME_255BYTES_UTF8_2B , UTF_8 ),
140- Arguments .of (FileSystem .LINUX , FILE_NAME_255BYTES_UTF8_3B , UTF_8 ),
141- Arguments .of (FileSystem .LINUX , FILE_NAME_255BYTES_UTF8_4B , UTF_8 ),
142- Arguments .of (FileSystem .MAC_OSX , FILE_NAME_255BYTES_UTF8_1B , UTF_8 ),
143- Arguments .of (FileSystem .MAC_OSX , FILE_NAME_255BYTES_UTF8_2B , UTF_8 ),
144- Arguments .of (FileSystem .MAC_OSX , FILE_NAME_255BYTES_UTF8_3B , UTF_8 ),
145- Arguments .of (FileSystem .MAC_OSX , FILE_NAME_255BYTES_UTF8_4B , UTF_8 ),
146- Arguments .of (FileSystem .WINDOWS , FILE_NAME_255CHARS_UTF8_1B , UTF_8 ),
147- Arguments .of (FileSystem .WINDOWS , FILE_NAME_255CHARS_UTF8_2B , UTF_8 ),
148- Arguments .of (FileSystem .WINDOWS , FILE_NAME_255CHARS_UTF8_3B , UTF_8 ),
149- Arguments .of (FileSystem .WINDOWS , FILE_NAME_255CHARS_UTF8_4B , UTF_8 ),
134+ Arguments .of (FileSystem .GENERIC , repeat (FILE_NAME_255_BYTES_UTF8_1B , 4 ), UTF_8 ),
135+ Arguments .of (FileSystem .GENERIC , repeat (FILE_NAME_255_BYTES_UTF8_2B , 4 ), UTF_8 ),
136+ Arguments .of (FileSystem .GENERIC , repeat (FILE_NAME_255_BYTES_UTF8_3B , 4 ), UTF_8 ),
137+ Arguments .of (FileSystem .GENERIC , repeat (FILE_NAME_255_BYTES_UTF8_4B , 4 ), UTF_8 ),
138+ Arguments .of (FileSystem .LINUX , FILE_NAME_255_BYTES_UTF8_1B , UTF_8 ),
139+ Arguments .of (FileSystem .LINUX , FILE_NAME_255_BYTES_UTF8_2B , UTF_8 ),
140+ Arguments .of (FileSystem .LINUX , FILE_NAME_255_BYTES_UTF8_3B , UTF_8 ),
141+ Arguments .of (FileSystem .LINUX , FILE_NAME_255_BYTES_UTF8_4B , UTF_8 ),
142+ Arguments .of (FileSystem .MAC_OSX , FILE_NAME_255_BYTES_UTF8_1B , UTF_8 ),
143+ Arguments .of (FileSystem .MAC_OSX , FILE_NAME_255_BYTES_UTF8_2B , UTF_8 ),
144+ Arguments .of (FileSystem .MAC_OSX , FILE_NAME_255_BYTES_UTF8_3B , UTF_8 ),
145+ Arguments .of (FileSystem .MAC_OSX , FILE_NAME_255_BYTES_UTF8_4B , UTF_8 ),
146+ Arguments .of (FileSystem .WINDOWS , FILE_NAME_255_CHARS_UTF8_1B , UTF_8 ),
147+ Arguments .of (FileSystem .WINDOWS , FILE_NAME_255_CHARS_UTF8_2B , UTF_8 ),
148+ Arguments .of (FileSystem .WINDOWS , FILE_NAME_255_CHARS_UTF8_3B , UTF_8 ),
149+ Arguments .of (FileSystem .WINDOWS , FILE_NAME_255_CHARS_UTF8_4B , UTF_8 ),
150150 // Repeat some tests with other encodings for GENERIC and LINUX
151- Arguments .of (FileSystem .GENERIC , repeat (FILE_NAME_255BYTES_UTF8_1B , 4 ), US_ASCII ),
151+ Arguments .of (FileSystem .GENERIC , repeat (FILE_NAME_255_BYTES_UTF8_1B , 4 ), US_ASCII ),
152152 Arguments .of (FileSystem .GENERIC , repeat (CHAR_UTF8_2B , 1020 ), ISO_8859_1 ),
153- Arguments .of (FileSystem .LINUX , FILE_NAME_255BYTES_UTF8_1B , US_ASCII ),
153+ Arguments .of (FileSystem .LINUX , FILE_NAME_255_BYTES_UTF8_1B , US_ASCII ),
154154 Arguments .of (FileSystem .LINUX , repeat (CHAR_UTF8_2B , 255 ), ISO_8859_1 ));
155155 }
156156
@@ -297,8 +297,8 @@ void testIsLegalName(final FileSystem fs) {
297297
298298 @ Test
299299 void testIsLegalName_Encoding () {
300- assertFalse (FileSystem .GENERIC .isLegalFileName (FILE_NAME_255BYTES_UTF8_3B , US_ASCII ), "US-ASCII cannot represent all chars" );
301- assertTrue (FileSystem .GENERIC .isLegalFileName (FILE_NAME_255BYTES_UTF8_3B , UTF_8 ), "UTF-8 can represent all chars" );
300+ assertFalse (FileSystem .GENERIC .isLegalFileName (FILE_NAME_255_BYTES_UTF8_3B , US_ASCII ), "US-ASCII cannot represent all chars" );
301+ assertTrue (FileSystem .GENERIC .isLegalFileName (FILE_NAME_255_BYTES_UTF8_3B , UTF_8 ), "UTF-8 can represent all chars" );
302302 }
303303
304304 @ ParameterizedTest (name = "{index}: {0} with charset {2}" )
@@ -350,44 +350,42 @@ void testMaxNameLength_MatchesRealSystem(@TempDir final Path tempDir) {
350350 final FileSystem fs = FileSystem .getCurrent ();
351351 final String [] validNames ;
352352 switch (fs ) {
353- case MAC_OSX :
354- case LINUX :
355- // Names with 255 UTF-8 bytes are legal
353+ case MAC_OSX :
354+ case LINUX :
355+ // Names with 255 UTF-8 bytes are legal
356+ // @formatter:off
356357 validNames = new String [] {
357- FILE_NAME_255BYTES_UTF8_1B ,
358- FILE_NAME_255BYTES_UTF8_2B ,
359- FILE_NAME_255BYTES_UTF8_3B ,
360- FILE_NAME_255BYTES_UTF8_4B
358+ FILE_NAME_255_BYTES_UTF8_1B ,
359+ FILE_NAME_255_BYTES_UTF8_2B ,
360+ FILE_NAME_255_BYTES_UTF8_3B ,
361+ FILE_NAME_255_BYTES_UTF8_4B
361362 };
362- break ;
363- case WINDOWS :
364- // Names with 255 UTF-16 code units are legal
363+ // @formatter:on
364+ break ;
365+ case WINDOWS :
366+ // Names with 255 UTF-16 code units are legal
367+ // @formatter:off
365368 validNames = new String [] {
366- FILE_NAME_255CHARS_UTF8_1B ,
367- FILE_NAME_255CHARS_UTF8_2B ,
368- FILE_NAME_255CHARS_UTF8_3B ,
369- FILE_NAME_255CHARS_UTF8_4B
369+ FILE_NAME_255_CHARS_UTF8_1B ,
370+ FILE_NAME_255_CHARS_UTF8_2B ,
371+ FILE_NAME_255_CHARS_UTF8_3B ,
372+ FILE_NAME_255_CHARS_UTF8_4B
370373 };
371- break ;
372- default :
373- throw new IllegalStateException ("Unexpected value: " + fs );
374+ // @formatter:on
375+ break ;
376+ default :
377+ throw new IllegalStateException ("Unexpected value: " + fs );
374378 }
375379 int failures = 0 ;
376380 for (final String fileName : validNames ) {
377381 // 1) OS should accept names at the documented limit.
378- assertDoesNotThrow (
379- () -> createAndDelete (tempDir , fileName ), "OS should accept max-length name: " + fileName );
380-
382+ assertDoesNotThrow (() -> createAndDelete (tempDir , fileName ), "OS should accept max-length name: " + fileName );
381383 // 2) Library should consider them legal.
382384 assertTrue (fs .isLegalFileName (fileName , UTF_8 ), "Commons IO should accept max-length name: " + fileName );
383-
384385 // 3) For “one over” the limit: Commons IO must reject; OS may or may not enforce strictly.
385386 final String tooLongName = fileName + "a" ;
386-
387387 // Library contract: must be illegal.
388- assertFalse (
389- fs .isLegalFileName (tooLongName , UTF_8 ), "Commons IO should reject too-long name: " + tooLongName );
390-
388+ assertFalse (fs .isLegalFileName (tooLongName , UTF_8 ), "Commons IO should reject too-long name: " + tooLongName );
391389 // OS behavior: may or may not reject.
392390 try {
393391 createAndDelete (tempDir , tooLongName );
@@ -404,7 +402,7 @@ void testMaxNameLength_MatchesRealSystem(@TempDir final Path tempDir) {
404402 // macOS is trickier because the API and filesystem limits don’t always match:
405403 //
406404 // - POSIX API layer (getdirentries/readdir): 1023 bytes per component since macOS 10.5.
407- // https://man.freebsd.org/cgi/man.cgi?query=dir&sektion=5&apropos=0&manpath=macOS+15.6
405+ // https://man.freebsd.org/cgi/man.cgi?query=dir&sektion=5&apropos=0&manpath=macOS+15.6
408406 // - HFS+: enforces 255 UTF-16 code units per component.
409407 // - APFS: enforces 255 UTF-8 bytes per component.
410408 //
@@ -426,10 +424,9 @@ void testNameLengthStrategyTruncate_Succeeds(final NameLengthStrategy strategy,
426424
427425 @ ParameterizedTest (name = "{index}: {0} truncates {2} with limit {1} throws" )
428426 @ MethodSource
429- void testNameLengthStrategyTruncate_Throws (
430- final NameLengthStrategy strategy , final int limit , final String input , final Charset charset , final String message ) {
431- final IllegalArgumentException ex =
432- assertThrows (IllegalArgumentException .class , () -> strategy .truncate (input , limit , charset ));
427+ void testNameLengthStrategyTruncate_Throws (final NameLengthStrategy strategy , final int limit , final String input , final Charset charset ,
428+ final String message ) {
429+ final IllegalArgumentException ex = assertThrows (IllegalArgumentException .class , () -> strategy .truncate (input , limit , charset ));
433430 final String exMessage = ex .getMessage ();
434431 assertTrue (exMessage .contains (message ), "ex message contains " + message + ": " + exMessage );
435432 }
0 commit comments