Repository: ant-ivy
Updated Branches:
  refs/heads/master ff49f0dd3 -> c4828bfd0


properly release the file descriptors and avoid duplicate code


Project: http://git-wip-us.apache.org/repos/asf/ant-ivy/repo
Commit: http://git-wip-us.apache.org/repos/asf/ant-ivy/commit/c4828bfd
Tree: http://git-wip-us.apache.org/repos/asf/ant-ivy/tree/c4828bfd
Diff: http://git-wip-us.apache.org/repos/asf/ant-ivy/diff/c4828bfd

Branch: refs/heads/master
Commit: c4828bfd09ea8c579fa8840cd77733c64b8ebb39
Parents: ff49f0d
Author: Nicolas Lalevée <[email protected]>
Authored: Sun Jul 2 19:23:21 2017 +0200
Committer: Nicolas Lalevée <[email protected]>
Committed: Sun Jul 2 19:23:21 2017 +0200

----------------------------------------------------------------------
 .../java/org/apache/ivy/ant/IvyPublishTest.java | 206 +++----------------
 1 file changed, 29 insertions(+), 177 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ant-ivy/blob/c4828bfd/test/java/org/apache/ivy/ant/IvyPublishTest.java
----------------------------------------------------------------------
diff --git a/test/java/org/apache/ivy/ant/IvyPublishTest.java 
b/test/java/org/apache/ivy/ant/IvyPublishTest.java
index 86fbdb5..077df58 100644
--- a/test/java/org/apache/ivy/ant/IvyPublishTest.java
+++ b/test/java/org/apache/ivy/ant/IvyPublishTest.java
@@ -128,31 +128,33 @@ public class IvyPublishTest {
         // should have published the files with "1" resolver
         File published = new 
File("test/repositories/1/apache/resolve-extends/ivys/ivy-1.2.xml");
         assertTrue(published.exists());
+        checkPublishedFile(published, "ivy-extends-merged.xml");
+    }
 
+    private void checkPublishedFile(File published, String expectedFilename) 
throws IOException {
         // do a text compare, since we want to test comments as well as 
structure.
         // we could do a better job of this with xmlunit
-
-        int lineNo = 1;
-
-        @SuppressWarnings("resource")
-        BufferedReader merged = new BufferedReader(new FileReader(published));
-        BufferedReader expected = new BufferedReader(new 
InputStreamReader(getClass()
-                .getResourceAsStream("ivy-extends-merged.xml")));
-        for (String mergeLine = merged.readLine(), expectedLine = 
expected.readLine(); mergeLine != null
-                && expectedLine != null; mergeLine = merged.readLine(), 
expectedLine = expected
-                .readLine()) {
-
-            // strip timestamps for the comparison
-            if (mergeLine.contains("<info")) {
-                mergeLine = mergeLine.replaceFirst("\\s?publication=\"\\d+\"", 
"");
-            }
-            // discard whitespace-only lines
-            if (!(mergeLine.trim().equals("") && 
expectedLine.trim().equals(""))) {
-                assertEquals("published descriptor matches at line[" + lineNo 
+ "]", expectedLine,
-                    mergeLine);
+        try (BufferedReader merged = new BufferedReader(new 
FileReader(published))) {
+            try (BufferedReader expected = new BufferedReader(new 
InputStreamReader(getClass()
+                    .getResourceAsStream(expectedFilename)))) {
+                int lineNo = 1;
+                for (String mergeLine = merged.readLine(), expectedLine = 
expected.readLine(); mergeLine != null
+                        && expectedLine != null; mergeLine = 
merged.readLine(), expectedLine = expected
+                        .readLine()) {
+
+                    // strip timestamps for the comparison
+                    if (mergeLine.contains("<info")) {
+                        mergeLine = 
mergeLine.replaceFirst("\\s?publication=\"\\d+\"", "");
+                    }
+                    // discard whitespace-only lines
+                    if (!(mergeLine.trim().equals("") && 
expectedLine.trim().equals(""))) {
+                        assertEquals("published descriptor matches at line[" + 
lineNo + "]", expectedLine,
+                                mergeLine);
+                    }
+
+                    ++lineNo;
+                }
             }
-
-            ++lineNo;
         }
     }
 
@@ -178,32 +180,7 @@ public class IvyPublishTest {
         // should have published the files with "1" resolver
         File published = new 
File("test/repositories/1/apache/resolve-extends/ivys/ivy-1.2.xml");
         assertTrue(published.exists());
-
-        // do a text compare, since we want to test comments as well as 
structure.
-        // we could do a better job of this with xmlunit
-
-        int lineNo = 1;
-
-        @SuppressWarnings("resource")
-        BufferedReader merged = new BufferedReader(new FileReader(published));
-        BufferedReader expected = new BufferedReader(new 
InputStreamReader(getClass()
-                .getResourceAsStream("ivy-extends-merged.xml")));
-        for (String mergeLine = merged.readLine(), expectedLine = 
expected.readLine(); mergeLine != null
-                && expectedLine != null; mergeLine = merged.readLine(), 
expectedLine = expected
-                .readLine()) {
-
-            // strip timestamps for the comparison
-            if (mergeLine.contains("<info")) {
-                mergeLine = mergeLine.replaceFirst("\\s?publication=\"\\d+\"", 
"");
-            }
-            // discard whitespace-only lines
-            if (!(mergeLine.trim().equals("") && 
expectedLine.trim().equals(""))) {
-                assertEquals("published descriptor matches at line[" + lineNo 
+ "]", expectedLine,
-                    mergeLine);
-            }
-
-            ++lineNo;
-        }
+        checkPublishedFile(published, "ivy-extends-merged.xml");
     }
 
     @Test
@@ -234,32 +211,7 @@ public class IvyPublishTest {
         // should have published the files with "1" resolver
         File published = new 
File("test/repositories/1/apache/resolve-extends/ivys/ivy-1.2.xml");
         assertTrue(published.exists());
-
-        // do a text compare, since we want to test comments as well as 
structure.
-        // we could do a better job of this with xmlunit
-
-        int lineNo = 1;
-
-        @SuppressWarnings("resource")
-        BufferedReader merged = new BufferedReader(new FileReader(published));
-        BufferedReader expected = new BufferedReader(new 
InputStreamReader(getClass()
-                .getResourceAsStream("ivy-extends-merged.xml")));
-        for (String mergeLine = merged.readLine(), expectedLine = 
expected.readLine(); mergeLine != null
-                && expectedLine != null; mergeLine = merged.readLine(), 
expectedLine = expected
-                .readLine()) {
-
-            // strip timestamps for the comparison
-            if (mergeLine.contains("<info")) {
-                mergeLine = mergeLine.replaceFirst("\\s?publication=\"\\d+\"", 
"");
-            }
-            // discard whitespace-only lines
-            if (!(mergeLine.trim().equals("") && 
expectedLine.trim().equals(""))) {
-                assertEquals("published descriptor matches at line[" + lineNo 
+ "]", expectedLine,
-                    mergeLine);
-            }
-
-            ++lineNo;
-        }
+        checkPublishedFile(published, "ivy-extends-merged.xml");
     }
 
     @Test
@@ -284,32 +236,7 @@ public class IvyPublishTest {
         // should have published the files with "1" resolver
         File published = new 
File("test/repositories/1/apache/child1/ivys/ivy-1.2.xml");
         assertTrue(published.exists());
-
-        // do a text compare, since we want to test comments as well as 
structure.
-        // we could do a better job of this with xmlunit
-
-        int lineNo = 1;
-
-        @SuppressWarnings("resource")
-        BufferedReader merged = new BufferedReader(new FileReader(published));
-        BufferedReader expected = new BufferedReader(new 
InputStreamReader(getClass()
-                .getResourceAsStream("extends/child1/ivy-child1-merged.xml")));
-        for (String mergeLine = merged.readLine(), expectedLine = 
expected.readLine(); mergeLine != null
-                && expectedLine != null; mergeLine = merged.readLine(), 
expectedLine = expected
-                .readLine()) {
-
-            // strip timestamps for the comparison
-            if (mergeLine.contains("<info")) {
-                mergeLine = mergeLine.replaceFirst("\\s?publication=\"\\d+\"", 
"");
-            }
-            // discard whitespace-only lines
-            if (!(mergeLine.trim().equals("") && 
expectedLine.trim().equals(""))) {
-                assertEquals("published descriptor matches at line[" + lineNo 
+ "]", expectedLine,
-                    mergeLine);
-            }
-
-            ++lineNo;
-        }
+        checkPublishedFile(published, "extends/child1/ivy-child1-merged.xml");
     }
 
     @Test
@@ -344,32 +271,7 @@ public class IvyPublishTest {
         // should have published the files with "1" resolver
         File published = new 
File("test/repositories/1/apache/resolve-minimal/ivys/ivy-1.2.xml");
         assertTrue(published.exists());
-
-        // do a text compare, since we want to test comments as well as 
structure.
-        // we could do a better job of this with xmlunit
-
-        int lineNo = 1;
-
-        @SuppressWarnings("resource")
-        BufferedReader merged = new BufferedReader(new FileReader(published));
-        BufferedReader expected = new BufferedReader(new 
InputStreamReader(getClass()
-                .getResourceAsStream("ivy-extends-minimal-merged.xml")));
-        for (String mergeLine = merged.readLine(), expectedLine = 
expected.readLine(); mergeLine != null
-                && expectedLine != null; mergeLine = merged.readLine(), 
expectedLine = expected
-                .readLine()) {
-
-            // strip timestamps for the comparison
-            if (mergeLine.contains("<info")) {
-                mergeLine = mergeLine.replaceFirst("\\s?publication=\"\\d+\"", 
"");
-            }
-            // discard whitespace-only lines
-            if (!(mergeLine.trim().equals("") && 
expectedLine.trim().equals(""))) {
-                assertEquals("published descriptor matches at line[" + lineNo 
+ "]", expectedLine,
-                    mergeLine);
-            }
-
-            ++lineNo;
-        }
+        checkPublishedFile(published, "ivy-extends-minimal-merged.xml");
     }
 
     @Test
@@ -410,32 +312,7 @@ public class IvyPublishTest {
         // should have published the files with "1" resolver
         File published = new 
File("test/repositories/1/apache/resolve-minimal/ivys/ivy-1.2.xml");
         assertTrue(published.exists());
-
-        // do a text compare, since we want to test comments as well as 
structure.
-        // we could do a better job of this with xmlunit
-
-        int lineNo = 1;
-
-        @SuppressWarnings("resource")
-        BufferedReader merged = new BufferedReader(new FileReader(published));
-        BufferedReader expected = new BufferedReader(new 
InputStreamReader(getClass()
-                
.getResourceAsStream("ivy-extends-extra-attributes-merged.xml")));
-        for (String mergeLine = merged.readLine(), expectedLine = 
expected.readLine(); mergeLine != null
-                && expectedLine != null; mergeLine = merged.readLine(), 
expectedLine = expected
-                .readLine()) {
-
-            // strip timestamps for the comparison
-            if (mergeLine.contains("<info")) {
-                mergeLine = mergeLine.replaceFirst("\\s?publication=\"\\d+\"", 
"");
-            }
-            // discard whitespace-only lines
-            if (!(mergeLine.trim().equals("") && 
expectedLine.trim().equals(""))) {
-                assertEquals("published descriptor matches at line[" + lineNo 
+ "]", expectedLine,
-                    mergeLine);
-            }
-
-            ++lineNo;
-        }
+        checkPublishedFile(published, 
"ivy-extends-extra-attributes-merged.xml");
     }
 
     @Test
@@ -477,32 +354,7 @@ public class IvyPublishTest {
         // should have published the files with "1" resolver
         File published = new 
File("test/repositories/1/apache/resolve-minimal/ivys/ivy-1.2.xml");
         assertTrue(published.exists());
-
-        // do a text compare, since we want to test comments as well as 
structure.
-        // we could do a better job of this with xmlunit
-
-        int lineNo = 1;
-
-        @SuppressWarnings("resource")
-        BufferedReader merged = new BufferedReader(new FileReader(published));
-        BufferedReader expected = new BufferedReader(new 
InputStreamReader(getClass()
-                
.getResourceAsStream("ivy-extends-extra-attributes-merged.xml")));
-        for (String mergeLine = merged.readLine(), expectedLine = 
expected.readLine(); mergeLine != null
-                && expectedLine != null; mergeLine = merged.readLine(), 
expectedLine = expected
-                .readLine()) {
-
-            // strip timestamps for the comparison
-            if (mergeLine.contains("<info")) {
-                mergeLine = mergeLine.replaceFirst("\\s?publication=\"\\d+\"", 
"");
-            }
-            // discard whitespace-only lines
-            if (!(mergeLine.trim().equals("") && 
expectedLine.trim().equals(""))) {
-                assertEquals("published descriptor matches at line[" + lineNo 
+ "]", expectedLine,
-                    mergeLine);
-            }
-
-            ++lineNo;
-        }
+        checkPublishedFile(published, 
"ivy-extends-extra-attributes-merged.xml");
     }
 
     @Test

Reply via email to