]> source.dussan.org Git - poi.git/commitdiff
tidy up some test code
authorPJ Fanning <fanningpj@apache.org>
Tue, 19 Sep 2017 21:04:30 +0000 (21:04 +0000)
committerPJ Fanning <fanningpj@apache.org>
Tue, 19 Sep 2017 21:04:30 +0000 (21:04 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1808944 13f79535-47bb-0310-9956-ffa450edef68

src/ooxml/testcases/org/apache/poi/extractor/TestExtractorFactory.java
src/ooxml/testcases/org/apache/poi/xssf/usermodel/BaseTestXSSFPivotTable.java
src/scratchpad/testcases/org/apache/poi/hsmf/TestBasics.java
src/testcases/org/apache/poi/hssf/usermodel/TestHSSFCell.java
src/testcases/org/apache/poi/hssf/util/TestAreaReference.java

index dfae641070dd529f465e1d45790e4f696f6563c0..fb378df0dd61dbbbe2deef952438ec1dc26cae67 100644 (file)
@@ -332,7 +332,7 @@ public class TestExtractorFactory {
         // Text
         try {
             ExtractorFactory.createExtractor(txt);
-            fail();
+            fail("expected IllegalArgumentException");
         } catch(IllegalArgumentException e) {
             // Good
         }
@@ -480,14 +480,9 @@ public class TestExtractorFactory {
         extractor.close();
 
         // Text
-        try {
-            FileInputStream stream = new FileInputStream(txt);
-            try {
-                ExtractorFactory.createExtractor(stream);
-                fail();
-            } finally {
-                IOUtils.closeQuietly(stream);
-            }
+        try (FileInputStream stream = new FileInputStream(txt)) {
+            ExtractorFactory.createExtractor(stream);
+            fail("expected IllegalArgumentException");
         } catch(IllegalArgumentException e) {
             // Good
         }
@@ -568,7 +563,7 @@ public class TestExtractorFactory {
         // Text
         try {
             ExtractorFactory.createExtractor(new POIFSFileSystem(new FileInputStream(txt)));
-            fail();
+            fail("expected IllegalArgumentException");
         } catch(IOException e) {
             // Good
         }
@@ -650,7 +645,7 @@ public class TestExtractorFactory {
         // Text
         try {
             ExtractorFactory.createExtractor(new OPOIFSFileSystem(new FileInputStream(txt)));
-            fail();
+            fail("expected IllegalArgumentException");
         } catch(IOException e) {
             // Good
         }
index 21b7b01bc0e75d29bb4efee51789fe46ec2c3096..c711c83e4684d06a21dcd554f0ada92b70ef33ba 100644 (file)
@@ -86,16 +86,9 @@ public abstract class BaseTestXSSFPivotTable {
     /**
      * Verify that it's not possible to create a row label outside of the referenced area.
      */
-    @Test
+    @Test(expected = IndexOutOfBoundsException.class)
     public void testAddRowLabelOutOfRangeThrowsException() {
-        int columnIndex = 5;
-
-        try {
-            pivotTable.addRowLabel(columnIndex);
-        } catch(IndexOutOfBoundsException e) {
-            return;
-        }
-        fail();
+        pivotTable.addRowLabel(5);
     }
 
     /**
@@ -197,16 +190,9 @@ public abstract class BaseTestXSSFPivotTable {
     /**
      * Verify that it's not possible to create a column label outside of the referenced area.
      */
-    @Test
+    @Test(expected = IndexOutOfBoundsException.class)
     public void testAddColumnLabelOutOfRangeThrowsException() {
-        int columnIndex = 5;
-
-        try {
-            pivotTable.addColumnLabel(DataConsolidateFunction.SUM, columnIndex);
-        } catch(IndexOutOfBoundsException e) {
-            return;
-        }
-        fail();
+        pivotTable.addColumnLabel(DataConsolidateFunction.SUM, 5);
     }
 
      /**
@@ -226,17 +212,9 @@ public abstract class BaseTestXSSFPivotTable {
     /**
      * Verify that it's not possible to create a data column outside of the referenced area.
      */
-    @Test
+    @Test(expected = IndexOutOfBoundsException.class)
     public void testAddDataColumnOutOfRangeThrowsException() {
-        int columnIndex = 5;
-        boolean isDataField = true;
-
-        try {
-            pivotTable.addDataColumn(columnIndex, isDataField);
-        } catch(IndexOutOfBoundsException e) {
-            return;
-        }
-        fail();
+        pivotTable.addDataColumn(5, true);
     }
 
      /**
@@ -257,15 +235,9 @@ public abstract class BaseTestXSSFPivotTable {
      /**
      * Verify that it's not possible to create a new filter outside of the referenced area.
      */
-    @Test
+    @Test(expected = IndexOutOfBoundsException.class)
     public void testAddReportFilterOutOfRangeThrowsException() {
-        int columnIndex = 5;
-        try {
-            pivotTable.addReportFilter(columnIndex);
-        } catch(IndexOutOfBoundsException e) {
-            return;
-        }
-        fail();
+        pivotTable.addReportFilter(5);
     }
     
     /**
index 207d3fdcb5d5e60c202f9814669de121dd82ea04..860f1f5e6c904df139122237921b2e13ff5bc169 100644 (file)
@@ -19,6 +19,7 @@ package org.apache.poi.hsmf;
 
 import static org.apache.poi.POITestCase.assertContains;
 import static org.apache.poi.POITestCase.assertStartsWith;
+import static org.junit.Assert.fail;
 
 import java.io.IOException;
 
@@ -99,13 +100,13 @@ public final class TestBasics extends TestCase {
       // Quick doesn't have them
       try {
          quick.getHeaders();
-         fail();
+         fail("expected ChunkNotFoundException");
       } catch(ChunkNotFoundException e) {}
       
       // Attachments doesn't have them
       try {
          attachments.getHeaders();
-         fail();
+         fail("expected ChunkNotFoundException");
       } catch(ChunkNotFoundException e) {}
       
       // Outlook30 has some
@@ -157,7 +158,7 @@ public final class TestBasics extends TestCase {
 
       try {
           attachments.getHtmlBody();
-          fail();
+         fail("expected ChunkNotFoundException");
       } catch(ChunkNotFoundException e) {
           // Good
       }
@@ -170,7 +171,7 @@ public final class TestBasics extends TestCase {
       
       try {
          attachments.getHtmlBody();
-         fail();
+         fail("expected ChunkNotFoundException");
       } catch(ChunkNotFoundException e) {
          // Good
       }
@@ -185,13 +186,13 @@ public final class TestBasics extends TestCase {
 
       try {
          noRecipientAddress.getRecipientEmailAddress();
-         fail();
+         fail("expected ChunkNotFoundException");
       } catch(ChunkNotFoundException e) {
          // Good
       }
       try {
          noRecipientAddress.getRecipientEmailAddressList();
-         fail();
+         fail("expected ChunkNotFoundException");
       } catch(ChunkNotFoundException e) {
          // Good
       }
index a9cc347bef84b3f9302e150effc4e90e835f1377..7fe5f09224cd2f3c2046f050bd51d4bf3e13e11c 100644 (file)
@@ -301,13 +301,13 @@ public final class TestHSSFCell extends BaseTestCell {
                styB.verifyBelongsToWorkbook(wbB);
                try {
                        styA.verifyBelongsToWorkbook(wbB);
-                       fail();
+                       fail("expected IllegalArgumentException");
                } catch (IllegalArgumentException e) {
                        // expected during successful test
                }
                try {
                        styB.verifyBelongsToWorkbook(wbA);
-                       fail();
+                       fail("expected IllegalArgumentException");
                } catch (IllegalArgumentException e) {
                        // expected during successful test
                }
@@ -319,13 +319,13 @@ public final class TestHSSFCell extends BaseTestCell {
                cellB.setCellStyle(styB);
                try {
                        cellA.setCellStyle(styB);
-                       fail();
+                       fail("expected IllegalArgumentException");
                } catch (IllegalArgumentException e) {
                        // expected during successful test
                }
                try {
                        cellB.setCellStyle(styA);
-                       fail();
+                       fail("expected IllegalArgumentException");
                } catch (IllegalArgumentException e) {
                        // expected during successful test
                }
@@ -352,7 +352,7 @@ public final class TestHSSFCell extends BaseTestCell {
                Record[] recs = RecordInspector.getRecords(sheet, 0);
                if (recs.length == 28 && recs[23] instanceof StringRecord) {
                    wb.close();
-                       throw new AssertionFailedError("Identified bug - leftover StringRecord");
+                       fail("Identified bug - leftover StringRecord");
                }
                confirmStringRecord(sheet, false);
 
index 2819289ea91e1181a4bbc65bd32d0df02f8fd8c6..c14ca44e42b673c7ba2f696eda44af7066b891ac 100644 (file)
@@ -126,19 +126,19 @@ public final class TestAreaReference extends TestCase {
         new AreaReference(ref2D, SpreadsheetVersion.EXCEL97);
         try {
             new AreaReference(refDCSimple, SpreadsheetVersion.EXCEL97);
-            fail();
+            fail("expected IllegalArgumentException");
         } catch(IllegalArgumentException e) {
                // expected during successful test
         }
         try {
             new AreaReference(refDC2D, SpreadsheetVersion.EXCEL97);
-            fail();
+            fail("expected IllegalArgumentException");
         } catch(IllegalArgumentException e) {
                // expected during successful test
         }
         try {
             new AreaReference(refDC3D, SpreadsheetVersion.EXCEL97);
-            fail();
+            fail("expected IllegalArgumentException");
         } catch(IllegalArgumentException e) {
                // expected during successful test
         }