mirror of https://github.com/apache/poi.git
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:
parent
36a42899ff
commit
60a98da8e8
|
@ -40,6 +40,7 @@ import junit.framework.TestCase;
|
||||||
*
|
*
|
||||||
* @author Yegor Kozlov
|
* @author Yegor Kozlov
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("InfiniteLoopStatement")
|
||||||
public class MemoryUsage extends TestCase {
|
public class MemoryUsage extends TestCase {
|
||||||
private static final int NUM_COLUMNS = 255;
|
private static final int NUM_COLUMNS = 255;
|
||||||
|
|
||||||
|
@ -56,16 +57,16 @@ public class MemoryUsage extends TestCase {
|
||||||
* @param wb the workbook to write to
|
* @param wb the workbook to write to
|
||||||
* @param numCols the number of columns in a row
|
* @param numCols the number of columns in a row
|
||||||
*/
|
*/
|
||||||
public static void mixedSpreadsheet(Workbook wb, int numCols){
|
public static void mixedSpreadsheet(Workbook wb, int numCols) {
|
||||||
|
System.out.println();
|
||||||
System.out.println("Testing " + wb.getClass().getName());
|
System.out.println("Testing " + wb.getClass().getName() + " mixed");
|
||||||
printMemoryUsage("before");
|
printMemoryUsage("before");
|
||||||
int i=0, cnt=0;
|
int i=0, cnt=0;
|
||||||
try {
|
try {
|
||||||
Sheet sh = wb.createSheet();
|
Sheet sh = wb.createSheet();
|
||||||
for(i=0; ; i++){
|
for(i=0; ; i++) {
|
||||||
Row row = sh.createRow(i);
|
Row row = sh.createRow(i);
|
||||||
for(int j=0; j < numCols; j++){
|
for(int j=0; j < numCols; j++) {
|
||||||
Cell cell = row.createCell(j);
|
Cell cell = row.createCell(j);
|
||||||
if(j % 2 == 0) {
|
if(j % 2 == 0) {
|
||||||
cell.setCellValue(j);
|
cell.setCellValue(j);
|
||||||
|
@ -75,7 +76,7 @@ public class MemoryUsage extends TestCase {
|
||||||
cnt++;
|
cnt++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (OutOfMemoryError er){
|
} catch (OutOfMemoryError er) {
|
||||||
System.out.println("Failed at row=" + i + ", objects : " + cnt);
|
System.out.println("Failed at row=" + i + ", objects : " + cnt);
|
||||||
} catch (final Exception e) {
|
} catch (final Exception e) {
|
||||||
System.out.println("Unable to reach an OutOfMemoryError");
|
System.out.println("Unable to reach an OutOfMemoryError");
|
||||||
|
@ -95,22 +96,22 @@ public class MemoryUsage extends TestCase {
|
||||||
* @param wb the workbook to write to
|
* @param wb the workbook to write to
|
||||||
* @param numCols the number of columns in a row
|
* @param numCols the number of columns in a row
|
||||||
*/
|
*/
|
||||||
public static void numberSpreadsheet(Workbook wb, int numCols){
|
public static void numberSpreadsheet(Workbook wb, int numCols) {
|
||||||
|
System.out.println();
|
||||||
System.out.println("Testing " + wb.getClass().getName());
|
System.out.println("Testing " + wb.getClass().getName() + " numbers");
|
||||||
printMemoryUsage("before");
|
printMemoryUsage("before");
|
||||||
int i=0, cnt=0;
|
int i=0, cnt=0;
|
||||||
try {
|
try {
|
||||||
Sheet sh = wb.createSheet();
|
Sheet sh = wb.createSheet();
|
||||||
for(i=0; ; i++){
|
for(i=0; ; i++) {
|
||||||
Row row = sh.createRow(i);
|
Row row = sh.createRow(i);
|
||||||
for(int j=0; j < numCols; j++){
|
for(int j=0; j < numCols; j++) {
|
||||||
Cell cell = row.createCell(j);
|
Cell cell = row.createCell(j);
|
||||||
cell.setCellValue(j);
|
cell.setCellValue(j);
|
||||||
cnt++;
|
cnt++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (OutOfMemoryError er){
|
} catch (OutOfMemoryError er) {
|
||||||
System.out.println("Failed at row=" + i + ", objects : " + cnt);
|
System.out.println("Failed at row=" + i + ", objects : " + cnt);
|
||||||
} catch (final Exception e) {
|
} catch (final Exception e) {
|
||||||
System.out.println("Unable to reach an OutOfMemoryError");
|
System.out.println("Unable to reach an OutOfMemoryError");
|
||||||
|
@ -158,11 +159,14 @@ public class MemoryUsage extends TestCase {
|
||||||
*
|
*
|
||||||
* @see #testXmlAttached()
|
* @see #testXmlAttached()
|
||||||
*/
|
*/
|
||||||
public void testXmlDetached(){
|
public void testXmlDetached() {
|
||||||
|
System.out.println();
|
||||||
|
System.out.println("Testing detached");
|
||||||
|
|
||||||
List<CTRow> rows = new ArrayList<>();
|
List<CTRow> rows = new ArrayList<>();
|
||||||
int i = 0;
|
int i = 0;
|
||||||
try {
|
try {
|
||||||
for(;;){
|
for(;;) {
|
||||||
//create a standalone CTRow bean
|
//create a standalone CTRow bean
|
||||||
CTRow r = CTRow.Factory.newInstance();
|
CTRow r = CTRow.Factory.newInstance();
|
||||||
r.setR(++i);
|
r.setR(++i);
|
||||||
|
@ -183,7 +187,9 @@ public class MemoryUsage extends TestCase {
|
||||||
*
|
*
|
||||||
* @see #testXmlAttached()
|
* @see #testXmlAttached()
|
||||||
*/
|
*/
|
||||||
public void testXmlAttached(){
|
public void testXmlAttached() {
|
||||||
|
System.out.println();
|
||||||
|
System.out.println("Testing attached");
|
||||||
printMemoryUsage("before");
|
printMemoryUsage("before");
|
||||||
List<CTRow> rows = new ArrayList<>();
|
List<CTRow> rows = new ArrayList<>();
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
@ -191,7 +197,7 @@ public class MemoryUsage extends TestCase {
|
||||||
CTWorksheet sh = CTWorksheet.Factory.newInstance();
|
CTWorksheet sh = CTWorksheet.Factory.newInstance();
|
||||||
CTSheetData data = sh.addNewSheetData();
|
CTSheetData data = sh.addNewSheetData();
|
||||||
try {
|
try {
|
||||||
for(;;){
|
for(;;) {
|
||||||
//create CTRow attached to the parent object
|
//create CTRow attached to the parent object
|
||||||
CTRow r = data.addNewRow();
|
CTRow r = data.addNewRow();
|
||||||
r.setR(++i);
|
r.setR(++i);
|
||||||
|
@ -206,20 +212,19 @@ public class MemoryUsage extends TestCase {
|
||||||
printMemoryUsage("after");
|
printMemoryUsage("after");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testMixedHSSF(){
|
public void testMixedHSSF() {
|
||||||
|
mixedSpreadsheet(new HSSFWorkbook(), NUM_COLUMNS);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testMixedXSSF() {
|
||||||
|
mixedSpreadsheet(new XSSFWorkbook(), NUM_COLUMNS);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testNumberHSSF() {
|
||||||
numberSpreadsheet(new HSSFWorkbook(), NUM_COLUMNS);
|
numberSpreadsheet(new HSSFWorkbook(), NUM_COLUMNS);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testMixedXSSF(){
|
public void testNumberXSSF() {
|
||||||
numberSpreadsheet(new XSSFWorkbook(), NUM_COLUMNS);
|
numberSpreadsheet(new XSSFWorkbook(), NUM_COLUMNS);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testNumberHSSF(){
|
|
||||||
numberSpreadsheet(new HSSFWorkbook(), NUM_COLUMNS);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testNumberXSSF(){
|
|
||||||
numberSpreadsheet(new XSSFWorkbook(), NUM_COLUMNS);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -23,13 +23,13 @@ import static org.junit.Assert.assertNotNull;
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileFilter;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.ArrayList;
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import org.apache.poi.POIDataSamples;
|
import org.apache.poi.POIDataSamples;
|
||||||
import org.apache.poi.hpsf.CustomProperties;
|
import org.apache.poi.hpsf.CustomProperties;
|
||||||
|
@ -59,19 +59,18 @@ public class TestReadAllFiles {
|
||||||
|
|
||||||
@Parameters(name="{index}: {0} using {1}")
|
@Parameters(name="{index}: {0} using {1}")
|
||||||
public static Iterable<Object[]> files() {
|
public static Iterable<Object[]> files() {
|
||||||
final List<Object[]> files = new ArrayList<>();
|
File hpsfTestDir = _samples.getFile("");
|
||||||
|
|
||||||
_samples.getFile("").listFiles(f -> {
|
File[] files = hpsfTestDir.listFiles(f -> true);
|
||||||
if (f.getName().startsWith("Test")) {
|
Objects.requireNonNull(files, "Could not find directory " + hpsfTestDir.getAbsolutePath());
|
||||||
files.add(new Object[]{ f });
|
|
||||||
}
|
// convert to list of object-arrays for @Parameterized
|
||||||
return false;
|
return Arrays.stream(files).
|
||||||
});
|
map(file1 -> new Object[] {file1}).
|
||||||
|
collect(Collectors.toList());
|
||||||
return files;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Parameter(value=0)
|
@Parameter()
|
||||||
public File file;
|
public File file;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -158,9 +157,11 @@ public class TestReadAllFiles {
|
||||||
*/
|
*/
|
||||||
if (dir.hasEntry(DocumentSummaryInformation.DEFAULT_STREAM_NAME)) {
|
if (dir.hasEntry(DocumentSummaryInformation.DEFAULT_STREAM_NAME)) {
|
||||||
final DocumentSummaryInformation dsi = TestWriteWellKnown.getDocumentSummaryInformation(poifs);
|
final DocumentSummaryInformation dsi = TestWriteWellKnown.getDocumentSummaryInformation(poifs);
|
||||||
|
assertNotNull(dsi);
|
||||||
|
|
||||||
/* Execute the get... methods. */
|
/* Execute the get... methods. */
|
||||||
dsi.getByteCount();
|
dsi.getByteCount();
|
||||||
|
//noinspection ResultOfMethodCallIgnored
|
||||||
dsi.getByteOrder();
|
dsi.getByteOrder();
|
||||||
dsi.getCategory();
|
dsi.getCategory();
|
||||||
dsi.getCompany();
|
dsi.getCompany();
|
||||||
|
|
|
@ -22,7 +22,6 @@ import static org.apache.poi.POITestCase.testPassesNow;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.Assert.assertNull;
|
||||||
import static org.junit.Assert.assertSame;
|
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
import static org.junit.Assume.assumeTrue;
|
import static org.junit.Assume.assumeTrue;
|
||||||
|
|
Loading…
Reference in New Issue