jmeter-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fschumac...@apache.org
Subject svn commit: r1766195 - /jmeter/trunk/test/src/org/apache/jmeter/save/TestSaveService.java
Date Sat, 22 Oct 2016 14:36:15 GMT
Author: fschumacher
Date: Sat Oct 22 14:36:15 2016
New Revision: 1766195

URL: http://svn.apache.org/viewvc?rev=1766195&view=rev
Log:
Refactor int[] to new class FileStats to make intent of
code clearer.

Bugzilla Id: 60222

Modified:
    jmeter/trunk/test/src/org/apache/jmeter/save/TestSaveService.java

Modified: jmeter/trunk/test/src/org/apache/jmeter/save/TestSaveService.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/test/src/org/apache/jmeter/save/TestSaveService.java?rev=1766195&r1=1766194&r2=1766195&view=diff
==============================================================================
--- jmeter/trunk/test/src/org/apache/jmeter/save/TestSaveService.java (original)
+++ jmeter/trunk/test/src/org/apache/jmeter/save/TestSaveService.java Sat Oct 22 14:36:15
2016
@@ -118,7 +118,7 @@ public class TestSaveService extends JMe
         
         boolean failed = false;
 
-        int [] orig = readFile(new BufferedReader(new FileReader(testFile)));
+        FileStats orig = computeFileStats(new BufferedReader(new FileReader(testFile)));
 
         HashTree tree = SaveService.loadTree(testFile);
 
@@ -131,19 +131,19 @@ public class TestSaveService extends JMe
 
         ByteArrayInputStream ins = new ByteArrayInputStream(out.toByteArray());
         
-        int [] output = readFile(new BufferedReader(new InputStreamReader(ins)));
+        FileStats output = computeFileStats(new BufferedReader(new InputStreamReader(ins)));
         // We only check the length of the result. Comparing the
         // actual result (out.toByteArray==original) will usually
         // fail, because the order of the properties within each
         // test element may change. Comparing the lengths should be
         // enough to detect most problem cases...
-        if ((checkSize && (orig[0] != output[0] ))|| orig[1] != output[1]) {
+        if ((checkSize && !orig.isSameSize(output)) || !orig.hasSameLinesCount(output))
{
             failed = true;
             System.out.println();
             System.out.println("Loading file testfiles/" + fileName + " and "
-                    + "saving it back changes its size from " + orig[0] + " to " + output[0]
+ ".");
-            if (orig[1] != output[1]) {
-                System.out.println("Number of lines changes from " + orig[1] + " to " + output[1]);
+                    + "saving it back changes its size from " + orig.size + " to " + output.size
+ ".");
+            if (!orig.hasSameLinesCount(output)) {
+                System.out.println("Number of lines changes from " + orig.lines + " to "
+ output.lines);
             }
             if (saveOut) {
                 final File outFile = findTestFile("testfiles/" + fileName + ".out");
@@ -173,7 +173,7 @@ public class TestSaveService extends JMe
      * "jmeterTestPlan" element which may vary because of 
      * different attributes/attribute lengths.
      */
-    private int[] readFile(BufferedReader br) throws Exception {
+    private FileStats computeFileStats(BufferedReader br) throws Exception {
         try {
             int length=0;
             int lines=0;
@@ -184,7 +184,7 @@ public class TestSaveService extends JMe
                     length += line.length();
                 }
             }
-            return new int []{length, lines};
+            return new FileStats(length, lines);
         } finally {
             br.close();
         }
@@ -210,4 +210,28 @@ public class TestSaveService extends JMe
             fail("One or more classes not found:"+missingClasses);
         }
     }
+
+    private static class FileStats {
+        int size;
+        int lines;
+
+        public FileStats(int size, int lines) {
+            this.size = size;
+            this.lines = lines;
+        }
+
+        public boolean isSameSize(FileStats other) {
+            if (other == null) {
+                return false;
+            }
+            return size == other.size;
+        }
+
+        public boolean hasSameLinesCount(FileStats other) {
+            if (other == null) {
+                return false;
+            }
+            return lines == other.lines;
+        }
+    }
 }



Mime
View raw message