aboutsummaryrefslogtreecommitdiffstats
path: root/src/testcases/org/apache/poi
diff options
context:
space:
mode:
Diffstat (limited to 'src/testcases/org/apache/poi')
-rw-r--r--src/testcases/org/apache/poi/POITestCase.java22
-rw-r--r--src/testcases/org/apache/poi/ddf/TestEscherDump.java7
-rw-r--r--src/testcases/org/apache/poi/hpsf/basic/TestBasic.java36
-rw-r--r--src/testcases/org/apache/poi/hssf/dev/TestBiffViewer.java11
-rw-r--r--src/testcases/org/apache/poi/hssf/dev/TestEFBiffViewer.java8
-rw-r--r--src/testcases/org/apache/poi/hssf/dev/TestFormulaViewer.java9
-rw-r--r--src/testcases/org/apache/poi/hssf/dev/TestReSave.java13
-rw-r--r--src/testcases/org/apache/poi/hssf/dev/TestRecordLister.java8
-rw-r--r--src/testcases/org/apache/poi/hssf/extractor/TestOldExcelExtractor.java24
-rw-r--r--src/testcases/org/apache/poi/hssf/model/AllModelTests.java38
-rw-r--r--src/testcases/org/apache/poi/hssf/model/TestRowBlocksReader.java17
-rw-r--r--src/testcases/org/apache/poi/hssf/record/TestSSTRecord.java65
-rw-r--r--src/testcases/org/apache/poi/hssf/record/aggregates/AllRecordAggregateTests.java29
-rw-r--r--src/testcases/org/apache/poi/hssf/record/aggregates/TestRowRecordsAggregate.java55
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/TestOLE2Embeding.java64
-rw-r--r--src/testcases/org/apache/poi/poifs/filesystem/TestNPOIFSMiniStore.java36
-rw-r--r--src/testcases/org/apache/poi/poifs/property/AllPOIFSPropertyTests.java24
-rw-r--r--src/testcases/org/apache/poi/poifs/property/TestDirectoryProperty.java26
-rw-r--r--src/testcases/org/apache/poi/poifs/property/TestDocumentProperty.java3
-rw-r--r--src/testcases/org/apache/poi/poifs/property/TestRootProperty.java14
-rw-r--r--src/testcases/org/apache/poi/ss/usermodel/TestFractionFormat.java20
-rw-r--r--src/testcases/org/apache/poi/util/TestHexDump.java172
-rw-r--r--src/testcases/org/apache/poi/util/TestTempFile.java29
23 files changed, 381 insertions, 349 deletions
diff --git a/src/testcases/org/apache/poi/POITestCase.java b/src/testcases/org/apache/poi/POITestCase.java
index 3d0cea51dc..6de936fddf 100644
--- a/src/testcases/org/apache/poi/POITestCase.java
+++ b/src/testcases/org/apache/poi/POITestCase.java
@@ -17,16 +17,17 @@
package org.apache.poi;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
import java.util.Collection;
-import junit.framework.TestCase;
-
/**
* Parent class for POI JUnit TestCases, which provide additional
* features
*/
-public class POITestCase extends TestCase {
+public class POITestCase {
public static void assertContains(String haystack, String needle) {
assertTrue(
"Unable to find expected text '" + needle + "' in text:\n" + haystack,
@@ -40,21 +41,6 @@ public class POITestCase extends TestCase {
);
}
- public static <T> void assertEquals(T[] expected, T[] actual)
- {
- assertEquals("Non-matching lengths", expected.length, actual.length);
- for (int i=0; i<expected.length; i++) {
- assertEquals("Mis-match at offset " + i, expected[i], actual[i]);
- }
- }
- public static void assertEquals(byte[] expected, byte[] actual)
- {
- assertEquals("Non-matching lengths", expected.length, actual.length);
- for (int i=0; i<expected.length; i++) {
- assertEquals("Mis-match at offset " + i, expected[i], actual[i]);
- }
- }
-
public static <T> void assertContains(T needle, T[] haystack)
{
// Check
diff --git a/src/testcases/org/apache/poi/ddf/TestEscherDump.java b/src/testcases/org/apache/poi/ddf/TestEscherDump.java
index 718585592f..efc6427144 100644
--- a/src/testcases/org/apache/poi/ddf/TestEscherDump.java
+++ b/src/testcases/org/apache/poi/ddf/TestEscherDump.java
@@ -23,12 +23,15 @@ import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;
+import java.io.UnsupportedEncodingException;
import org.apache.poi.POIDataSamples;
import org.apache.poi.hssf.HSSFTestDataSamples;
import org.apache.poi.util.IOUtils;
+import org.apache.poi.util.LocaleUtil;
import org.junit.Test;
+@SuppressWarnings("resource")
public class TestEscherDump {
@Test
public void testSimple() throws Exception {
@@ -64,8 +67,8 @@ public class TestEscherDump {
* to redirect stdout to avoid spamming the console with output
*/
private static class NullPrinterStream extends PrintStream {
- private NullPrinterStream() {
- super(new NullOutputStream());
+ private NullPrinterStream() throws UnsupportedEncodingException {
+ super(new NullOutputStream(),true,LocaleUtil.CHARSET_1252.name());
}
/**
* Implementation of an OutputStream which does nothing, used
diff --git a/src/testcases/org/apache/poi/hpsf/basic/TestBasic.java b/src/testcases/org/apache/poi/hpsf/basic/TestBasic.java
index b9b0edec84..ef902c0836 100644
--- a/src/testcases/org/apache/poi/hpsf/basic/TestBasic.java
+++ b/src/testcases/org/apache/poi/hpsf/basic/TestBasic.java
@@ -17,6 +17,11 @@
package org.apache.poi.hpsf.basic;
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileNotFoundException;
@@ -25,8 +30,6 @@ import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.util.List;
-import junit.framework.TestCase;
-
import org.apache.poi.POIDataSamples;
import org.apache.poi.hpsf.DocumentSummaryInformation;
import org.apache.poi.hpsf.HPSFException;
@@ -37,13 +40,15 @@ import org.apache.poi.hpsf.PropertySetFactory;
import org.apache.poi.hpsf.Section;
import org.apache.poi.hpsf.SummaryInformation;
import org.apache.poi.hpsf.wellknown.SectionIDMap;
+import org.junit.Before;
+import org.junit.Test;
/**
* <p>Tests the basic HPSF functionality.</p>
*
* @author Rainer Klute (klute@rainer-klute.de)
*/
-public final class TestBasic extends TestCase {
+public final class TestBasic {
private static final String POI_FS = "TestGermanWord90.doc";
private static final String[] POI_FILES = new String[]
@@ -80,6 +85,7 @@ public final class TestBasic extends TestCase {
* @exception FileNotFoundException if the file to be read does not exist.
* @exception IOException if any other I/O exception occurs.
*/
+ @Before
public void setUp() throws IOException
{
POIDataSamples samples = POIDataSamples.getHPSFInstance();
@@ -91,6 +97,7 @@ public final class TestBasic extends TestCase {
* <p>Checks the names of the files in the POI filesystem. They
* are expected to be in a certain order.</p>
*/
+ @Test
public void testReadFiles()
{
String[] expected = POI_FILES;
@@ -112,6 +119,7 @@ public final class TestBasic extends TestCase {
* @exception UnsupportedEncodingException if a character encoding is not
* supported.
*/
+ @Test
public void testCreatePropertySets()
throws UnsupportedEncodingException, IOException
{
@@ -152,24 +160,21 @@ public final class TestBasic extends TestCase {
* @exception IOException if an I/O exception occurs
* @exception HPSFException if any HPSF exception occurs
*/
+ @Test
public void testPropertySetMethods() throws IOException, HPSFException
{
/* Loop over the two property sets. */
for (int i = 0; i < 2; i++)
{
byte[] b = poiFiles[i].getBytes();
- PropertySet ps =
- PropertySetFactory.create(new ByteArrayInputStream(b));
- assertEquals(ps.getByteOrder(), BYTE_ORDER);
- assertEquals(ps.getFormat(), FORMAT);
- assertEquals(ps.getOSVersion(), OS_VERSION);
- assertEquals(new String(ps.getClassID().getBytes()),
- new String(CLASS_ID));
- assertEquals(ps.getSectionCount(), SECTION_COUNT[i]);
- assertEquals(ps.isSummaryInformation(),
- IS_SUMMARY_INFORMATION[i]);
- assertEquals(ps.isDocumentSummaryInformation(),
- IS_DOCUMENT_SUMMARY_INFORMATION[i]);
+ PropertySet ps = PropertySetFactory.create(new ByteArrayInputStream(b));
+ assertEquals(BYTE_ORDER, ps.getByteOrder());
+ assertEquals(FORMAT, ps.getFormat());
+ assertEquals(OS_VERSION, ps.getOSVersion());
+ assertArrayEquals(CLASS_ID, ps.getClassID().getBytes());
+ assertEquals(SECTION_COUNT[i], ps.getSectionCount());
+ assertEquals(IS_SUMMARY_INFORMATION[i], ps.isSummaryInformation());
+ assertEquals(IS_DOCUMENT_SUMMARY_INFORMATION[i], ps.isDocumentSummaryInformation());
}
}
@@ -181,6 +186,7 @@ public final class TestBasic extends TestCase {
* @exception IOException if an I/O exception occurs
* @exception HPSFException if any HPSF exception occurs
*/
+ @Test
public void testSectionMethods() throws IOException, HPSFException
{
final SummaryInformation si = (SummaryInformation)
diff --git a/src/testcases/org/apache/poi/hssf/dev/TestBiffViewer.java b/src/testcases/org/apache/poi/hssf/dev/TestBiffViewer.java
index c96aec4f7f..0463162daf 100644
--- a/src/testcases/org/apache/poi/hssf/dev/TestBiffViewer.java
+++ b/src/testcases/org/apache/poi/hssf/dev/TestBiffViewer.java
@@ -19,9 +19,11 @@ package org.apache.poi.hssf.dev;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
+import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import org.apache.poi.poifs.filesystem.NPOIFSFileSystem;
+import org.apache.poi.util.LocaleUtil;
public class TestBiffViewer extends BaseXLSIteratingTest {
static {
@@ -44,12 +46,13 @@ public class TestBiffViewer extends BaseXLSIteratingTest {
}
@Override
- void runOneFile(File file) throws IOException {
- NPOIFSFileSystem fs = new NPOIFSFileSystem(file, true);
+ void runOneFile(File fileIn) throws IOException {
+ NPOIFSFileSystem fs = new NPOIFSFileSystem(fileIn, true);
InputStream is = BiffViewer.getPOIFSInputStream(fs);
try {
- // use a NullOutputStream to not write the bytes anywhere for best runtime
- BiffViewer.runBiffViewer(new PrintWriter(NULL_OUTPUT_STREAM), is, true, true, true, false);
+ // use a NullOutputStream to not write the bytes anywhere for best runtime
+ PrintWriter dummy = new PrintWriter(new OutputStreamWriter(NULL_OUTPUT_STREAM, LocaleUtil.CHARSET_1252));
+ BiffViewer.runBiffViewer(dummy, is, true, true, true, false);
} finally {
is.close();
fs.close();
diff --git a/src/testcases/org/apache/poi/hssf/dev/TestEFBiffViewer.java b/src/testcases/org/apache/poi/hssf/dev/TestEFBiffViewer.java
index 32eaa924f4..0763a55875 100644
--- a/src/testcases/org/apache/poi/hssf/dev/TestEFBiffViewer.java
+++ b/src/testcases/org/apache/poi/hssf/dev/TestEFBiffViewer.java
@@ -20,6 +20,8 @@ import java.io.File;
import java.io.IOException;
import java.io.PrintStream;
+import org.apache.poi.util.LocaleUtil;
+
public class TestEFBiffViewer extends BaseXLSIteratingTest {
static {
// these are likely ok to fail
@@ -39,13 +41,13 @@ public class TestEFBiffViewer extends BaseXLSIteratingTest {
}
@Override
- void runOneFile(File file) throws IOException {
+ void runOneFile(File fileIn) throws IOException {
PrintStream save = System.out;
try {
// redirect standard out during the test to avoid spamming the console with output
- System.setOut(new PrintStream(NULL_OUTPUT_STREAM));
+ System.setOut(new PrintStream(NULL_OUTPUT_STREAM,true,LocaleUtil.CHARSET_1252.name()));
- EFBiffViewer.main(new String[] { file.getAbsolutePath() });
+ EFBiffViewer.main(new String[] { fileIn.getAbsolutePath() });
} finally {
System.setOut(save);
}
diff --git a/src/testcases/org/apache/poi/hssf/dev/TestFormulaViewer.java b/src/testcases/org/apache/poi/hssf/dev/TestFormulaViewer.java
index b6014376c5..1b2ef67e2c 100644
--- a/src/testcases/org/apache/poi/hssf/dev/TestFormulaViewer.java
+++ b/src/testcases/org/apache/poi/hssf/dev/TestFormulaViewer.java
@@ -19,6 +19,7 @@ package org.apache.poi.hssf.dev;
import java.io.File;
import java.io.PrintStream;
+import org.apache.poi.util.LocaleUtil;
import org.junit.Ignore;
import org.junit.Test;
@@ -39,15 +40,15 @@ public class TestFormulaViewer extends BaseXLSIteratingTest {
public void testMain() throws Exception {
}
- @Override
- void runOneFile(File file) throws Exception {
+ @Override
+ void runOneFile(File fileIn) throws Exception {
PrintStream save = System.out;
try {
// redirect standard out during the test to avoid spamming the console with output
- System.setOut(new PrintStream(NULL_OUTPUT_STREAM));
+ System.setOut(new PrintStream(NULL_OUTPUT_STREAM,true,LocaleUtil.CHARSET_1252.name()));
FormulaViewer viewer = new FormulaViewer();
- viewer.setFile(file.getAbsolutePath());
+ viewer.setFile(fileIn.getAbsolutePath());
viewer.setList(true);
viewer.run();
} finally {
diff --git a/src/testcases/org/apache/poi/hssf/dev/TestReSave.java b/src/testcases/org/apache/poi/hssf/dev/TestReSave.java
index e26bffea3a..d858f881eb 100644
--- a/src/testcases/org/apache/poi/hssf/dev/TestReSave.java
+++ b/src/testcases/org/apache/poi/hssf/dev/TestReSave.java
@@ -24,6 +24,7 @@ import java.util.ArrayList;
import java.util.List;
import org.apache.poi.POIDataSamples;
+import org.apache.poi.util.LocaleUtil;
public class TestReSave extends BaseXLSIteratingTest {
static {
@@ -36,20 +37,20 @@ public class TestReSave extends BaseXLSIteratingTest {
}
@Override
- void runOneFile(File file) throws Exception {
+ void runOneFile(File fileIn) throws Exception {
// avoid running on files leftover from previous failed runs
- if(file.getName().endsWith("-saved.xls")) {
+ if(fileIn.getName().endsWith("-saved.xls")) {
return;
}
PrintStream save = System.out;
try {
// redirect standard out during the test to avoid spamming the console with output
- System.setOut(new PrintStream(NULL_OUTPUT_STREAM));
+ System.setOut(new PrintStream(NULL_OUTPUT_STREAM,true,LocaleUtil.CHARSET_1252.name()));
- File reSavedFile = new File(file.getParentFile(), file.getName().replace(".xls", "-saved.xls"));
+ File reSavedFile = new File(fileIn.getParentFile(), fileIn.getName().replace(".xls", "-saved.xls"));
try {
- ReSave.main(new String[] { file.getAbsolutePath() });
+ ReSave.main(new String[] { fileIn.getAbsolutePath() });
// also try BiffViewer on the saved file
new TestBiffViewer().runOneFile(reSavedFile);
@@ -59,7 +60,7 @@ public class TestReSave extends BaseXLSIteratingTest {
ReSave.main(new String[] { reSavedFile.getAbsolutePath() });
} finally {
// clean up the re-re-saved file
- new File(file.getParentFile(), reSavedFile.getName().replace(".xls", "-saved.xls")).delete();
+ new File(fileIn.getParentFile(), reSavedFile.getName().replace(".xls", "-saved.xls")).delete();
}
} finally {
// clean up the re-saved file
diff --git a/src/testcases/org/apache/poi/hssf/dev/TestRecordLister.java b/src/testcases/org/apache/poi/hssf/dev/TestRecordLister.java
index 4c0ad1add0..7f53793043 100644
--- a/src/testcases/org/apache/poi/hssf/dev/TestRecordLister.java
+++ b/src/testcases/org/apache/poi/hssf/dev/TestRecordLister.java
@@ -20,6 +20,8 @@ import java.io.File;
import java.io.IOException;
import java.io.PrintStream;
+import org.apache.poi.util.LocaleUtil;
+
public class TestRecordLister extends BaseXLSIteratingTest {
static {
// these are likely ok to fail
@@ -31,14 +33,14 @@ public class TestRecordLister extends BaseXLSIteratingTest {
}
@Override
- void runOneFile(File file) throws IOException {
+ void runOneFile(File fileIn) throws IOException {
PrintStream save = System.out;
try {
// redirect standard out during the test to avoid spamming the console with output
- System.setOut(new PrintStream(NULL_OUTPUT_STREAM));
+ System.setOut(new PrintStream(NULL_OUTPUT_STREAM,true,LocaleUtil.CHARSET_1252.name()));
RecordLister viewer = new RecordLister();
- viewer.setFile(file.getAbsolutePath());
+ viewer.setFile(fileIn.getAbsolutePath());
viewer.run();
} finally {
System.setOut(save);
diff --git a/src/testcases/org/apache/poi/hssf/extractor/TestOldExcelExtractor.java b/src/testcases/org/apache/poi/hssf/extractor/TestOldExcelExtractor.java
index bb2cfea66f..0a236a2908 100644
--- a/src/testcases/org/apache/poi/hssf/extractor/TestOldExcelExtractor.java
+++ b/src/testcases/org/apache/poi/hssf/extractor/TestOldExcelExtractor.java
@@ -17,27 +17,32 @@
package org.apache.poi.hssf.extractor;
+import static org.apache.poi.POITestCase.assertContains;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
import java.io.File;
-import java.io.InputStream;
-import org.apache.poi.POITestCase;
import org.apache.poi.hssf.HSSFTestDataSamples;
+import org.junit.Test;
/**
* Unit tests for the Excel 5/95 and Excel 4 (and older) text
* extractor
*/
-public final class TestOldExcelExtractor extends POITestCase {
+public final class TestOldExcelExtractor {
private static OldExcelExtractor createExtractor(String sampleFileName) {
- InputStream is = HSSFTestDataSamples.openSampleFileStream(sampleFileName);
+ File file = HSSFTestDataSamples.getSampleFile(sampleFileName);
try {
- return new OldExcelExtractor(is);
+ return new OldExcelExtractor(file);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
+ @Test
public void testSimpleExcel3() {
OldExcelExtractor extractor = createExtractor("testEXCEL_3.xls");
@@ -59,6 +64,8 @@ public final class TestOldExcelExtractor extends POITestCase {
assertEquals(3, extractor.getBiffVersion());
assertEquals(0x10, extractor.getFileType());
}
+
+ @Test
public void testSimpleExcel4() {
OldExcelExtractor extractor = createExtractor("testEXCEL_4.xls");
@@ -77,6 +84,8 @@ public final class TestOldExcelExtractor extends POITestCase {
assertEquals(4, extractor.getBiffVersion());
assertEquals(0x10, extractor.getFileType());
}
+
+ @Test
public void testSimpleExcel5() {
for (String ver : new String[] {"5", "95"}) {
OldExcelExtractor extractor = createExtractor("testEXCEL_"+ver+".xls");
@@ -101,6 +110,7 @@ public final class TestOldExcelExtractor extends POITestCase {
}
}
+ @Test
public void testStrings() {
OldExcelExtractor extractor = createExtractor("testEXCEL_4.xls");
String text = extractor.getText();
@@ -119,6 +129,7 @@ public final class TestOldExcelExtractor extends POITestCase {
// TODO Find some then test
}
+ @Test
public void testFormattedNumbersExcel4() {
OldExcelExtractor extractor = createExtractor("testEXCEL_4.xls");
String text = extractor.getText();
@@ -136,6 +147,8 @@ public final class TestOldExcelExtractor extends POITestCase {
// assertContains(text, "55,624");
// assertContains(text, "11,743,477");
}
+
+ @Test
public void testFormattedNumbersExcel5() {
for (String ver : new String[] {"5", "95"}) {
OldExcelExtractor extractor = createExtractor("testEXCEL_"+ver+".xls");
@@ -160,6 +173,7 @@ public final class TestOldExcelExtractor extends POITestCase {
}
}
+ @Test
public void testFromFile() throws Exception {
for (String ver : new String[] {"4", "5", "95"}) {
String filename = "testEXCEL_"+ver+".xls";
diff --git a/src/testcases/org/apache/poi/hssf/model/AllModelTests.java b/src/testcases/org/apache/poi/hssf/model/AllModelTests.java
index a243226867..0d140ab7d3 100644
--- a/src/testcases/org/apache/poi/hssf/model/AllModelTests.java
+++ b/src/testcases/org/apache/poi/hssf/model/AllModelTests.java
@@ -17,30 +17,26 @@
package org.apache.poi.hssf.model;
-import junit.framework.Test;
-import junit.framework.TestSuite;
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
/**
* Collects all tests for <tt>org.apache.poi.hssf.model</tt>.
- *
- * @author Josh Micich
*/
+@RunWith(Suite.class)
+@Suite.SuiteClasses({
+ TestDrawingManager.class,
+ TestDrawingManager2.class,
+ TestFormulaParser.class,
+ TestFormulaParserEval.class,
+ TestFormulaParserIf.class,
+ TestLinkTable.class,
+ TestOperandClassTransformer.class,
+ TestRowBlocksReader.class,
+ TestRVA.class,
+ TestSheet.class,
+ TestSheetAdditional.class,
+ TestWorkbook.class
+})
public final class AllModelTests {
-
- public static Test suite() {
- TestSuite result = new TestSuite(AllModelTests.class.getName());
- result.addTestSuite(TestDrawingManager.class);
- result.addTestSuite(TestDrawingManager2.class);
- result.addTestSuite(TestFormulaParser.class);
- result.addTestSuite(TestFormulaParserEval.class);
- result.addTestSuite(TestFormulaParserIf.class);
- result.addTestSuite(TestLinkTable.class);
- result.addTestSuite(TestOperandClassTransformer.class);
- result.addTestSuite(TestRowBlocksReader.class);
- result.addTestSuite(TestRVA.class);
- result.addTestSuite(TestSheet.class);
- result.addTestSuite(TestSheetAdditional.class);
- result.addTestSuite(TestWorkbook.class);
- return result;
- }
}
diff --git a/src/testcases/org/apache/poi/hssf/model/TestRowBlocksReader.java b/src/testcases/org/apache/poi/hssf/model/TestRowBlocksReader.java
index 3dd24aeeea..bf1fce7996 100644
--- a/src/testcases/org/apache/poi/hssf/model/TestRowBlocksReader.java
+++ b/src/testcases/org/apache/poi/hssf/model/TestRowBlocksReader.java
@@ -17,10 +17,12 @@
package org.apache.poi.hssf.model;
-import java.util.Arrays;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
-import junit.framework.AssertionFailedError;
-import junit.framework.TestCase;
+import java.util.Arrays;
import org.apache.poi.hssf.record.NumberRecord;
import org.apache.poi.hssf.record.Record;
@@ -28,27 +30,30 @@ import org.apache.poi.hssf.record.RowRecord;
import org.apache.poi.hssf.record.UnknownRecord;
import org.apache.poi.hssf.record.WindowTwoRecord;
import org.apache.poi.hssf.record.pivottable.ViewDefinitionRecord;
+import org.apache.poi.util.LocaleUtil;
+import org.junit.Test;
/**
* Tests for {@link RowBlocksReader}
*
* @author Josh Micich
*/
-public final class TestRowBlocksReader extends TestCase {
+public final class TestRowBlocksReader {
+ @Test
public void testAbnormalPivotTableRecords_bug46280() {
int SXVIEW_SID = ViewDefinitionRecord.sid;
Record[] inRecs = {
new RowRecord(0),
new NumberRecord(),
// normally MSODRAWING(0x00EC) would come here before SXVIEW
- new UnknownRecord(SXVIEW_SID, "dummydata (SXVIEW: View Definition)".getBytes()),
+ new UnknownRecord(SXVIEW_SID, "dummydata (SXVIEW: View Definition)".getBytes(LocaleUtil.CHARSET_1252)),
new WindowTwoRecord(),
};
RecordStream rs = new RecordStream(Arrays.asList(inRecs), 0);
RowBlocksReader rbr = new RowBlocksReader(rs);
if (rs.peekNextClass() == WindowTwoRecord.class) {
// Should have stopped at the SXVIEW record
- throw new AssertionFailedError("Identified bug 46280b");
+ fail("Identified bug 46280b");
}
RecordStream rbStream = rbr.getPlainRecordStream();
assertEquals(inRecs[0], rbStream.getNext());
diff --git a/src/testcases/org/apache/poi/hssf/record/TestSSTRecord.java b/src/testcases/org/apache/poi/hssf/record/TestSSTRecord.java
index 30b9aff177..cd98ee0840 100644
--- a/src/testcases/org/apache/poi/hssf/record/TestSSTRecord.java
+++ b/src/testcases/org/apache/poi/hssf/record/TestSSTRecord.java
@@ -18,6 +18,9 @@
package org.apache.poi.hssf.record;
import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
@@ -28,21 +31,22 @@ import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Iterator;
-import junit.framework.AssertionFailedError;
-import junit.framework.TestCase;
-
import org.apache.poi.hssf.HSSFTestDataSamples;
import org.apache.poi.hssf.record.common.UnicodeString;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.util.HexRead;
import org.apache.poi.util.LittleEndian;
+import org.apache.poi.util.LocaleUtil;
+import org.junit.Test;
+
+import junit.framework.AssertionFailedError;
/**
* @author Marc Johnson (mjohnson at apache dot org)
* @author Glen Stampoultzis (glens at apache.org)
*/
-public final class TestSSTRecord extends TestCase {
+public final class TestSSTRecord {
/**
* decodes hexdump files and concatenates the results
@@ -55,7 +59,7 @@ public final class TestSSTRecord extends TestCase {
for (int i = 0; i < nFiles; i++) {
String sampleFileName = hexDumpFileNames[i];
InputStream is = HSSFTestDataSamples.openSampleFileStream(sampleFileName);
- BufferedReader br = new BufferedReader(new InputStreamReader(is));
+ BufferedReader br = new BufferedReader(new InputStreamReader(is, LocaleUtil.CHARSET_1252));
while (true) {
String line = br.readLine();
@@ -86,6 +90,7 @@ public final class TestSSTRecord extends TestCase {
* SST is often split over several {@link ContinueRecord}s
* @throws IOException
*/
+ @Test
public void testContinuedRecord() throws IOException {
byte[] origData;
SSTRecord record;
@@ -109,20 +114,20 @@ public final class TestSSTRecord extends TestCase {
assertEquals( 5249, record.getNumUniqueStrings() );
assertEquals( 5249, record.countStrings() );
ser_output = record.serialize();
- if (false) { // set true to observe make sure areSameSSTs() is working
- ser_output[11000] = 'X';
- }
+// if (false) { // set true to observe make sure areSameSSTs() is working
+// ser_output[11000] = 'X';
+// }
SSTRecord rec2 = createSSTFromRawData(ser_output);
if (!areSameSSTs(record, rec2)) {
throw new AssertionFailedError("large SST re-serialized incorrectly");
}
- if (false) {
- // TODO - trivial differences in ContinueRecord break locations
- // Sample data should be checked against what most recent Excel version produces.
- // maybe tweaks are required in ContinuableRecordOutput
- assertArrayEquals(origData, ser_output);
- }
+// if (false) {
+// // TODO - trivial differences in ContinueRecord break locations
+// // Sample data should be checked against what most recent Excel version produces.
+// // maybe tweaks are required in ContinuableRecordOutput
+// assertArrayEquals(origData, ser_output);
+// }
}
private boolean areSameSSTs(SSTRecord a, SSTRecord b) {
@@ -147,7 +152,7 @@ public final class TestSSTRecord extends TestCase {
*
* @exception IOException
*/
-
+ @Test
public void testHugeStrings() {
SSTRecord record = new SSTRecord();
byte[][] bstrings =
@@ -161,7 +166,7 @@ public final class TestSSTRecord extends TestCase {
for ( int k = 0; k < bstrings.length; k++ )
{
Arrays.fill( bstrings[k], (byte) ( 'a' + k ) );
- strings[k] = new UnicodeString( new String(bstrings[k]) );
+ strings[k] = new UnicodeString( new String(bstrings[k], LocaleUtil.CHARSET_1252) );
record.addString( strings[k] );
total_length += 3 + bstrings[k].length;
}
@@ -198,7 +203,7 @@ public final class TestSSTRecord extends TestCase {
if ( ( bstrings[k].length % 2 ) == 1 )
{
Arrays.fill( bstrings[k], (byte) ( 'a' + k ) );
- strings[k] = new UnicodeString( new String(bstrings[k]) );
+ strings[k] = new UnicodeString( new String(bstrings[k], LocaleUtil.CHARSET_1252) );
}
else
{
@@ -230,6 +235,7 @@ public final class TestSSTRecord extends TestCase {
/**
* test SSTRecord boundary conditions
*/
+ @Test
public void testSSTRecordBug() {
// create an SSTRecord and write a certain pattern of strings
// to it ... then serialize it and verify the content
@@ -265,6 +271,7 @@ public final class TestSSTRecord extends TestCase {
/**
* test simple addString
*/
+ @Test
public void testSimpleAddString() {
SSTRecord record = new SSTRecord();
UnicodeString s1 = new UnicodeString("Hello world");
@@ -310,6 +317,7 @@ public final class TestSSTRecord extends TestCase {
/**
* test simple constructor
*/
+ @Test
public void testSimpleConstructor() {
SSTRecord record = new SSTRecord();
@@ -334,13 +342,16 @@ public final class TestSSTRecord extends TestCase {
/**
* Tests that workbooks with rich text that duplicates a non rich text cell can be read and written.
*/
- public void testReadWriteDuplicatedRichText1() {
+ @Test
+ public void testReadWriteDuplicatedRichText1() throws Exception {
HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("duprich1.xls");
HSSFSheet sheet = wb.getSheetAt( 1 );
assertEquals( "01/05 (Wed)", sheet.getRow( 0 ).getCell(8 ).getStringCellValue() );
assertEquals( "01/05 (Wed)", sheet.getRow( 1 ).getCell(8 ).getStringCellValue() );
- HSSFTestDataSamples.writeOutAndReadBack(wb);
+ HSSFTestDataSamples.writeOutAndReadBack(wb).close();
+
+ wb.close();
// test the second file.
wb = HSSFTestDataSamples.openSampleWorkbook("duprich2.xls");
@@ -353,7 +364,9 @@ public final class TestSSTRecord extends TestCase {
assertEquals( "Testing", sheet.getRow( row++ ).getCell(0 ).getStringCellValue() );
assertEquals( "Testing", sheet.getRow( row++ ).getCell(0 ).getStringCellValue() );
- HSSFTestDataSamples.writeOutAndReadBack(wb);
+ HSSFTestDataSamples.writeOutAndReadBack(wb).close();
+
+ wb.close();
}
/**
@@ -1447,7 +1460,7 @@ public final class TestSSTRecord extends TestCase {
/**
* deep comparison of two SST records
*/
- public static void assertEquals(SSTRecord expected, SSTRecord actual){
+ private static void assertRecordEquals(SSTRecord expected, SSTRecord actual){
assertEquals("number of strings", expected.getNumStrings(), actual.getNumStrings());
assertEquals("number of unique strings", expected.getNumUniqueStrings(), actual.getNumUniqueStrings());
assertEquals("count of strings", expected.countStrings(), actual.countStrings());
@@ -1458,8 +1471,8 @@ public final class TestSSTRecord extends TestCase {
assertTrue("String at idx=" + k, us1.equals(us2));
}
}
-
-
+
+ @Test
public void test50779_1(){
byte[] bytes = HexRead.readFromString(data_50779_1);
@@ -1475,9 +1488,10 @@ public final class TestSSTRecord extends TestCase {
SSTRecord dst = new SSTRecord(in);
assertEquals(81, dst.getNumStrings());
- assertEquals(src, dst);
+ assertRecordEquals(src, dst);
}
+ @Test
public void test50779_2() {
byte[] bytes = HexRead.readFromString(data_50779_2);
@@ -1493,9 +1507,10 @@ public final class TestSSTRecord extends TestCase {
SSTRecord dst = new SSTRecord(in);
assertEquals(81, dst.getNumStrings());
- assertEquals(src, dst);
+ assertRecordEquals(src, dst);
}
+ @Test
public void test57456() {
byte[] bytes = HexRead.readFromString("FC, 00, 08, 00, 00, 00, 00, 00, E1, 06, 00, 00");
RecordInputStream in = TestcaseRecordInputStream.create(bytes);
diff --git a/src/testcases/org/apache/poi/hssf/record/aggregates/AllRecordAggregateTests.java b/src/testcases/org/apache/poi/hssf/record/aggregates/AllRecordAggregateTests.java
index 57fe336b60..4edf3eb9c0 100644
--- a/src/testcases/org/apache/poi/hssf/record/aggregates/AllRecordAggregateTests.java
+++ b/src/testcases/org/apache/poi/hssf/record/aggregates/AllRecordAggregateTests.java
@@ -17,26 +17,21 @@
package org.apache.poi.hssf.record.aggregates;
-import junit.framework.Test;
-import junit.framework.TestSuite;
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
/**
* Collects all tests for package <tt>org.apache.poi.hssf.record.aggregates</tt>.
- *
- * @author Josh Micich
*/
+@RunWith(Suite.class)
+@Suite.SuiteClasses({
+ TestCFRecordsAggregate.class,
+ TestColumnInfoRecordsAggregate.class,
+ TestFormulaRecordAggregate.class,
+ TestRowRecordsAggregate.class,
+ TestSharedValueManager.class,
+ TestValueRecordsAggregate.class,
+ TestPageSettingsBlock.class
+})
public final class AllRecordAggregateTests {
-
- public static Test suite() {
- TestSuite result = new TestSuite(AllRecordAggregateTests.class.getName());
-
- result.addTestSuite(TestCFRecordsAggregate.class);
- result.addTestSuite(TestColumnInfoRecordsAggregate.class);
- result.addTestSuite(TestFormulaRecordAggregate.class);
- result.addTestSuite(TestRowRecordsAggregate.class);
- result.addTestSuite(TestSharedValueManager.class);
- result.addTestSuite(TestValueRecordsAggregate.class);
- result.addTestSuite(TestPageSettingsBlock.class);
- return result;
- }
}
diff --git a/src/testcases/org/apache/poi/hssf/record/aggregates/TestRowRecordsAggregate.java b/src/testcases/org/apache/poi/hssf/record/aggregates/TestRowRecordsAggregate.java
index 14a968612d..1d8b508c71 100644
--- a/src/testcases/org/apache/poi/hssf/record/aggregates/TestRowRecordsAggregate.java
+++ b/src/testcases/org/apache/poi/hssf/record/aggregates/TestRowRecordsAggregate.java
@@ -17,14 +17,12 @@
package org.apache.poi.hssf.record.aggregates;
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.OutputStream;
-import java.util.Arrays;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
-import junit.framework.AssertionFailedError;
-import junit.framework.TestCase;
+import java.util.Arrays;
import org.apache.poi.hssf.HSSFTestDataSamples;
import org.apache.poi.hssf.model.RecordStream;
@@ -42,12 +40,15 @@ import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.usermodel.RecordInspector;
import org.apache.poi.hssf.usermodel.RecordInspector.RecordCollector;
import org.apache.poi.hssf.util.CellRangeAddress8Bit;
+import org.apache.poi.util.LocaleUtil;
+import org.junit.Test;
/**
* Tests for {@link RowRecordsAggregate}
*/
-public final class TestRowRecordsAggregate extends TestCase {
+public final class TestRowRecordsAggregate {
+ @Test
public void testRowGet() {
RowRecordsAggregate rra = new RowRecordsAggregate();
RowRecord rr = new RowRecord(4);
@@ -67,7 +68,8 @@ public final class TestRowRecordsAggregate extends TestCase {
* {@link SharedFormulaRecord}s, these records should appear immediately after the first
* {@link FormulaRecord}s that they apply to (and only once).<br/>
*/
- public void testArraysAndTables() {
+ @Test
+ public void testArraysAndTables() throws Exception {
HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("testArraysAndTables.xls");
Record[] sheetRecs = RecordInspector.getRecords(wb.getSheetAt(0), 0);
@@ -82,20 +84,22 @@ public final class TestRowRecordsAggregate extends TestCase {
assertEquals(0, countSharedFormulas);
- if (false) { // set true to observe re-serialized file
- File f = new File(System.getProperty("java.io.tmpdir") + "/testArraysAndTables-out.xls");
- try {
- OutputStream os = new FileOutputStream(f);
- wb.write(os);
- os.close();
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- System.out.println("Output file to " + f.getAbsolutePath());
- }
+// if (false) { // set true to observe re-serialized file
+// File f = new File(System.getProperty("java.io.tmpdir") + "/testArraysAndTables-out.xls");
+// try {
+// OutputStream os = new FileOutputStream(f);
+// wb.write(os);
+// os.close();
+// } catch (IOException e) {
+// throw new RuntimeException(e);
+// }
+// System.out.println("Output file to " + f.getAbsolutePath());
+// }
+
+ wb.close();
}
- private static int verifySharedValues(Record[] recs, Class shfClass) {
+ private static int verifySharedValues(Record[] recs, Class<? extends SharedValueRecordBase> shfClass) {
int result =0;
for(int i=0; i<recs.length; i++) {
@@ -104,7 +108,7 @@ public final class TestRowRecordsAggregate extends TestCase {
result++;
Record prevRec = recs[i-1];
if (!(prevRec instanceof FormulaRecord)) {
- throw new AssertionFailedError("Bad record order at index "
+ fail("Bad record order at index "
+ i + ": Formula record expected but got ("
+ prevRec.getClass().getName() + ")");
}
@@ -130,12 +134,13 @@ public final class TestRowRecordsAggregate extends TestCase {
* This fix in {@link RowRecordsAggregate} was implemented anyway since any {@link
* UnknownRecord} has the potential of being 'continued'.
*/
+ @Test
public void testUnknownContinue_bug46280() {
Record[] inRecs = {
new RowRecord(0),
new NumberRecord(),
- new UnknownRecord(0x5555, "dummydata".getBytes()),
- new ContinueRecord("moredummydata".getBytes()),
+ new UnknownRecord(0x5555, "dummydata".getBytes(LocaleUtil.CHARSET_1252)),
+ new ContinueRecord("moredummydata".getBytes(LocaleUtil.CHARSET_1252)),
};
RecordStream rs = new RecordStream(Arrays.asList(inRecs), 0);
RowRecordsAggregate rra;
@@ -143,7 +148,7 @@ public final class TestRowRecordsAggregate extends TestCase {
rra = new RowRecordsAggregate(rs, SharedValueManager.createEmpty());
} catch (RuntimeException e) {
if (e.getMessage().startsWith("Unexpected record type")) {
- throw new AssertionFailedError("Identified bug 46280a");
+ fail("Identified bug 46280a");
}
throw e;
}
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestOLE2Embeding.java b/src/testcases/org/apache/poi/hssf/usermodel/TestOLE2Embeding.java
index e425acc1e4..262b66d3a4 100644
--- a/src/testcases/org/apache/poi/hssf/usermodel/TestOLE2Embeding.java
+++ b/src/testcases/org/apache/poi/hssf/usermodel/TestOLE2Embeding.java
@@ -18,16 +18,14 @@
package org.apache.poi.hssf.usermodel;
import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
-import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
-import junit.framework.TestCase;
-
import org.apache.poi.POIDataSamples;
import org.apache.poi.hssf.HSSFTestDataSamples;
import org.apache.poi.poifs.filesystem.DirectoryNode;
@@ -35,52 +33,59 @@ import org.apache.poi.poifs.filesystem.Ole10Native;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.ss.usermodel.ClientAnchor;
import org.apache.poi.ss.usermodel.CreationHelper;
+import org.apache.poi.util.LocaleUtil;
+import org.junit.Test;
/**
*
*/
-public final class TestOLE2Embeding extends TestCase {
+public final class TestOLE2Embeding {
- public void testEmbeding() {
+ @Test
+ public void testEmbeding() throws Exception {
// This used to break, until bug #43116 was fixed
HSSFWorkbook workbook = HSSFTestDataSamples.openSampleWorkbook("ole2-embedding.xls");
// Check we can get at the Escher layer still
workbook.getAllPictures();
+
+ workbook.close();
}
+ @Test
public void testEmbeddedObjects() throws Exception {
HSSFWorkbook workbook = HSSFTestDataSamples.openSampleWorkbook("ole2-embedding.xls");
List<HSSFObjectData> objects = workbook.getAllEmbeddedObjects();
assertEquals("Wrong number of objects", 2, objects.size());
assertEquals("Wrong name for first object", "MBD06CAB431",
- ((HSSFObjectData)
- objects.get(0)).getDirectory().getName());
+ objects.get(0).getDirectory().getName());
assertEquals("Wrong name for second object", "MBD06CAC85A",
- ((HSSFObjectData)
- objects.get(1)).getDirectory().getName());
+ objects.get(1).getDirectory().getName());
+
+ workbook.close();
}
+ @Test
public void testReallyEmbedSomething() throws Exception {
- HSSFWorkbook wb = new HSSFWorkbook();
- HSSFSheet sheet = wb.createSheet();
+ HSSFWorkbook wb1 = new HSSFWorkbook();
+ HSSFSheet sheet = wb1.createSheet();
HSSFPatriarch patriarch = sheet.createDrawingPatriarch();
byte[] pictureData = HSSFTestDataSamples.getTestDataFileContent("logoKarmokar4.png");
byte[] picturePPT = POIDataSamples.getSlideShowInstance().readFile("clock.jpg");
- int imgIdx = wb.addPicture(pictureData, HSSFWorkbook.PICTURE_TYPE_PNG);
+ int imgIdx = wb1.addPicture(pictureData, HSSFWorkbook.PICTURE_TYPE_PNG);
POIFSFileSystem pptPoifs = getSamplePPT();
- int pptIdx = wb.addOlePackage(pptPoifs, "Sample-PPT", "sample.ppt", "sample.ppt");
+ int pptIdx = wb1.addOlePackage(pptPoifs, "Sample-PPT", "sample.ppt", "sample.ppt");
POIFSFileSystem xlsPoifs = getSampleXLS();
- int imgPPT = wb.addPicture(picturePPT, HSSFWorkbook.PICTURE_TYPE_JPEG);
- int xlsIdx = wb.addOlePackage(xlsPoifs, "Sample-XLS", "sample.xls", "sample.xls");
- int txtIdx = wb.addOlePackage(getSampleTXT(), "Sample-TXT", "sample.txt", "sample.txt");
+ int imgPPT = wb1.addPicture(picturePPT, HSSFWorkbook.PICTURE_TYPE_JPEG);
+ int xlsIdx = wb1.addOlePackage(xlsPoifs, "Sample-XLS", "sample.xls", "sample.xls");
+ int txtIdx = wb1.addOlePackage(getSampleTXT(), "Sample-TXT", "sample.txt", "sample.txt");
int rowoffset = 5;
int coloffset = 5;
- CreationHelper ch = wb.getCreationHelper();
+ CreationHelper ch = wb1.getCreationHelper();
HSSFClientAnchor anchor = (HSSFClientAnchor)ch.createClientAnchor();
anchor.setAnchor((short)(2+coloffset), 1+rowoffset, 0, 0, (short)(3+coloffset), 5+rowoffset, 0, 0);
anchor.setAnchorType(ClientAnchor.DONT_MOVE_AND_RESIZE);
@@ -107,31 +112,35 @@ public final class TestOLE2Embeding extends TestCase {
circle.setShapeType(HSSFSimpleShape.OBJECT_TYPE_OVAL);
circle.setNoFill(true);
- if (false) {
- FileOutputStream fos = new FileOutputStream("embed.xls");
- wb.write(fos);
- fos.close();
- }
+// if (false) {
+// FileOutputStream fos = new FileOutputStream("embed.xls");
+// wb.write(fos);
+// fos.close();
+// }
- wb = HSSFTestDataSamples.writeOutAndReadBack(wb);
+ HSSFWorkbook wb2 = HSSFTestDataSamples.writeOutAndReadBack(wb1);
+ wb1.close();
ByteArrayOutputStream bos = new ByteArrayOutputStream();
- HSSFObjectData od = wb.getAllEmbeddedObjects().get(0);
+ HSSFObjectData od = wb2.getAllEmbeddedObjects().get(0);
Ole10Native ole10 = Ole10Native.createFromEmbeddedOleObject((DirectoryNode)od.getDirectory());
bos.reset();
pptPoifs.writeFilesystem(bos);
assertArrayEquals(ole10.getDataBuffer(), bos.toByteArray());
- od = wb.getAllEmbeddedObjects().get(1);
+ od = wb2.getAllEmbeddedObjects().get(1);
ole10 = Ole10Native.createFromEmbeddedOleObject((DirectoryNode)od.getDirectory());
bos.reset();
xlsPoifs.writeFilesystem(bos);
assertArrayEquals(ole10.getDataBuffer(), bos.toByteArray());
- od = wb.getAllEmbeddedObjects().get(2);
+ od = wb2.getAllEmbeddedObjects().get(2);
ole10 = Ole10Native.createFromEmbeddedOleObject((DirectoryNode)od.getDirectory());
assertArrayEquals(ole10.getDataBuffer(), getSampleTXT());
+ xlsPoifs.close();
+ pptPoifs.close();
+ wb2.close();
}
static POIFSFileSystem getSamplePPT() throws IOException {
@@ -150,12 +159,13 @@ public final class TestOLE2Embeding extends TestCase {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
wb.write(bos);
+ wb.close();
POIFSFileSystem poifs = new POIFSFileSystem(new ByteArrayInputStream(bos.toByteArray()));
return poifs;
}
static byte[] getSampleTXT() {
- return "All your base are belong to us".getBytes();
+ return "All your base are belong to us".getBytes(LocaleUtil.CHARSET_1252);
}
} \ No newline at end of file
diff --git a/src/testcases/org/apache/poi/poifs/filesystem/TestNPOIFSMiniStore.java b/src/testcases/org/apache/poi/poifs/filesystem/TestNPOIFSMiniStore.java
index 4f102084d7..d8eb43b423 100644
--- a/src/testcases/org/apache/poi/poifs/filesystem/TestNPOIFSMiniStore.java
+++ b/src/testcases/org/apache/poi/poifs/filesystem/TestNPOIFSMiniStore.java
@@ -17,25 +17,30 @@
package org.apache.poi.poifs.filesystem;
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
import java.io.ByteArrayInputStream;
import java.nio.ByteBuffer;
import java.util.Iterator;
import org.apache.poi.POIDataSamples;
-import org.apache.poi.POITestCase;
import org.apache.poi.poifs.common.POIFSConstants;
import org.apache.poi.util.IOUtils;
+import org.junit.Test;
/**
* Tests for the Mini Store in the NIO POIFS
*/
-public final class TestNPOIFSMiniStore extends POITestCase {
+public final class TestNPOIFSMiniStore {
private static final POIDataSamples _inst = POIDataSamples.getPOIFSInstance();
/**
* Check that for a given mini block, we can correctly figure
* out what the next one is
*/
+ @Test
public void testNextBlock() throws Exception {
// It's the same on 512 byte and 4096 byte block files!
NPOIFSFileSystem fsA = new NPOIFSFileSystem(_inst.getFile("BlockSize512.zvi"));
@@ -103,14 +108,17 @@ public final class TestNPOIFSMiniStore extends POITestCase {
for(int i=181; i<fs.getBigBlockSizeDetails().getBATEntriesPerBlock(); i++) {
assertEquals(POIFSConstants.UNUSED_BLOCK, ministore.getNextBlock(i));
}
-
- fs.close();
}
+ fsD.close();
+ fsC.close();
+ fsB.close();
+ fsA.close();
}
/**
* Check we get the right data back for each block
*/
+ @Test
public void testGetBlock() throws Exception {
// It's the same on 512 byte and 4096 byte block files!
NPOIFSFileSystem fsA = new NPOIFSFileSystem(_inst.getFile("BlockSize512.zvi"));
@@ -170,15 +178,18 @@ public final class TestNPOIFSMiniStore extends POITestCase {
assertEquals((byte)0, b.get());
assertEquals((byte)0, b.get());
}
-
- fs.close();
}
+ fsD.close();
+ fsC.close();
+ fsB.close();
+ fsA.close();
}
/**
* Ask for free blocks where there are some already
* to be had from the SFAT
*/
+ @Test
public void testGetFreeBlockWithSpare() throws Exception {
NPOIFSFileSystem fs = new NPOIFSFileSystem(_inst.getFile("BlockSize512.zvi"));
NPOIFSMiniStore ministore = fs.getMiniStore();
@@ -210,6 +221,7 @@ public final class TestNPOIFSMiniStore extends POITestCase {
* Ask for free blocks where no free ones exist, and so the
* stream needs to be extended and another SBAT added
*/
+ @Test
public void testGetFreeBlockWithNoneSpare() throws Exception {
NPOIFSFileSystem fs = new NPOIFSFileSystem(_inst.openResourceAsStream("BlockSize512.zvi"));
NPOIFSMiniStore ministore = fs.getMiniStore();
@@ -254,6 +266,7 @@ public final class TestNPOIFSMiniStore extends POITestCase {
* Test that we will extend the underlying chain of
* big blocks that make up the ministream as needed
*/
+ @Test
public void testCreateBlockIfNeeded() throws Exception {
NPOIFSFileSystem fs = new NPOIFSFileSystem(_inst.openResourceAsStream("BlockSize512.zvi"));
NPOIFSMiniStore ministore = fs.getMiniStore();
@@ -334,6 +347,7 @@ public final class TestNPOIFSMiniStore extends POITestCase {
fs.close();
}
+ @Test
public void testCreateMiniStoreFirst() throws Exception {
NPOIFSFileSystem fs = new NPOIFSFileSystem();
NPOIFSMiniStore ministore = fs.getMiniStore();
@@ -385,7 +399,7 @@ public final class TestNPOIFSMiniStore extends POITestCase {
byte[] rdata = new byte[data.length];
dis = new DocumentInputStream(entry);
IOUtils.readFully(dis, rdata);
- assertEquals(data, rdata);
+ assertArrayEquals(data, rdata);
dis.close();
entry = (DocumentEntry)fs.getRoot().getEntry("mini2");
@@ -393,13 +407,14 @@ public final class TestNPOIFSMiniStore extends POITestCase {
rdata = new byte[data.length];
dis = new DocumentInputStream(entry);
IOUtils.readFully(dis, rdata);
- assertEquals(data, rdata);
+ assertArrayEquals(data, rdata);
dis.close();
// Done
fs.close();
}
+ @Test
public void testMultiBlockStream() throws Exception {
byte[] data1B = new byte[63];
byte[] data2B = new byte[64+14];
@@ -451,12 +466,13 @@ public final class TestNPOIFSMiniStore extends POITestCase {
DocumentInputStream dis = fs.createDocumentInputStream("mini1");
IOUtils.readFully(dis, r1);
dis.close();
- assertEquals(data1B, r1);
+ assertArrayEquals(data1B, r1);
byte[] r2 = new byte[data2B.length];
dis = fs.createDocumentInputStream("mini2");
IOUtils.readFully(dis, r2);
dis.close();
- assertEquals(data2B, r2);
+ assertArrayEquals(data2B, r2);
+ fs.close();
}
}
diff --git a/src/testcases/org/apache/poi/poifs/property/AllPOIFSPropertyTests.java b/src/testcases/org/apache/poi/poifs/property/AllPOIFSPropertyTests.java
index 99d4c99be5..c4f03a35b8 100644
--- a/src/testcases/org/apache/poi/poifs/property/AllPOIFSPropertyTests.java
+++ b/src/testcases/org/apache/poi/poifs/property/AllPOIFSPropertyTests.java
@@ -17,23 +17,19 @@
package org.apache.poi.poifs.property;
-import junit.framework.Test;
-import junit.framework.TestSuite;
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
/**
* Tests for org.apache.poi.poifs.property<br/>
- *
- * @author Josh Micich
*/
+@RunWith(Suite.class)
+@Suite.SuiteClasses({
+ TestDirectoryProperty.class,
+ TestDocumentProperty.class,
+ TestPropertyFactory.class,
+ TestPropertyTable.class,
+ TestRootProperty.class
+})
public final class AllPOIFSPropertyTests {
-
- public static Test suite() {
- TestSuite result = new TestSuite(AllPOIFSPropertyTests.class.getName());
- result.addTestSuite(TestDirectoryProperty.class);
- result.addTestSuite(TestDocumentProperty.class);
- result.addTestSuite(TestPropertyFactory.class);
- result.addTestSuite(TestPropertyTable.class);
- result.addTestSuite(TestRootProperty.class);
- return result;
- }
}
diff --git a/src/testcases/org/apache/poi/poifs/property/TestDirectoryProperty.java b/src/testcases/org/apache/poi/poifs/property/TestDirectoryProperty.java
index 9569de1d4b..8db101c25d 100644
--- a/src/testcases/org/apache/poi/poifs/property/TestDirectoryProperty.java
+++ b/src/testcases/org/apache/poi/poifs/property/TestDirectoryProperty.java
@@ -17,6 +17,10 @@
package org.apache.poi.poifs.property;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.ArrayList;
@@ -25,21 +29,20 @@ import java.util.Iterator;
import java.util.List;
import org.apache.poi.poifs.storage.RawDataUtil;
-
-import junit.framework.TestCase;
+import org.apache.poi.util.LocaleUtil;
+import org.junit.Test;
/**
* Class to test DirectoryProperty functionality
- *
- * @author Marc Johnson
*/
-public final class TestDirectoryProperty extends TestCase {
+public final class TestDirectoryProperty {
private DirectoryProperty _property;
private byte[] _testblock;
/**
* Test constructing DirectoryProperty
*/
+ @Test
public void testConstructor() throws IOException {
createBasicDirectoryProperty();
verifyProperty();
@@ -48,6 +51,7 @@ public final class TestDirectoryProperty extends TestCase {
/**
* Test pre-write functionality
*/
+ @Test
public void testPreWrite() throws IOException {
createBasicDirectoryProperty();
_property.preWrite();
@@ -97,8 +101,8 @@ public final class TestDirectoryProperty extends TestCase {
}
private void verifyChildren(int count) {
- Iterator iter = _property.getChildren();
- List children = new ArrayList();
+ Iterator<Property> iter = _property.getChildren();
+ List<Property> children = new ArrayList<Property>();
while (iter.hasNext())
{
@@ -116,7 +120,7 @@ public final class TestDirectoryProperty extends TestCase {
iter = children.iterator();
while (iter.hasNext())
{
- Property child = ( Property ) iter.next();
+ Property child = iter.next();
Child next = child.getNextChild();
if (next != null)
@@ -175,7 +179,7 @@ public final class TestDirectoryProperty extends TestCase {
{
_testblock[ index ] = ( byte ) 0;
}
- byte[] name_bytes = name.getBytes();
+ byte[] name_bytes = name.getBytes(LocaleUtil.CHARSET_1252);
for (index = 0; index < limit; index++)
{
@@ -197,6 +201,7 @@ public final class TestDirectoryProperty extends TestCase {
}
}
+ @Test
public void testAddChild() throws IOException {
createBasicDirectoryProperty();
_property.addChild(new LocalProperty(1));
@@ -224,6 +229,7 @@ public final class TestDirectoryProperty extends TestCase {
_property.addChild(new LocalProperty(3));
}
+ @Test
public void testDeleteChild() throws IOException {
createBasicDirectoryProperty();
Property p1 = new LocalProperty(1);
@@ -244,6 +250,7 @@ public final class TestDirectoryProperty extends TestCase {
_property.addChild(new LocalProperty(1));
}
+ @Test
public void testChangeName() throws IOException {
createBasicDirectoryProperty();
Property p1 = new LocalProperty(1);
@@ -262,6 +269,7 @@ public final class TestDirectoryProperty extends TestCase {
assertTrue(_property.changeName(p1, originalName));
}
+ @Test
public void testReadingConstructor() {
String[] input = {
"42 00 6F 00 6F 00 74 00 20 00 45 00 6E 00 74 00 72 00 79 00 00 00 00 00 00 00 00 00 00 00 00 00",
diff --git a/src/testcases/org/apache/poi/poifs/property/TestDocumentProperty.java b/src/testcases/org/apache/poi/poifs/property/TestDocumentProperty.java
index 41acc760bc..bd0b30edde 100644
--- a/src/testcases/org/apache/poi/poifs/property/TestDocumentProperty.java
+++ b/src/testcases/org/apache/poi/poifs/property/TestDocumentProperty.java
@@ -21,6 +21,7 @@ import java.io.ByteArrayOutputStream;
import java.io.IOException;
import org.apache.poi.poifs.storage.RawDataUtil;
+import org.apache.poi.util.LocaleUtil;
import junit.framework.TestCase;
@@ -137,7 +138,7 @@ public final class TestDocumentProperty extends TestCase {
{
testblock[ index ] = ( byte ) 0x0;
}
- byte[] name_bytes = name.getBytes();
+ byte[] name_bytes = name.getBytes(LocaleUtil.CHARSET_1252);
for (index = 0; index < limit; index++)
{
diff --git a/src/testcases/org/apache/poi/poifs/property/TestRootProperty.java b/src/testcases/org/apache/poi/poifs/property/TestRootProperty.java
index 46c073096b..27708a4b61 100644
--- a/src/testcases/org/apache/poi/poifs/property/TestRootProperty.java
+++ b/src/testcases/org/apache/poi/poifs/property/TestRootProperty.java
@@ -17,23 +17,27 @@
package org.apache.poi.poifs.property;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
import java.io.ByteArrayOutputStream;
import java.io.IOException;
-import junit.framework.TestCase;
-
import org.apache.poi.poifs.common.POIFSConstants;
import org.apache.poi.poifs.storage.RawDataUtil;
+import org.apache.poi.util.LocaleUtil;
+import org.junit.Test;
/**
* Class to test RootProperty functionality
*
* @author Marc Johnson
*/
-public final class TestRootProperty extends TestCase {
+public final class TestRootProperty {
private RootProperty _property;
private byte[] _testblock;
+ @Test
public void testConstructor() throws IOException {
createBasicRootProperty();
verifyProperty();
@@ -67,7 +71,7 @@ public final class TestRootProperty extends TestCase {
for (; index < 0x80; index++) {
_testblock[index] = (byte) 0;
}
- byte[] name_bytes = name.getBytes();
+ byte[] name_bytes = name.getBytes(LocaleUtil.CHARSET_1252);
for (index = 0; index < limit; index++) {
_testblock[index * 2] = name_bytes[index];
@@ -86,6 +90,7 @@ public final class TestRootProperty extends TestCase {
}
}
+ @Test
public void testSetSize() {
for (int j = 0; j < 10; j++) {
createBasicRootProperty();
@@ -94,6 +99,7 @@ public final class TestRootProperty extends TestCase {
}
}
+ @Test
public void testReadingConstructor() {
String[] input = {
"52 00 6F 00 6F 00 74 00 20 00 45 00 6E 00 74 00 72 00 79 00 00 00 00 00 00 00 00 00 00 00 00 00",
diff --git a/src/testcases/org/apache/poi/ss/usermodel/TestFractionFormat.java b/src/testcases/org/apache/poi/ss/usermodel/TestFractionFormat.java
index 1db2507ea6..6fd632c0c5 100644
--- a/src/testcases/org/apache/poi/ss/usermodel/TestFractionFormat.java
+++ b/src/testcases/org/apache/poi/ss/usermodel/TestFractionFormat.java
@@ -17,35 +17,34 @@
package org.apache.poi.ss.usermodel;
+import static org.junit.Assert.assertEquals;
+
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
-import junit.framework.TestCase;
-
import org.apache.poi.hssf.HSSFTestDataSamples;
-import org.apache.poi.ss.usermodel.Cell;
-import org.apache.poi.ss.usermodel.DataFormatter;
-import org.apache.poi.ss.usermodel.FormulaEvaluator;
-import org.apache.poi.ss.usermodel.FractionFormat;
-import org.apache.poi.ss.usermodel.Row;
+import org.apache.poi.util.LocaleUtil;
+import org.junit.Test;
/**
* Tests for the Fraction Formatting part of DataFormatter.
* Largely taken from bug #54686
*/
-public final class TestFractionFormat extends TestCase {
- public void testSingle() throws Exception {
+public final class TestFractionFormat {
+ @Test
+ public void testSingle() throws Exception {
FractionFormat f = new FractionFormat("", "##");
double val = 321.321;
String ret = f.format(val);
assertEquals("26027/81", ret);
}
+ @Test
public void testTruthFile() throws Exception {
File truthFile = HSSFTestDataSamples.getSampleFile("54686_fraction_formats.txt");
- BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(truthFile)));
+ BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(truthFile), LocaleUtil.CHARSET_1252));
Workbook wb = HSSFTestDataSamples.openSampleWorkbook("54686_fraction_formats.xls");
Sheet sheet = wb.getSheetAt(0);
DataFormatter formatter = new DataFormatter();
@@ -73,6 +72,7 @@ public final class TestFractionFormat extends TestCase {
}
truthLine = reader.readLine();
}
+ wb.close();
reader.close();
}
diff --git a/src/testcases/org/apache/poi/util/TestHexDump.java b/src/testcases/org/apache/poi/util/TestHexDump.java
index f6e149e75e..7509363c52 100644
--- a/src/testcases/org/apache/poi/util/TestHexDump.java
+++ b/src/testcases/org/apache/poi/util/TestHexDump.java
@@ -28,20 +28,15 @@ import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
-import java.io.InputStream;
import java.io.PrintStream;
import java.lang.reflect.Constructor;
import org.junit.Test;
-public final class TestHexDump {
+public class TestHexDump {
@Test
public void testDump() throws IOException {
- byte[] testArray = new byte[ 256 ];
-
- for (int j = 0; j < 256; j++) {
- testArray[ j ] = ( byte ) j;
- }
+ byte[] testArray = testArray();
ByteArrayOutputStream streamAct = new ByteArrayOutputStream();
HexDump.dump(testArray, 0, streamAct, 0);
byte bytesAct[] = streamAct.toByteArray();
@@ -55,7 +50,7 @@ public final class TestHexDump {
HexDump.dump(testArray, 0x10000000L, streamAct, 0);
bytesAct = streamAct.toByteArray();
bytesExp = toHexDump(0x10000000L,0);
-
+
assertEquals("array size mismatch", bytesExp.length, bytesAct.length);
assertArrayEquals("array mismatch", bytesExp, bytesAct);
@@ -108,15 +103,15 @@ public final class TestHexDump {
// verify proper behaviour with empty byte array
streamAct.reset();
HexDump.dump( new byte[0], 0, streamAct, 0 );
- assertEquals( "No Data" + System.getProperty( "line.separator"), streamAct.toString() );
+ assertEquals( "No Data" + System.getProperty( "line.separator"), streamAct.toString(LocaleUtil.CHARSET_1252.name()) );
}
-
+
private byte[] toHexDump(long offset, int index) {
StringBuilder strExp = new StringBuilder(), chrs = new StringBuilder();
Object obj[] = new Object[33];
StringBuilder format = new StringBuilder();
-
+
for (int j = 0; j < 16 && (index + j*16) < 256; j++) {
obj[0] = offset+index+j*16;
chrs.setLength(0);
@@ -133,7 +128,7 @@ public final class TestHexDump {
}
obj[17] = chrs.toString();
format.append("%18$s"+HexDump.EOL);
-
+
String str = String.format(LocaleUtil.getUserLocale(), format.toString(), obj);
strExp.append(str);
}
@@ -144,11 +139,11 @@ public final class TestHexDump {
@Test
public void testToHex() {
assertEquals("000A", HexDump.toHex((short)0xA));
-
+
assertEquals("[]", HexDump.toHex(new short[] { }));
assertEquals("[000A]", HexDump.toHex(new short[] { 0xA }));
assertEquals("[000A, 000B]", HexDump.toHex(new short[] { 0xA, 0xB }));
-
+
assertEquals("0A", HexDump.toHex((byte)0xA));
assertEquals("0000000A", HexDump.toHex(0xA));
@@ -163,9 +158,9 @@ public final class TestHexDump {
assertEquals("0: 0A, 0B\n2: 0C, 0D\n4: 0E, 0F", HexDump.toHex(new byte[] { 0xA, 0xB, 0xC, 0xD, 0xE, 0xF }, 2));
assertEquals("FFFF", HexDump.toHex((short)0xFFFF));
-
+
assertEquals("00000000000004D2", HexDump.toHex(1234l));
-
+
assertEquals("0xFE", HexDump.byteToHex(-2));
assertEquals("0x25", HexDump.byteToHex(37));
assertEquals("0xFFFE", HexDump.shortToHex(-2));
@@ -178,20 +173,15 @@ public final class TestHexDump {
@Test
public void testDumpToString() throws Exception {
- byte[] testArray = new byte[ 256 ];
-
- for (int j = 0; j < 256; j++)
- {
- testArray[ j ] = ( byte ) j;
- }
+ byte[] testArray = testArray();
String dump = HexDump.dump(testArray, 0, 0);
//System.out.println("Hex: \n" + dump);
- assertTrue("Had: \n" + dump,
+ assertTrue("Had: \n" + dump,
dump.contains("0123456789:;<=>?"));
dump = HexDump.dump(testArray, 2, 1);
//System.out.println("Hex: \n" + dump);
- assertTrue("Had: \n" + dump,
+ assertTrue("Had: \n" + dump,
dump.contains("123456789:;<=>?@"));
}
@@ -208,88 +198,48 @@ public final class TestHexDump {
public void testDumpToStringOutOfIndex3() throws Exception {
HexDump.dump(new byte[ 1 ], 0, 1);
}
-
-
- @Test
- public void testDumpToPrintStream() throws IOException {
- byte[] testArray = new byte[ 256 ];
-
- for (int j = 0; j < 256; j++)
- {
- testArray[ j ] = ( byte ) j;
- }
- InputStream in = new ByteArrayInputStream(testArray);
- try {
- ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
- PrintStream out = new PrintStream(byteOut);
- try {
- HexDump.dump(in, out, 0, 256);
- } finally {
- out.close();
- }
-
- String str = new String(byteOut.toByteArray());
- assertTrue("Had: \n" + str,
- str.contains("0123456789:;<=>?"));
- } finally {
- in.close();
- }
-
- in = new ByteArrayInputStream(testArray);
- try {
- ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
- PrintStream out = new PrintStream(byteOut);
- try {
- // test with more than we have
- HexDump.dump(in, out, 0, 1000);
- } finally {
- out.close();
- }
-
- String str = new String(byteOut.toByteArray());
- assertTrue("Had: \n" + str,
- str.contains("0123456789:;<=>?"));
- } finally {
- in.close();
- }
- in = new ByteArrayInputStream(testArray);
- try {
- ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
- PrintStream out = new PrintStream(byteOut);
- try {
- // test with -1
- HexDump.dump(in, out, 0, -1);
- } finally {
- out.close();
- }
-
- String str = new String(byteOut.toByteArray());
- assertTrue("Had: \n" + str,
- str.contains("0123456789:;<=>?"));
- } finally {
- in.close();
- }
-
- in = new ByteArrayInputStream(testArray);
- try {
- ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
- PrintStream out = new PrintStream(byteOut);
- try {
- HexDump.dump(in, out, 1, 235);
- } finally {
- out.close();
- }
-
- String str = new String(byteOut.toByteArray());
- assertTrue("Line contents should be moved by one now, but Had: \n" + str,
+ @Test
+ public void testDumpToPrintStream() throws IOException {
+ byte[] testArray = testArray();
+ ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
+ PrintStream out = new PrintStream(byteOut,true,LocaleUtil.CHARSET_1252.name());
+ ByteArrayInputStream byteIn = new ByteArrayInputStream(testArray);
+ byteIn.mark(256);
+ String str;
+
+ byteIn.reset();
+ byteOut.reset();
+ HexDump.dump(byteIn, out, 0, 256);
+ str = new String(byteOut.toByteArray(), LocaleUtil.CHARSET_1252);
+ assertTrue("Had: \n" + str, str.contains("0123456789:;<=>?"));
+
+ // test with more than we have
+ byteIn.reset();
+ byteOut.reset();
+ HexDump.dump(byteIn, out, 0, 1000);
+ str = new String(byteOut.toByteArray(), LocaleUtil.CHARSET_1252);
+ assertTrue("Had: \n" + str, str.contains("0123456789:;<=>?"));
+
+ // test with -1
+ byteIn.reset();
+ byteOut.reset();
+ HexDump.dump(byteIn, out, 0, -1);
+ str = new String(byteOut.toByteArray(), LocaleUtil.CHARSET_1252);
+ assertTrue("Had: \n" + str, str.contains("0123456789:;<=>?"));
+
+ byteIn.reset();
+ byteOut.reset();
+ HexDump.dump(byteIn, out, 1, 235);
+ str = new String(byteOut.toByteArray(), LocaleUtil.CHARSET_1252);
+ assertTrue("Line contents should be moved by one now, but Had: \n" + str,
str.contains("123456789:;<=>?@"));
- } finally {
- in.close();
- }
+
+ byteIn.close();
+ byteOut.close();
}
-
+
@Test
public void testConstruct() throws Exception {
// to cover private constructor
@@ -300,25 +250,35 @@ public final class TestHexDump {
c.setAccessible(true);
// call it
- assertNotNull(c.newInstance((Object[]) null));
+ assertNotNull(c.newInstance((Object[]) null));
}
-
+
@Test
public void testMain() throws Exception {
File file = TempFile.createTempFile("HexDump", ".dat");
try {
FileOutputStream out = new FileOutputStream(file);
try {
- IOUtils.copy(new ByteArrayInputStream("teststring".getBytes()), out);
+ IOUtils.copy(new ByteArrayInputStream("teststring".getBytes(LocaleUtil.CHARSET_1252)), out);
} finally {
out.close();
}
assertTrue(file.exists());
assertTrue(file.length() > 0);
-
+
HexDump.main(new String[] { file.getAbsolutePath() });
} finally {
assertTrue(file.exists() && file.delete());
}
}
+
+ private static byte[] testArray() {
+ byte[] testArray = new byte[ 256 ];
+
+ for (int j = 0; j < 256; j++) {
+ testArray[ j ] = ( byte ) j;
+ }
+
+ return testArray;
+ }
}
diff --git a/src/testcases/org/apache/poi/util/TestTempFile.java b/src/testcases/org/apache/poi/util/TestTempFile.java
index c41032fe2d..f22be76f76 100644
--- a/src/testcases/org/apache/poi/util/TestTempFile.java
+++ b/src/testcases/org/apache/poi/util/TestTempFile.java
@@ -16,36 +16,42 @@
==================================================================== */
package org.apache.poi.util;
-import junit.framework.TestCase;
+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 java.io.File;
-import java.io.FileWriter;
+import java.io.FileOutputStream;
import java.io.IOException;
+import org.junit.Test;
+
/**
* @author Glen Stampoultzis
*/
-public class TestTempFile extends TestCase {
- TempFile tempFile;
-
+public class TestTempFile {
+ @Test
public void testCreateTempFile()
throws Exception
{
File tempFile = TempFile.createTempFile("test", ".txt");
- FileWriter w = new FileWriter(tempFile);
- w.write("testing");
- w.close();
+ FileOutputStream fos = new FileOutputStream(tempFile);
+ fos.write(1);
+ fos.close();
assertTrue(tempFile.exists());
assertEquals("poifiles", tempFile.getParentFile().getName());
// Can't think of a good way to check whether a file is actually deleted since it would require the VM to stop.
}
+ @Test
public void testConstructor() {
// can currently be constructed...
new TempFile();
}
+ @Test(expected=IllegalArgumentException.class)
public void testSetTempFileCreationStrategy() throws IOException {
TempFile.setTempFileCreationStrategy(new TempFile.DefaultTempFileCreationStrategy());
@@ -57,11 +63,6 @@ public class TestTempFile extends TestCase {
assertNotNull(file1);
assertTrue(file1.delete());
- try {
- TempFile.setTempFileCreationStrategy(null);
- fail("Expecting an exception here");
- } catch (IllegalArgumentException e) {
- // expecting an exception here...
- }
+ TempFile.setTempFileCreationStrategy(null);
}
}