@@ -259,6 +259,8 @@ public synchronized void close() throws IOException {
259259 new ByteArrayInputStream ("ABC" .getBytes (StandardCharsets .UTF_8 ))));
260260 assertFalse (IOUtils .contentEquals (new ByteArrayInputStream ("ABC" .getBytes (StandardCharsets .UTF_8 )),
261261 new ByteArrayInputStream ("ABCD" .getBytes (StandardCharsets .UTF_8 ))));
262+ assertFalse (IOUtils .contentEquals (new ByteArrayInputStream ("apache" .getBytes (StandardCharsets .UTF_8 )),
263+ new ByteArrayInputStream ("apacha" .getBytes (StandardCharsets .UTF_8 ))));
262264 }
263265
264266 @ Test public void testContentEquals_Reader_Reader () throws Exception {
@@ -287,6 +289,7 @@ public synchronized void close() throws IOException {
287289 assertTrue (IOUtils .contentEquals (new StringReader ("ABC" ), new StringReader ("ABC" )));
288290 assertFalse (IOUtils .contentEquals (new StringReader ("ABCD" ), new StringReader ("ABC" )));
289291 assertFalse (IOUtils .contentEquals (new StringReader ("ABC" ), new StringReader ("ABCD" )));
292+ assertFalse (IOUtils .contentEquals (new StringReader ("apache" ), new StringReader ("apacha" )));
290293 }
291294
292295 @ Test public void testContentEqualsIgnoreEOL () throws Exception {
@@ -311,28 +314,38 @@ public synchronized void close() throws IOException {
311314 assertTrue (IOUtils .contentEqualsIgnoreEOL (input1 , input1 ));
312315 }
313316
314- Reader r1 ;
315- Reader r2 ;
316-
317- r1 = new CharArrayReader ("" .toCharArray ());
318- r2 = new CharArrayReader ("" .toCharArray ());
319- assertTrue (IOUtils .contentEqualsIgnoreEOL (r1 , r2 ));
320-
321- r1 = new CharArrayReader ("1" .toCharArray ());
322- r2 = new CharArrayReader ("1" .toCharArray ());
323- assertTrue (IOUtils .contentEqualsIgnoreEOL (r1 , r2 ));
324-
325- r1 = new CharArrayReader ("1" .toCharArray ());
326- r2 = new CharArrayReader ("2" .toCharArray ());
327- assertFalse (IOUtils .contentEqualsIgnoreEOL (r1 , r2 ));
328-
329- r1 = new CharArrayReader ("123\r abc" .toCharArray ());
330- r2 = new CharArrayReader ("123\n abc" .toCharArray ());
331- assertTrue (IOUtils .contentEqualsIgnoreEOL (r1 , r2 ));
332-
333- r1 = new CharArrayReader ("321" .toCharArray ());
334- r2 = new CharArrayReader ("321\r \n " .toCharArray ());
335- assertTrue (IOUtils .contentEqualsIgnoreEOL (r1 , r2 ));
317+ testSingleEOL ("" , "" , true );
318+ testSingleEOL ("" , "\n " , false );
319+ testSingleEOL ("" , "\r " , false );
320+ testSingleEOL ("" , "\r \n " , false );
321+ testSingleEOL ("" , "\r \r " , false );
322+ testSingleEOL ("" , "\n \n " , false );
323+ testSingleEOL ("1" , "1" , true );
324+ testSingleEOL ("1" , "2" , false );
325+ testSingleEOL ("123\r abc" , "123\n abc" , true );
326+ testSingleEOL ("321" , "321\r \n " , true );
327+ testSingleEOL ("321" , "321\r \n aabb" , false );
328+ testSingleEOL ("321" , "321\n " , true );
329+ testSingleEOL ("321" , "321\r " , true );
330+ testSingleEOL ("321" , "321\r \n " , true );
331+ testSingleEOL ("321" , "321\r \r " , false );
332+ testSingleEOL ("321" , "321\n \r " , false );
333+ testSingleEOL ("321\n " , "321" , true );
334+ testSingleEOL ("321\n " , "321\n \r " , false );
335+ testSingleEOL ("321\n " , "321\r \n " , true );
336+ testSingleEOL ("321\r " , "321\r \n " , true );
337+ testSingleEOL ("321\r \n " , "321\r \n \r " , false );
338+ testSingleEOL ("123" , "1234" , false );
339+ }
340+
341+ public void testSingleEOL (String s1 , String s2 , boolean ifEquals ) throws IOException {
342+ assertEquals (ifEquals , IOUtils .contentEqualsIgnoreEOL (new CharArrayReader (s1 .toCharArray ()),
343+ new CharArrayReader (s2 .toCharArray ())), "failed at :{" + s1 + "," + s2 + "}" );
344+ assertEquals (ifEquals , IOUtils .contentEqualsIgnoreEOL (new CharArrayReader (s2 .toCharArray ()),
345+ new CharArrayReader (s1 .toCharArray ())), "failed at :{" + s2 + "," + s1 + "}" );
346+ assertTrue (IOUtils .contentEqualsIgnoreEOL (new CharArrayReader (s1 .toCharArray ()),
347+ new CharArrayReader (s1 .toCharArray ())), "failed at :{" + s1 + "," + s1 + "}" );
348+ assertTrue (IOUtils .contentEqualsIgnoreEOL (new CharArrayReader (s2 .toCharArray ()), new CharArrayReader (s2 .toCharArray ())), "failed at :{" + s2 + "," + s2 + "}" );
336349 }
337350
338351 @ Test public void testCopy_ByteArray_OutputStream () throws Exception {
0 commit comments