Fix some warnings in unit tests

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1808521 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Dominik Stadler 2017-09-16 08:29:06 +00:00
parent 7c01f5a50c
commit 0297946834
10 changed files with 21 additions and 21 deletions

View File

@ -27,9 +27,6 @@ import java.util.Map;
*/ */
@Internal @Internal
public class StringUtil { public class StringUtil {
private static final POILogger logger = POILogFactory
.getLogger(StringUtil.class);
protected static final Charset ISO_8859_1 = Charset.forName("ISO-8859-1"); 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 UTF16LE = Charset.forName("UTF-16LE");
public static final Charset UTF8 = Charset.forName("UTF-8"); public static final Charset UTF8 = Charset.forName("UTF-8");

View File

@ -156,7 +156,7 @@ public final class POIDataSamples {
/** /**
* *
* @param sampleFileName the name of the test file * @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 * @throws RuntimeException if the file was not found
*/ */
public File getFile(String sampleFileName) { public File getFile(String sampleFileName) {

View File

@ -19,7 +19,6 @@ package org.apache.poi;
import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertThat; import static org.junit.Assert.assertThat;

View File

@ -17,10 +17,6 @@
package org.apache.poi; 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.Collections;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;

View File

@ -73,6 +73,7 @@ public final class TestNumberComparer {
public void testSpecificExampleA() { public void testSpecificExampleA() {
double a = 0.06-0.01; double a = 0.06-0.01;
double b = 0.05; double b = 0.05;
//noinspection ConstantConditions
assertFalse(a == b); assertFalse(a == b);
assertEquals(0, NumberComparer.compare(a, b)); assertEquals(0, NumberComparer.compare(a, b));
} }
@ -84,6 +85,7 @@ public final class TestNumberComparer {
public void testSpecificExampleB() { public void testSpecificExampleB() {
double a = 1+1.0028-0.9973; double a = 1+1.0028-0.9973;
double b = 1.0055; double b = 1.0055;
//noinspection ConstantConditions
assertFalse(a == b); assertFalse(a == b);
assertEquals(0, NumberComparer.compare(a, b)); assertEquals(0, NumberComparer.compare(a, b));
} }

View File

@ -251,11 +251,8 @@ public class TestHexDump {
public void testMain() throws Exception { public void testMain() throws Exception {
File file = TempFile.createTempFile("HexDump", ".dat"); File file = TempFile.createTempFile("HexDump", ".dat");
try { try {
FileOutputStream out = new FileOutputStream(file); try (FileOutputStream out = new FileOutputStream(file)) {
try {
IOUtils.copy(new ByteArrayInputStream("teststring".getBytes(LocaleUtil.CHARSET_1252)), out); IOUtils.copy(new ByteArrayInputStream("teststring".getBytes(LocaleUtil.CHARSET_1252)), out);
} finally {
out.close();
} }
assertTrue(file.exists()); assertTrue(file.exists());
assertTrue(file.length() > 0); assertTrue(file.length() > 0);

View File

@ -256,6 +256,7 @@ public final class TestIntList extends TestCase {
IntList list = new IntList(); IntList list = new IntList();
assertEquals(list, list); assertEquals(list, list);
//noinspection ObjectEqualsNull
assertTrue(!list.equals(null)); assertTrue(!list.equals(null));
IntList list2 = new IntList(200); IntList list2 = new IntList(200);

View File

@ -42,17 +42,17 @@ public final class TestPOILogger extends POILogger {
POILogger log = POILogFactory.getLogger( "foo" ); POILogger log = POILogFactory.getLogger( "foo" );
assertTrue(log instanceof TestPOILogger); assertTrue(log instanceof TestPOILogger);
TestPOILogger tlog = (TestPOILogger)log; TestPOILogger tLog = (TestPOILogger)log;
log.log(POILogger.WARN, "Test = ", 1); 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")); log.log(POILogger.ERROR, "Test ", 1,2,new Exception("bla"));
assertEquals("Test 12", tlog.lastLog); assertEquals("Test 12", tLog.lastLog);
assertNotNull(tlog.lastEx); assertNotNull(tLog.lastEx);
log.log(POILogger.ERROR, "log\nforging", "\nevil","\nlog"); log.log(POILogger.ERROR, "log\nforging", "\nevil","\nlog");
assertEquals("log forging evil log", tlog.lastLog); assertEquals("log forging evil log", tLog.lastLog);
} finally { } finally {
POILogFactory._loggerClassName = oldLCN; POILogFactory._loggerClassName = oldLCN;
} }

View File

@ -137,7 +137,9 @@ public class TestStringUtil {
try { try {
i.next(); i.next();
fail(); fail();
} catch(ArrayIndexOutOfBoundsException e) {} } catch(ArrayIndexOutOfBoundsException e) {
// expected here
}
i = new StringsIterator(new String[] {"1"}); i = new StringsIterator(new String[] {"1"});
@ -148,7 +150,9 @@ public class TestStringUtil {
try { try {
i.next(); i.next();
fail(); fail();
} catch(ArrayIndexOutOfBoundsException e) {} } catch(ArrayIndexOutOfBoundsException e) {
// expected here
}
i = new StringsIterator(new String[] {"1","2","3"}); i = new StringsIterator(new String[] {"1","2","3"});
@ -163,7 +167,9 @@ public class TestStringUtil {
try { try {
i.next(); i.next();
fail(); fail();
} catch(ArrayIndexOutOfBoundsException e) {} } catch(ArrayIndexOutOfBoundsException e) {
// expected here
}
} }

View File

@ -54,10 +54,12 @@ public class TestTempFile {
@After @After
public void tearDown() throws IOException { public void tearDown() throws IOException {
String[] files = tempDir.list(); String[] files = tempDir.list();
assertNotNull(files);
// can have the "poifiles" subdir // can have the "poifiles" subdir
if(files.length == 1) { if(files.length == 1) {
assertEquals("Had: " + Arrays.toString(files), DefaultTempFileCreationStrategy.POIFILES, files[0]); assertEquals("Had: " + Arrays.toString(files), DefaultTempFileCreationStrategy.POIFILES, files[0]);
files = new File(tempDir, files[0]).list(); files = new File(tempDir, files[0]).list();
assertNotNull(files);
assertEquals("Had: " + Arrays.toString(files), 0, files.length); assertEquals("Had: " + Arrays.toString(files), 0, files.length);
} else { } else {
assertEquals("Had: " + Arrays.toString(files), 0, files.length); assertEquals("Had: " + Arrays.toString(files), 0, files.length);