Fix some IDE warnings and better output in unit test

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1852280 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Dominik Stadler 2019-01-27 09:58:02 +00:00
parent 36a42899ff
commit 60a98da8e8
3 changed files with 47 additions and 42 deletions

View File

@ -40,6 +40,7 @@ import junit.framework.TestCase;
*
* @author Yegor Kozlov
*/
@SuppressWarnings("InfiniteLoopStatement")
public class MemoryUsage extends TestCase {
private static final int NUM_COLUMNS = 255;
@ -57,8 +58,8 @@ public class MemoryUsage extends TestCase {
* @param numCols the number of columns in a row
*/
public static void mixedSpreadsheet(Workbook wb, int numCols) {
System.out.println("Testing " + wb.getClass().getName());
System.out.println();
System.out.println("Testing " + wb.getClass().getName() + " mixed");
printMemoryUsage("before");
int i=0, cnt=0;
try {
@ -96,8 +97,8 @@ public class MemoryUsage extends TestCase {
* @param numCols the number of columns in a row
*/
public static void numberSpreadsheet(Workbook wb, int numCols) {
System.out.println("Testing " + wb.getClass().getName());
System.out.println();
System.out.println("Testing " + wb.getClass().getName() + " numbers");
printMemoryUsage("before");
int i=0, cnt=0;
try {
@ -159,6 +160,9 @@ public class MemoryUsage extends TestCase {
* @see #testXmlAttached()
*/
public void testXmlDetached() {
System.out.println();
System.out.println("Testing detached");
List<CTRow> rows = new ArrayList<>();
int i = 0;
try {
@ -184,6 +188,8 @@ public class MemoryUsage extends TestCase {
* @see #testXmlAttached()
*/
public void testXmlAttached() {
System.out.println();
System.out.println("Testing attached");
printMemoryUsage("before");
List<CTRow> rows = new ArrayList<>();
int i = 0;
@ -207,11 +213,11 @@ public class MemoryUsage extends TestCase {
}
public void testMixedHSSF() {
numberSpreadsheet(new HSSFWorkbook(), NUM_COLUMNS);
mixedSpreadsheet(new HSSFWorkbook(), NUM_COLUMNS);
}
public void testMixedXSSF() {
numberSpreadsheet(new XSSFWorkbook(), NUM_COLUMNS);
mixedSpreadsheet(new XSSFWorkbook(), NUM_COLUMNS);
}
public void testNumberHSSF() {
@ -221,5 +227,4 @@ public class MemoryUsage extends TestCase {
public void testNumberXSSF() {
numberSpreadsheet(new XSSFWorkbook(), NUM_COLUMNS);
}
}

View File

@ -23,13 +23,13 @@ import static org.junit.Assert.assertNotNull;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileFilter;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;
import org.apache.poi.POIDataSamples;
import org.apache.poi.hpsf.CustomProperties;
@ -59,19 +59,18 @@ public class TestReadAllFiles {
@Parameters(name="{index}: {0} using {1}")
public static Iterable<Object[]> files() {
final List<Object[]> files = new ArrayList<>();
File hpsfTestDir = _samples.getFile("");
_samples.getFile("").listFiles(f -> {
if (f.getName().startsWith("Test")) {
files.add(new Object[]{ f });
}
return false;
});
File[] files = hpsfTestDir.listFiles(f -> true);
Objects.requireNonNull(files, "Could not find directory " + hpsfTestDir.getAbsolutePath());
return files;
// convert to list of object-arrays for @Parameterized
return Arrays.stream(files).
map(file1 -> new Object[] {file1}).
collect(Collectors.toList());
}
@Parameter(value=0)
@Parameter()
public File file;
/**
@ -158,9 +157,11 @@ public class TestReadAllFiles {
*/
if (dir.hasEntry(DocumentSummaryInformation.DEFAULT_STREAM_NAME)) {
final DocumentSummaryInformation dsi = TestWriteWellKnown.getDocumentSummaryInformation(poifs);
assertNotNull(dsi);
/* Execute the get... methods. */
dsi.getByteCount();
//noinspection ResultOfMethodCallIgnored
dsi.getByteOrder();
dsi.getCategory();
dsi.getCompany();

View File

@ -22,7 +22,6 @@ import static org.apache.poi.POITestCase.testPassesNow;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.junit.Assume.assumeTrue;