You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by jo...@apache.org on 2008/04/07 05:02:06 UTC

svn commit: r645348 [6/6] - in /poi/trunk/src: documentation/content/xdocs/ java/org/apache/poi/util/ testcases/org/apache/poi/ testcases/org/apache/poi/hssf/ testcases/org/apache/poi/hssf/eventusermodel/ testcases/org/apache/poi/hssf/extractor/ testca...

Modified: poi/trunk/src/testcases/org/apache/poi/poifs/filesystem/TestPropertySorter.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/poifs/filesystem/TestPropertySorter.java?rev=645348&r1=645347&r2=645348&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/poifs/filesystem/TestPropertySorter.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/poifs/filesystem/TestPropertySorter.java Sun Apr  6 20:02:03 2008
@@ -18,12 +18,21 @@
 
 package org.apache.poi.poifs.filesystem;
 
-import junit.framework.TestCase;
-import junit.framework.ComparisonFailure;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Comparator;
+import java.util.Iterator;
 
-import java.io.*;
-import java.util.*;
+import junit.framework.ComparisonFailure;
+import junit.framework.TestCase;
 
+import org.apache.poi.hssf.HSSFTestDataSamples;
 import org.apache.poi.poifs.property.DirectoryProperty;
 import org.apache.poi.poifs.property.Property;
 
@@ -36,45 +45,46 @@
  *
  * @author Yegor Kozlov
  */
-public class TestPropertySorter extends TestCase {
+public final class TestPropertySorter extends TestCase {
 
     //the correct order of entries in the test file
-    protected static final String[] _entries = {
+    private static final String[] _entries = {
         "dir", "JML", "UTIL", "Loader", "Sheet1", "Sheet2", "Sheet3",
         "__SRP_0", "__SRP_1", "__SRP_2", "__SRP_3", "__SRP_4", "__SRP_5",
         "ThisWorkbook", "_VBA_PROJECT",
     };
 
-    protected File testFile;
-
-    public void setUp(){
-        String home = System.getProperty("HSSF.testdata.path");
-        testFile = new File(home + "/39234.xls");
+    private static POIFSFileSystem openSampleFS() {
+        InputStream is = HSSFTestDataSamples.openSampleFileStream("39234.xls");
+        try {
+            return new POIFSFileSystem(is);
+        } catch (IOException e) {
+            throw new RuntimeException(e);
+        }
     }
-
+    
     /**
      * Test sorting of properties in <code>DirectoryProperty</code>
      */
     public void testSortProperties() throws IOException {
-        InputStream is = new FileInputStream(testFile);
-        POIFSFileSystem fs = new POIFSFileSystem(is);
-        is.close();
+        POIFSFileSystem fs = openSampleFS();
         Property[] props = getVBAProperties(fs);
 
         assertEquals(_entries.length, props.length);
 
-        // (1). See that there is a problem with the old case-sensitive property comparartor
-        Arrays.sort(props, new CaseSensitivePropertyComparator());
+        // (1). See that there is a problem with the old case-sensitive property comparator
+        Arrays.sort(props, OldCaseSensitivePropertyComparator);
         try {
             for (int i = 0; i < props.length; i++) {
                 assertEquals(_entries[i], props[i].getName());
             }
-            fail("case-sensitive property comparator returns properties in wrong order");
+            fail("expected old case-sensitive property comparator to return properties in wrong order");
         } catch (ComparisonFailure e){
-            ; // as expected
+            // expected during successful test
+            assertNotNull(e.getMessage());
         }
 
-        // (2) Verify that the fixed proeprty comparator works right
+        // (2) Verify that the fixed property comparator works right
         Arrays.sort(props, new DirectoryProperty.PropertyComparator());
         for (int i = 0; i < props.length; i++) {
             assertEquals(_entries[i], props[i].getName());
@@ -85,14 +95,12 @@
      * Serialize file system and verify that the order of properties is the same as in the original file.
      */
     public void testSerialization() throws IOException {
-        InputStream is = new FileInputStream(testFile);
-        POIFSFileSystem fs = new POIFSFileSystem(is);
-        is.close();
+        POIFSFileSystem fs = openSampleFS();
 
         ByteArrayOutputStream out = new ByteArrayOutputStream();
         fs.writeFilesystem(out);
         out.close();
-        is = new ByteArrayInputStream(out.toByteArray());
+        InputStream is = new ByteArrayInputStream(out.toByteArray());
         fs = new POIFSFileSystem(is);
         is.close();
         Property[] props = getVBAProperties(fs);
@@ -128,26 +136,17 @@
     /**
      * Old version of case-sensitive PropertyComparator to demonstrate the problem
      */
-    private class CaseSensitivePropertyComparator  implements Comparator
-    {
-
-        public boolean equals(Object o)
-        {
-            return this == o;
-        }
+    private static final Comparator OldCaseSensitivePropertyComparator = new Comparator() {
 
-        public int compare(Object o1, Object o2)
-        {
+        public int compare(Object o1, Object o2) {
             String name1  = (( Property ) o1).getName();
             String name2  = (( Property ) o2).getName();
-            int    result = name1.length() - name2.length();
+            int result = name1.length() - name2.length();
 
-            if (result == 0)
-            {
+            if (result == 0) {
                 result = name1.compareTo(name2);
             }
             return result;
         }
-    }
-
+    };
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org