]> source.dussan.org Git - poi.git/commitdiff
Fix some warnings in unit tests
authorDominik Stadler <centic@apache.org>
Sat, 16 Sep 2017 08:29:06 +0000 (08:29 +0000)
committerDominik Stadler <centic@apache.org>
Sat, 16 Sep 2017 08:29:06 +0000 (08:29 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1808521 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/poi/util/StringUtil.java
src/testcases/org/apache/poi/POIDataSamples.java
src/testcases/org/apache/poi/POITestCase.java
src/testcases/org/apache/poi/TestPOITestCase.java
src/testcases/org/apache/poi/ss/util/TestNumberComparer.java
src/testcases/org/apache/poi/util/TestHexDump.java
src/testcases/org/apache/poi/util/TestIntList.java
src/testcases/org/apache/poi/util/TestPOILogger.java
src/testcases/org/apache/poi/util/TestStringUtil.java
src/testcases/org/apache/poi/util/TestTempFile.java

index ddfc8e2fe46f53532fbe12b7135484a2cd1658f8..e0473b2b5aa28fabad2cca578e6766a120bdc365 100644 (file)
@@ -27,9 +27,6 @@ import java.util.Map;
  */
 @Internal
 public class StringUtil {
-
-    private static final POILogger logger = POILogFactory
-            .getLogger(StringUtil.class);
     protected static final Charset ISO_8859_1 = Charset.forName("ISO-8859-1");
     public static final Charset UTF16LE = Charset.forName("UTF-16LE");
     public static final Charset UTF8 = Charset.forName("UTF-8");
index f57d13dae077f9ef3d37e4c01c3d0042d55f6641..4b764c2ee36bff88714fce9452d99aed4c48bd3b 100644 (file)
@@ -156,7 +156,7 @@ public final class POIDataSamples {
     /**
      *
      * @param sampleFileName    the name of the test file
-     * @return
+     * @return Verifies that the file with the given name exists in the test-data directory
      * @throws RuntimeException if the file was not found
      */
     public File getFile(String sampleFileName) {
index 4aec492a4cb9011cbfec09db11c9cc3f6d933e91..7861030a1f1414c90f24b06416a2cac6f8c0ee8b 100644 (file)
@@ -19,7 +19,6 @@ package org.apache.poi;
 
 import static org.junit.Assert.assertArrayEquals;
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.assertThat;
index 4b3155e0195c27be920199439aa9aeca61388172..796f51335fa6dc6ff0a2c6a0f9089ac857389927 100644 (file)
 
 package org.apache.poi;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
 import java.util.Collections;
 import java.util.Locale;
 import java.util.Map;
index 506df674946ccecf464db53614f4fe9d6f625e08..33cf09ad755af84c025cd00dc05b6efcfd11acd4 100644 (file)
@@ -73,6 +73,7 @@ public final class TestNumberComparer {
        public void testSpecificExampleA() {
                double a = 0.06-0.01;
                double b = 0.05;
+               //noinspection ConstantConditions
                assertFalse(a == b);
                assertEquals(0, NumberComparer.compare(a, b));
        }
@@ -84,6 +85,7 @@ public final class TestNumberComparer {
        public void testSpecificExampleB() {
                double a = 1+1.0028-0.9973;
                double b = 1.0055;
+               //noinspection ConstantConditions
                assertFalse(a == b);
                assertEquals(0, NumberComparer.compare(a, b));
        }
index a9d55ae619fe6510d872346a9d6985839f6fb3d4..5611636959829813ee95596a31a6b8c8ffd7be5c 100644 (file)
@@ -251,11 +251,8 @@ public class TestHexDump {
     public void testMain() throws Exception {
         File file = TempFile.createTempFile("HexDump", ".dat");
         try {
-            FileOutputStream out = new FileOutputStream(file);
-            try {
+            try (FileOutputStream out = new FileOutputStream(file)) {
                 IOUtils.copy(new ByteArrayInputStream("teststring".getBytes(LocaleUtil.CHARSET_1252)), out);
-            } finally {
-                out.close();
             }
             assertTrue(file.exists());
             assertTrue(file.length() > 0);
index abf50158bcbcac984f53b1dfe43ae0925a37a383..092f8af3599b5cdb8260554012e54b2ced27afb9 100644 (file)
@@ -256,6 +256,7 @@ public final class TestIntList extends TestCase {
         IntList list = new IntList();
 
         assertEquals(list, list);
+        //noinspection ObjectEqualsNull
         assertTrue(!list.equals(null));
         IntList list2 = new IntList(200);
 
index 7a286001739ae8c1088fbe99c37ef0f98655f8ad..7f6e6a06e5c200803f56fd169297601b4528821b 100644 (file)
@@ -42,17 +42,17 @@ public final class TestPOILogger extends POILogger {
             POILogger log = POILogFactory.getLogger( "foo" );
             assertTrue(log instanceof TestPOILogger);
             
-            TestPOILogger tlog = (TestPOILogger)log;
+            TestPOILogger tLog = (TestPOILogger)log;
     
             log.log(POILogger.WARN, "Test = ", 1);
-            assertEquals("Test = 1", tlog.lastLog);
+            assertEquals("Test = 1", tLog.lastLog);
             
             log.log(POILogger.ERROR, "Test ", 1,2,new Exception("bla"));
-            assertEquals("Test 12", tlog.lastLog);
-            assertNotNull(tlog.lastEx);
+            assertEquals("Test 12", tLog.lastLog);
+            assertNotNull(tLog.lastEx);
             
             log.log(POILogger.ERROR, "log\nforging", "\nevil","\nlog");
-            assertEquals("log forging evil log", tlog.lastLog);
+            assertEquals("log forging evil log", tLog.lastLog);
         } finally {
             POILogFactory._loggerClassName = oldLCN;
         }
index 76f934f1488c7eeaf25efac5f74245607b0283d8..184cf12cf438cdab59dd6318fcb160d721494b46 100644 (file)
@@ -137,7 +137,9 @@ public class TestStringUtil {
        try {
           i.next();
           fail();
-       } catch(ArrayIndexOutOfBoundsException e) {}
+       } catch(ArrayIndexOutOfBoundsException e) {
+           // expected here
+       }
 
        
        i = new StringsIterator(new String[] {"1"});
@@ -148,7 +150,9 @@ public class TestStringUtil {
        try {
           i.next();
           fail();
-       } catch(ArrayIndexOutOfBoundsException e) {}
+       } catch(ArrayIndexOutOfBoundsException e) {
+           // expected here
+       }
 
        
        i = new StringsIterator(new String[] {"1","2","3"});
@@ -163,7 +167,9 @@ public class TestStringUtil {
        try {
           i.next();
           fail();
-       } catch(ArrayIndexOutOfBoundsException e) {}
+       } catch(ArrayIndexOutOfBoundsException e) {
+           // expected here
+       }
     }
     
 
index e893f00c52110bba8b3b42e870f419caf54f5481..8aac52cbb8fc3d8a1789c03e23c43a010be4b263 100644 (file)
@@ -54,10 +54,12 @@ public class TestTempFile {
     @After
     public void tearDown() throws IOException {
         String[] files = tempDir.list();
+        assertNotNull(files);
         // can have the "poifiles" subdir
         if(files.length == 1) {
             assertEquals("Had: " + Arrays.toString(files), DefaultTempFileCreationStrategy.POIFILES, files[0]);
             files = new File(tempDir, files[0]).list();
+            assertNotNull(files);
             assertEquals("Had: " + Arrays.toString(files), 0, files.length);
         } else {
             assertEquals("Had: " + Arrays.toString(files), 0, files.length);