aboutsummaryrefslogtreecommitdiffstats
path: root/src/scratchpad/testcases/org
diff options
context:
space:
mode:
authorAndreas Beeker <kiwiwings@apache.org>2019-12-27 23:00:13 +0000
committerAndreas Beeker <kiwiwings@apache.org>2019-12-27 23:00:13 +0000
commitc66575c1e7059ed403b74b76e699200fdee507b4 (patch)
tree0fe96421471b53e9f72a2370ce76d61b49a659bc /src/scratchpad/testcases/org
parent37282aae8f25970b157c40ae0888684f974ba666 (diff)
downloadpoi-c66575c1e7059ed403b74b76e699200fdee507b4.tar.gz
poi-c66575c1e7059ed403b74b76e699200fdee507b4.zip
Migrate all junit tests to Junit 4
get rid of references to junit.framework don't throw AssertionFailedErrors, but use Assert.fail instead add try-with-resources where it was missing git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1872041 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/scratchpad/testcases/org')
-rw-r--r--src/scratchpad/testcases/org/apache/poi/hdgf/TestHDGFCore.java25
-rw-r--r--src/scratchpad/testcases/org/apache/poi/hdgf/TestHDGFLZW.java34
-rw-r--r--src/scratchpad/testcases/org/apache/poi/hdgf/pointers/TestPointerFactory.java33
-rw-r--r--src/scratchpad/testcases/org/apache/poi/hslf/TestRecordCounts.java30
-rw-r--r--src/scratchpad/testcases/org/apache/poi/hslf/extractor/TestCruddyExtractor.java21
-rw-r--r--src/scratchpad/testcases/org/apache/poi/hslf/record/TestAnimationInfoAtom.java14
-rw-r--r--src/scratchpad/testcases/org/apache/poi/hslf/record/TestCString.java30
-rw-r--r--src/scratchpad/testcases/org/apache/poi/hslf/record/TestColorSchemeAtom.java26
-rw-r--r--src/scratchpad/testcases/org/apache/poi/hslf/record/TestDocument.java26
-rw-r--r--src/scratchpad/testcases/org/apache/poi/hslf/record/TestDocumentAtom.java47
-rw-r--r--src/scratchpad/testcases/org/apache/poi/hslf/record/TestExControl.java22
-rw-r--r--src/scratchpad/testcases/org/apache/poi/hslf/record/TestExHyperlinkAtom.java47
-rw-r--r--src/scratchpad/testcases/org/apache/poi/hslf/record/TestExMediaAtom.java15
-rw-r--r--src/scratchpad/testcases/org/apache/poi/hslf/record/TestExObjListAtom.java47
-rw-r--r--src/scratchpad/testcases/org/apache/poi/hslf/record/TestExOleObjAtom.java18
-rw-r--r--src/scratchpad/testcases/org/apache/poi/hslf/record/TestExVideoContainer.java21
-rw-r--r--src/scratchpad/testcases/org/apache/poi/hslf/record/TestHeadersFootersAtom.java23
-rw-r--r--src/scratchpad/testcases/org/apache/poi/hslf/record/TestHeadersFootersContainer.java31
-rw-r--r--src/scratchpad/testcases/org/apache/poi/hslf/record/TestInteractiveInfo.java37
-rw-r--r--src/scratchpad/testcases/org/apache/poi/hslf/record/TestInteractiveInfoAtom.java52
-rw-r--r--src/scratchpad/testcases/org/apache/poi/hslf/record/TestNotesAtom.java24
-rw-r--r--src/scratchpad/testcases/org/apache/poi/hslf/record/TestSlidePersistAtom.java24
-rw-r--r--src/scratchpad/testcases/org/apache/poi/hslf/record/TestTextBytesAtom.java39
-rw-r--r--src/scratchpad/testcases/org/apache/poi/hslf/record/TestTextCharsAtom.java41
-rw-r--r--src/scratchpad/testcases/org/apache/poi/hslf/record/TestTextHeaderAtom.java28
-rw-r--r--src/scratchpad/testcases/org/apache/poi/hslf/record/TestTextSpecInfoAtom.java16
-rw-r--r--src/scratchpad/testcases/org/apache/poi/hslf/record/TestTxInteractiveInfoAtom.java48
-rw-r--r--src/scratchpad/testcases/org/apache/poi/hslf/record/TestTxMasterStyleAtom.java34
-rw-r--r--src/scratchpad/testcases/org/apache/poi/hslf/record/TestUserEditAtom.java29
-rw-r--r--src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestMostRecentRecords.java22
-rw-r--r--src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestNotesText.java38
-rw-r--r--src/scratchpad/testcases/org/apache/poi/hsmf/Test7BitCodepage.java34
-rw-r--r--src/scratchpad/testcases/org/apache/poi/hsmf/TestBasics.java91
-rw-r--r--src/scratchpad/testcases/org/apache/poi/hsmf/TestBlankFileRead.java61
-rw-r--r--src/scratchpad/testcases/org/apache/poi/hsmf/TestMessageSubmissionChunk.java32
-rw-r--r--src/scratchpad/testcases/org/apache/poi/hsmf/TestMessageSubmissionChunkY2KRead.java38
-rw-r--r--src/scratchpad/testcases/org/apache/poi/hsmf/TestOutlook30FileRead.java55
-rw-r--r--src/scratchpad/testcases/org/apache/poi/hsmf/TestSimpleFileRead.java24
-rw-r--r--src/scratchpad/testcases/org/apache/poi/hsmf/datatypes/TestChunkData.java21
-rw-r--r--src/scratchpad/testcases/org/apache/poi/hsmf/datatypes/TestMAPIProperty.java30
-rw-r--r--src/scratchpad/testcases/org/apache/poi/hsmf/datatypes/TestSorters.java22
-rw-r--r--src/scratchpad/testcases/org/apache/poi/hsmf/datatypes/TestTypes.java19
-rw-r--r--src/scratchpad/testcases/org/apache/poi/hwpf/TestHWPFPictures.java44
-rw-r--r--src/scratchpad/testcases/org/apache/poi/hwpf/TestHWPFRangeParts.java23
-rw-r--r--src/scratchpad/testcases/org/apache/poi/hwpf/converter/AbstractWordUtilsTest.java14
-rw-r--r--src/scratchpad/testcases/org/apache/poi/hwpf/converter/TestNumberFormatter.java37
-rw-r--r--src/scratchpad/testcases/org/apache/poi/hwpf/converter/TestWordToTextConverter.java58
-rw-r--r--src/scratchpad/testcases/org/apache/poi/hwpf/model/TestBookmarksTables.java118
-rw-r--r--src/scratchpad/testcases/org/apache/poi/hwpf/model/TestCHPBinTable.java30
-rw-r--r--src/scratchpad/testcases/org/apache/poi/hwpf/model/TestNotesTables.java9
-rw-r--r--src/scratchpad/testcases/org/apache/poi/hwpf/model/TestPlexOfCps.java27
-rw-r--r--src/scratchpad/testcases/org/apache/poi/hwpf/model/TestSectionTable.java34
-rw-r--r--src/scratchpad/testcases/org/apache/poi/hwpf/model/types/LFOLVLBaseAbstractTypeTest.java14
-rw-r--r--src/scratchpad/testcases/org/apache/poi/hwpf/model/types/LVLFAbstractTypeTest.java14
-rw-r--r--src/scratchpad/testcases/org/apache/poi/hwpf/sprm/TableSprmUncompressorTest.java12
-rw-r--r--src/scratchpad/testcases/org/apache/poi/hwpf/sprm/TestSprms.java46
-rw-r--r--src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestBorderCode.java10
-rw-r--r--src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestBug49820.java48
-rw-r--r--src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestBug50075.java35
-rw-r--r--src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestHeaderStories.java41
-rw-r--r--src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestLists.java471
-rw-r--r--src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestOfficeDrawings.java34
-rw-r--r--src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestRangeDelete.java276
-rw-r--r--src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestRangeInsertion.java102
-rw-r--r--src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestRangeProperties.java24
-rw-r--r--src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestRangeReplacement.java162
66 files changed, 1575 insertions, 1477 deletions
diff --git a/src/scratchpad/testcases/org/apache/poi/hdgf/TestHDGFCore.java b/src/scratchpad/testcases/org/apache/poi/hdgf/TestHDGFCore.java
index ad3888d19e..e68cace494 100644
--- a/src/scratchpad/testcases/org/apache/poi/hdgf/TestHDGFCore.java
+++ b/src/scratchpad/testcases/org/apache/poi/hdgf/TestHDGFCore.java
@@ -17,36 +17,41 @@
package org.apache.poi.hdgf;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
import org.apache.poi.POIDataSamples;
import org.apache.poi.hdgf.extractor.VisioTextExtractor;
import org.apache.poi.hdgf.streams.PointerContainingStream;
import org.apache.poi.hdgf.streams.TrailerStream;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
-public final class TestHDGFCore extends TestCase {
+public final class TestHDGFCore {
private static POIDataSamples _dgTests = POIDataSamples.getDiagramInstance();
private POIFSFileSystem fs;
private HDGFDiagram hdgf;
private VisioTextExtractor textExtractor;
- @Override
- protected void setUp() throws Exception {
+ @Before
+ public void setUp() throws Exception {
fs = new POIFSFileSystem(_dgTests.openResourceAsStream("Test_Visio-Some_Random_Text.vsd"));
}
- @Override
- protected void tearDown() throws Exception {
+ @After
+ public void tearDown() throws Exception {
if (textExtractor != null) textExtractor.close();
if (hdgf != null) hdgf.close();
}
-
+ @Test
public void testCreate() throws Exception {
hdgf = new HDGFDiagram(fs);
}
+ @Test
public void testTrailer() throws Exception {
hdgf = new HDGFDiagram(fs);
assertNotNull(hdgf);
@@ -74,6 +79,7 @@ public final class TestHDGFCore extends TestCase {
* Tests that we can open a problematic file, that used to
* break with a negative chunk length
*/
+ @Test
public void testNegativeChunkLength() throws Exception {
fs = new POIFSFileSystem(_dgTests.openResourceAsStream("NegativeChunkLength.vsd"));
@@ -90,8 +96,8 @@ public final class TestHDGFCore extends TestCase {
* Tests that we can open a problematic file that triggers
* an ArrayIndexOutOfBoundsException when processing the
* chunk commands.
- * @throws Exception
*/
+ @Test
public void DISABLEDtestAIOOB() throws Exception {
fs = new POIFSFileSystem(_dgTests.openResourceAsStream("44501.vsd"));
@@ -99,6 +105,7 @@ public final class TestHDGFCore extends TestCase {
assertNotNull(hdgf);
}
+ @Test
public void testV5() throws Exception {
fs = new POIFSFileSystem(_dgTests.openResourceAsStream("v5_Connection_Types.vsd"));
@@ -111,6 +118,7 @@ public final class TestHDGFCore extends TestCase {
assertEquals("Static to Static\nDynamic to Static\nDynamic to Dynamic", text);
}
+ @Test
public void testV6NonUtf16LE() throws Exception {
fs = new POIFSFileSystem(_dgTests.openResourceAsStream("v6-non-utf16le.vsd"));
@@ -123,6 +131,7 @@ public final class TestHDGFCore extends TestCase {
assertEquals("Table\n\n\nPropertySheet\n\n\n\nPropertySheetField", text);
}
+ @Test
public void testUtf16LE() throws Exception {
fs = new POIFSFileSystem(_dgTests.openResourceAsStream("Test_Visio-Some_Random_Text.vsd"));
diff --git a/src/scratchpad/testcases/org/apache/poi/hdgf/TestHDGFLZW.java b/src/scratchpad/testcases/org/apache/poi/hdgf/TestHDGFLZW.java
index 7f89a050fb..5d23c1af5b 100644
--- a/src/scratchpad/testcases/org/apache/poi/hdgf/TestHDGFLZW.java
+++ b/src/scratchpad/testcases/org/apache/poi/hdgf/TestHDGFLZW.java
@@ -17,12 +17,15 @@
package org.apache.poi.hdgf;
+import static org.junit.Assert.assertEquals;
+
import java.io.ByteArrayInputStream;
-import junit.framework.TestCase;
+import org.junit.Ignore;
+import org.junit.Test;
-public final class TestHDGFLZW extends TestCase {
- public static final byte[] testTrailerComp = new byte[] {
+public final class TestHDGFLZW {
+ public static final byte[] testTrailerComp = {
123, // *mask bit*
-60, 2,
-21, -16, // 3 @ 4093
@@ -38,7 +41,7 @@ public final class TestHDGFLZW extends TestCase {
21, // *mask bit* 1,3,5
9,
-21, -16, // 3 @ 4093
- 103,
+ 103,
-21, -16, // 3 @ 4093
34,
-36, -1, // 18 @ 4078
@@ -72,7 +75,7 @@ public final class TestHDGFLZW extends TestCase {
1, 67, 85, 1, 81, -127, 0, -41, 0, 14, 6, 4, 17, 63, -63, 17, 68,
85, -65, 1, 30, -120, 0, 0, 42, 79, 18, 68, 126, -21, -16, -76, 69,
85, 1, 102, -119, 72, 37, 0, 97, 33 };
- public static final byte[] testTrailerDecomp = new byte[] {
+ public static final byte[] testTrailerDecomp = {
-60, 2, 0, 0, 0, 1, 0, 0, -72, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 1, 0, 3, 0, 0, 0, 3, 0, 0, 0, 3, 0, 0, 0, 4, 0, 0,
0, 9, 0, 0, 0, 103, 0, 0, 0, 34, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
@@ -108,6 +111,7 @@ public final class TestHDGFLZW extends TestCase {
0, 0, 42, 1, 0, 0, 84, 0, 0, 0, 0, 0
};
+ @Test
public void testFromToInt() {
byte b255 = -1;
assertEquals(255, HDGFLZW.fromByte(b255));
@@ -135,6 +139,7 @@ public final class TestHDGFLZW extends TestCase {
assertEquals(-128, HDGFLZW.fromInt( 128 ));
}
+ @Test
public void testCounts() throws Exception {
assertEquals(339, testTrailerComp.length);
assertEquals(632, testTrailerDecomp.length);
@@ -155,6 +160,7 @@ public final class TestHDGFLZW extends TestCase {
*/
}
+ @Test
public void testDecompress() throws Exception {
assertEquals(339, testTrailerComp.length);
assertEquals(632, testTrailerDecomp.length);
@@ -176,6 +182,7 @@ public final class TestHDGFLZW extends TestCase {
* Uses a part short enough that we agree with visio
* on the best way to compress it
*/
+ @Test
public void testCompressMini() throws Exception {
// first 11 bytes compressed = 12 bytes uncompressed
byte[] sourceComp = new byte[11];
@@ -186,7 +193,7 @@ public final class TestHDGFLZW extends TestCase {
// Compress it using our engine
HDGFLZW lzw = new HDGFLZW();
byte[] comp = lzw.compress(new ByteArrayInputStream(sourceDecomp));
-
+
// Now decompress it again
byte[] decomp = lzw.decompress(new ByteArrayInputStream(comp));
@@ -206,6 +213,7 @@ public final class TestHDGFLZW extends TestCase {
/**
* Tests that we can do several mask pages
*/
+ @Test
public void testCompressMidi() throws Exception {
// First 12 -> 11
// Next 32 -> 13
@@ -217,11 +225,11 @@ public final class TestHDGFLZW extends TestCase {
// Compress it using our engine
HDGFLZW lzw = new HDGFLZW();
byte[] comp = lzw.compress(new ByteArrayInputStream(sourceDecomp));
-
+
// We should be 3 characters bigger, as
// we split one compressed bit into two
assertEquals(27, comp.length);
-
+
// Now decompress it again
byte[] decomp = lzw.decompress(new ByteArrayInputStream(comp));
@@ -237,28 +245,30 @@ public final class TestHDGFLZW extends TestCase {
* Gets 160 bytes through then starts going wrong...
* TODO Fix this
*/
- public void DISABLEDtestCompressFull() throws Exception {
+ @Test
+ @Ignore
+ public void testCompressFull() throws Exception {
assertEquals(339, testTrailerComp.length);
assertEquals(632, testTrailerDecomp.length);
// Compress it using our engine
HDGFLZW lzw = new HDGFLZW();
byte[] comp = lzw.compress(new ByteArrayInputStream(testTrailerDecomp));
-
+
// Now decompress it again
byte[] decomp = lzw.decompress(new ByteArrayInputStream(comp));
// for(int i=0; i<comp.length; i++) {
// System.err.println(i + "\t" + comp[i] + "\t" + testTrailerComp[i]);
// }
-
+
// First up, check the round tripping
// assertEquals(632, decomp.length);
for(int i=0; i<decomp.length; i++) {
assertEquals("Wrong at " + i, decomp[i], testTrailerDecomp[i]);
}
-
+
// Now check the compressed intermediate version
assertEquals(339, comp.length);
for(int i=0; i<comp.length; i++) {
diff --git a/src/scratchpad/testcases/org/apache/poi/hdgf/pointers/TestPointerFactory.java b/src/scratchpad/testcases/org/apache/poi/hdgf/pointers/TestPointerFactory.java
index 60d12f0a8e..8947533312 100644
--- a/src/scratchpad/testcases/org/apache/poi/hdgf/pointers/TestPointerFactory.java
+++ b/src/scratchpad/testcases/org/apache/poi/hdgf/pointers/TestPointerFactory.java
@@ -17,48 +17,49 @@
package org.apache.poi.hdgf.pointers;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
/**
* Tests for the pointer factory, and the pointers themselves
*/
-public final class TestPointerFactory extends TestCase {
+public final class TestPointerFactory {
// Type: 14 Addr: 011eb2ac Offset: 1dd4 Len: 14d Format: 52 From: 24
- private static byte[] vp5_a = new byte[] {
+ private static byte[] vp5_a = {
0x14, 0, 0x52, 0, (byte)0xac, (byte)0xb2, 0x1e, 1, (byte)0xd4, 0x1d, 0, 0,
0x4d, 1, 0, 0
};
-
+
// Type: 16 Addr: 0143aff4 Offset: 80 Len: 54 Format: 46 From: 8a94
- private static byte[] vp6_a = new byte[] {
+ private static byte[] vp6_a = {
22, 0, 0, 0, -12, -81, 67, 1, -128, 0, 0, 0, 84, 0, 0, 0, 70, 0
};
// Type: 17 Addr: 014fd84c Offset: d4 Len: 20 Format: 54 From: 8a94
- private static byte[] vp6_b = new byte[] {
+ private static byte[] vp6_b = {
23, 0, 0, 0, 76, -40, 79, 1, -44, 0, 0, 0, 32, 0, 0, 0, 84, 0
};
// Type: 17 Addr: 014fd8bc Offset: f8 Len: 20 Format: 54 From: 8a94
- private static byte[] vp6_c = new byte[] {
+ private static byte[] vp6_c = {
23, 0, 0, 0, -68, -40, 79, 1, -8, 0, 0, 0, 32, 0, 0, 0, 84, 0
};
// Type: ff Addr: 014fffac Offset: 0 Len: 0 Format: 60 From: 8a94
- private static byte[] vp6_d = new byte[] {
+ private static byte[] vp6_d = {
-1, 0, 0, 0, -84, -1, 79, 1, 0, 0, 0, 0, 0, 0, 0, 0, 96, 0
};
+ @Test(expected = IllegalArgumentException.class)
public void testCreateV4() {
PointerFactory pf = new PointerFactory(4);
- try {
- pf.createPointer(new byte[]{}, 0);
- fail();
- } catch(IllegalArgumentException e) {
- // As expected
- }
+ pf.createPointer(new byte[]{}, 0);
}
+ @Test
public void testCreateV5() {
PointerFactory pf = new PointerFactory(5);
-
+
Pointer a = pf.createPointer(vp5_a, 0);
assertEquals(0x14, a.getType());
assertEquals(0x011eb2ac, a.getAddress());
@@ -75,6 +76,7 @@ public final class TestPointerFactory extends TestCase {
assertEquals(16, a.getSizeInBytes());
}
+ @Test
public void testCreateV6() {
PointerFactory pf = new PointerFactory(6);
@@ -131,6 +133,7 @@ public final class TestPointerFactory extends TestCase {
assertFalse(d.destinationHasPointers());
}
+ @Test
public void testCreateV6FromMid() {
PointerFactory pf = new PointerFactory(11);
diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/TestRecordCounts.java b/src/scratchpad/testcases/org/apache/poi/hslf/TestRecordCounts.java
index 473c9d3306..19d66525ae 100644
--- a/src/scratchpad/testcases/org/apache/poi/hslf/TestRecordCounts.java
+++ b/src/scratchpad/testcases/org/apache/poi/hslf/TestRecordCounts.java
@@ -18,27 +18,33 @@
package org.apache.poi.hslf;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
-import org.apache.poi.hslf.record.*;
-import org.apache.poi.hslf.usermodel.HSLFSlideShowImpl;
import org.apache.poi.POIDataSamples;
+import org.apache.poi.hslf.record.Notes;
+import org.apache.poi.hslf.record.Record;
+import org.apache.poi.hslf.record.Slide;
+import org.apache.poi.hslf.record.SlideListWithText;
+import org.apache.poi.hslf.usermodel.HSLFSlideShowImpl;
+import org.junit.Before;
+import org.junit.Test;
/**
* Tests that HSLFSlideShow returns the right numbers of key records when
* it parses the test file
- *
- * @author Nick Burch (nick at torchbox dot com)
*/
-public final class TestRecordCounts extends TestCase {
+public final class TestRecordCounts {
+
+ private static final POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
// HSLFSlideShow primed on the test data
- private final HSLFSlideShowImpl ss;
+ private HSLFSlideShowImpl ss;
- public TestRecordCounts() throws Exception {
- POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
+ @Before
+ public void setup() throws Exception {
ss = new HSLFSlideShowImpl(slTests.openResourceAsStream("basic_test_ppt_file.ppt"));
}
+ @Test
public void testSheetsCount() {
// Top level
Record[] r = ss.getRecords();
@@ -53,13 +59,14 @@ public final class TestRecordCounts extends TestCase {
assertEquals(3,count);
}
+ @Test
public void testNotesCount() {
// Top level
Record[] r = ss.getRecords();
int count = 0;
for (final Record rec : r) {
- if (rec instanceof Notes && rec.getRecordType() == 1008l) {
+ if (rec instanceof Notes && rec.getRecordType() == 1008L) {
count++;
}
}
@@ -67,6 +74,7 @@ public final class TestRecordCounts extends TestCase {
assertEquals(3,count);
}
+ @Test
public void testSlideListWithTextCount() {
// Second level
Record[] rt = ss.getRecords();
@@ -74,7 +82,7 @@ public final class TestRecordCounts extends TestCase {
int count = 0;
for (final Record rec : r) {
- if (rec instanceof SlideListWithText && rec.getRecordType() == 4080l) {
+ if (rec instanceof SlideListWithText && rec.getRecordType() == 4080L) {
count++;
}
}
diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/extractor/TestCruddyExtractor.java b/src/scratchpad/testcases/org/apache/poi/hslf/extractor/TestCruddyExtractor.java
index 33807ac576..b69fc579f2 100644
--- a/src/scratchpad/testcases/org/apache/poi/hslf/extractor/TestCruddyExtractor.java
+++ b/src/scratchpad/testcases/org/apache/poi/hslf/extractor/TestCruddyExtractor.java
@@ -18,21 +18,24 @@
package org.apache.poi.hslf.extractor;
-import java.util.List;
+import static org.junit.Assert.assertEquals;
-import junit.framework.TestCase;
+import java.util.List;
import org.apache.poi.POIDataSamples;
import org.apache.poi.util.StringUtil;
+import org.junit.Before;
+import org.junit.Test;
/**
* Tests that the QuickButCruddyTextExtractor works correctly
- *
- * @author Nick Burch (nick at torchbox dot com)
*/
-public final class TestCruddyExtractor extends TestCase {
+public final class TestCruddyExtractor {
+ private static final POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
+
// Extractor primed on the test data
- private final QuickButCruddyTextExtractor te;
+ private QuickButCruddyTextExtractor te;
+
// All the text to be found in the file
String[] allTheText = new String[] {
"This is a test title",
@@ -59,11 +62,12 @@ public final class TestCruddyExtractor extends TestCase {
"This is page two\nIt has several blocks of text\nNone of them have formatting",
};
- public TestCruddyExtractor() throws Exception {
- POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
+ @Before
+ public void setup() throws Exception {
te = new QuickButCruddyTextExtractor(slTests.openResourceAsStream("basic_test_ppt_file.ppt"));
}
+ @Test
public void testReadAsVector() {
// Extract the text from the file as a vector
List<String> foundTextV = te.getTextAsVector();
@@ -76,6 +80,7 @@ public final class TestCruddyExtractor extends TestCase {
}
}
+ @Test
public void testReadAsString() {
// Extract the text as a String
String foundText = te.getTextAsString();
diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestAnimationInfoAtom.java b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestAnimationInfoAtom.java
index df3150c59e..e6de0b4952 100644
--- a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestAnimationInfoAtom.java
+++ b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestAnimationInfoAtom.java
@@ -19,17 +19,18 @@ package org.apache.poi.hslf.record;
import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
import java.io.ByteArrayOutputStream;
-import junit.framework.TestCase;
+import org.junit.Test;
/**
* Tests that {@link HeadersFootersAtom} works properly
- *
- * @author Yegor Kozlov
*/
-public final class TestAnimationInfoAtom extends TestCase {
+public final class TestAnimationInfoAtom {
// From a real file
/*
<AnimationInfoAtom info="1" type="4081" size="28" offset="4015" header="01 00 F1 0F 1C 00 00 00 ">
@@ -37,12 +38,13 @@ public final class TestAnimationInfoAtom extends TestCase {
00 00 00
</AnimationInfoAtom>
*/
- private final byte[] data = new byte[] {
+ private final byte[] data = {
0x01, 0x00, (byte)0xF1, 0x0F, 0x1C, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x07, 0x04, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
+ @Test
public void testRead() {
AnimationInfoAtom record = new AnimationInfoAtom(data, 0, data.length);
assertEquals(RecordTypes.AnimationInfoAtom.typeID, record.getRecordType());
@@ -61,6 +63,7 @@ public final class TestAnimationInfoAtom extends TestCase {
assertEquals(0, record.getSlideCount());
}
+ @Test
public void testWrite() throws Exception {
AnimationInfoAtom record = new AnimationInfoAtom(data, 0, data.length);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
@@ -70,6 +73,7 @@ public final class TestAnimationInfoAtom extends TestCase {
assertArrayEquals(data, b);
}
+ @Test
public void testNewRecord() throws Exception {
AnimationInfoAtom record = new AnimationInfoAtom();
record.setDimColor(0x07000000);
diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestCString.java b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestCString.java
index 4289c27710..51f8c2daa3 100644
--- a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestCString.java
+++ b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestCString.java
@@ -18,29 +18,34 @@
package org.apache.poi.hslf.record;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
import java.io.ByteArrayOutputStream;
+import org.junit.Test;
+
/**
* Tests that CString works properly
- *
- * @author Nick Burch (nick at torchbox dot com)
*/
-public final class TestCString extends TestCase {
+public final class TestCString {
// From a real file
- private final byte[] data_a = new byte[] { 0, 0, 0xBA-256, 0x0f, 0x10, 0, 0, 0,
- 0x48, 00, 0x6F, 00, 0x67, 00, 0x77, 00,
- 0x61, 00, 0x72, 00, 0x74, 00, 0x73, 00 };
+ private final byte[] data_a = { 0, 0, 0xBA-256, 0x0f, 0x10, 0, 0, 0,
+ 0x48, 0, 0x6F, 0, 0x67, 0, 0x77, 0,
+ 0x61, 0, 0x72, 0, 0x74, 0, 0x73, 0 };
private final byte[] data_b = new byte[] { 0x10, 0, 0xBA-256, 0x0f, 0x10, 0, 0, 0,
- 0x43, 00, 0x6F, 00, 0x6D, 00, 0x6D, 00,
- 0x65, 00, 0x6E, 00, 0x74, 00, 0x73, 00 };
+ 0x43, 0, 0x6F, 0, 0x6D, 0, 0x6D, 0,
+ 0x65, 0, 0x6E, 0, 0x74, 0, 0x73, 0 };
+ @Test
public void testRecordType() {
CString ca = new CString(data_a, 0, data_a.length);
- assertEquals(4026l, ca.getRecordType());
+ assertEquals(4026L, ca.getRecordType());
CString cb = new CString(data_b, 0, data_a.length);
- assertEquals(4026l, cb.getRecordType());
+ assertEquals(4026L, cb.getRecordType());
}
+
+ @Test
public void testCount() {
CString ca = new CString(data_a, 0, data_a.length);
assertEquals(0, ca.getOptions());
@@ -51,6 +56,7 @@ public final class TestCString extends TestCase {
assertEquals(28, ca.getOptions());
}
+ @Test
public void testText() {
CString ca = new CString(data_a, 0, data_a.length);
assertEquals("Hogwarts", ca.getText());
@@ -61,6 +67,7 @@ public final class TestCString extends TestCase {
assertEquals("FooBar", ca.getText());
}
+ @Test
public void testWrite() throws Exception {
CString ca = new CString(data_a, 0, data_a.length);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
@@ -84,6 +91,7 @@ public final class TestCString extends TestCase {
}
// Turn data_a into data_b
+ @Test
public void testChange() throws Exception {
CString ca = new CString(data_a, 0, data_a.length);
ca.setText("Comments");
diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestColorSchemeAtom.java b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestColorSchemeAtom.java
index 9e0af0d9d5..c4b6f9ab7f 100644
--- a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestColorSchemeAtom.java
+++ b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestColorSchemeAtom.java
@@ -18,28 +18,31 @@
package org.apache.poi.hslf.record;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
+
import java.io.ByteArrayOutputStream;
+import org.junit.Test;
+
/**
* Tests that ColorSchemAtom works properly
- *
- * @author Nick Burch (nick at torchbox dot com)
*/
-public final class TestColorSchemeAtom extends TestCase {
+public final class TestColorSchemeAtom {
// From a real file
- private final byte[] data_a = new byte[] { 60, 0, 0xF0-256, 0x07, 0x20, 0, 0, 0,
- 0xFF-256, 0xFF-256, 0xFF-256, 00, 00, 00, 00, 00,
- 0x80-256, 0x80-256, 0x80-256, 00, 00, 00, 00, 00,
- 0xBB-256, 0xE0-256, 0xE3-256, 00, 0x33, 0x33, 0x99-256, 00,
- 00, 0x99-256, 0x99-256, 00, 0x99-256, 0xCC-256, 00, 00
+ private final byte[] data_a = { 60, 0, 0xF0-256, 0x07, 0x20, 0, 0, 0,
+ 0xFF-256, 0xFF-256, 0xFF-256, 0, 0, 0, 0, 0,
+ 0x80-256, 0x80-256, 0x80-256, 0, 0, 0, 0, 0,
+ 0xBB-256, 0xE0-256, 0xE3-256, 0, 0x33, 0x33, 0x99-256, 0,
+ 0, 0x99-256, 0x99-256, 0, 0x99-256, 0xCC-256, 0, 0
};
+ @Test
public void testRecordType() {
ColorSchemeAtom csa = new ColorSchemeAtom(data_a,0,data_a.length);
- assertEquals(2032l, csa.getRecordType());
+ assertEquals(2032L, csa.getRecordType());
}
+ @Test
public void testToRGB() {
byte[] rgb = ColorSchemeAtom.splitRGB(3669760);
@@ -49,6 +52,7 @@ public final class TestColorSchemeAtom extends TestCase {
assertEquals(55, rgb[2]);
}
+ @Test
public void testFromRGB() {
byte[] rgb_a = new byte[] { 0, 255-256, 55 };
byte[] rgb_b = new byte[] { 255-256, 127, 79 };
@@ -60,6 +64,7 @@ public final class TestColorSchemeAtom extends TestCase {
assertEquals( 5210111, ColorSchemeAtom.joinRGB( rgb_b[0], rgb_b[1], rgb_b[2] ) );
}
+ @Test
public void testRGBs() {
ColorSchemeAtom csa = new ColorSchemeAtom(data_a,0,data_a.length);
@@ -73,6 +78,7 @@ public final class TestColorSchemeAtom extends TestCase {
assertEquals( 52377 , csa.getAccentAndFollowingHyperlinkColourRGB() );
}
+ @Test
public void testWrite() throws Exception {
ColorSchemeAtom csa = new ColorSchemeAtom(data_a,0,data_a.length);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestDocument.java b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestDocument.java
index e9134eea48..fa576ced48 100644
--- a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestDocument.java
+++ b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestDocument.java
@@ -17,25 +17,28 @@
package org.apache.poi.hslf.record;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
-import org.apache.poi.hslf.usermodel.HSLFSlideShowImpl;
-import org.apache.poi.poifs.filesystem.*;
import org.apache.poi.POIDataSamples;
+import org.apache.poi.hslf.usermodel.HSLFSlideShowImpl;
+import org.apache.poi.poifs.filesystem.POIFSFileSystem;
+import org.junit.Before;
+import org.junit.Test;
/**
* Tests that Document works properly (Also tests Environment while we're at it)
- *
- * @author Nick Burch (nick at torchbox dot com)
*/
-public final class TestDocument extends TestCase {
+public final class TestDocument {
+ private static final POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
+
// HSLFSlideShow primed on the test data
- private final HSLFSlideShowImpl ss;
+ private HSLFSlideShowImpl ss;
// POIFS primed on the test data
- private final POIFSFileSystem pfs;
+ private POIFSFileSystem pfs;
- public TestDocument() throws Exception {
- POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
+ @Before
+ public void setup() throws Exception {
pfs = new POIFSFileSystem(slTests.openResourceAsStream("basic_test_ppt_file.ppt"));
ss = new HSLFSlideShowImpl(pfs);
}
@@ -50,11 +53,13 @@ public final class TestDocument extends TestCase {
throw new IllegalStateException("No Document record found");
}
+ @Test
public void testRecordType() {
Document dr = getDocRecord();
assertEquals(1000, dr.getRecordType());
}
+ @Test
public void testChildRecords() {
Document dr = getDocRecord();
assertNotNull(dr.getDocumentAtom());
@@ -68,6 +73,7 @@ public final class TestDocument extends TestCase {
assertNotNull(dr.getSlideListWithTexts()[2]);
}
+ @Test
public void testEnvironment() {
Document dr = getDocRecord();
Environment env = dr.getEnvironment();
diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestDocumentAtom.java b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestDocumentAtom.java
index 82ec7bec51..73aea573c0 100644
--- a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestDocumentAtom.java
+++ b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestDocumentAtom.java
@@ -18,46 +18,59 @@
package org.apache.poi.hslf.record;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
import java.io.ByteArrayOutputStream;
+import org.junit.Test;
+
/**
* Tests that DocumentAtom works properly
- *
- * @author Nick Burch (nick at torchbox dot com)
*/
-public final class TestDocumentAtom extends TestCase {
+public final class TestDocumentAtom {
// From a real file
- private final byte[] data_a = new byte[] { 1, 0, 0xE9-256, 3, 0x28, 0, 0, 0,
+ private final byte[] data_a = { 1, 0, 0xE9-256, 3, 0x28, 0, 0, 0,
0x80-256, 0x16, 0, 0, 0xE0-256, 0x10, 0, 0,
0xE0-256, 0x10, 0, 0, 0x80-256, 0x16, 0, 0,
0x05, 0, 0, 0, 0x0A, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0,
1, 0, 0, 0, 0, 0, 0, 1 };
+ @Test
public void testRecordType() {
DocumentAtom da = new DocumentAtom(data_a, 0, data_a.length);
assertEquals(1001l, da.getRecordType());
}
+
+ @Test
public void testSizeAndZoom() {
DocumentAtom da = new DocumentAtom(data_a, 0, data_a.length);
- assertEquals(5760l, da.getSlideSizeX());
- assertEquals(4320l, da.getSlideSizeY());
- assertEquals(4320l, da.getNotesSizeX());
- assertEquals(5760l, da.getNotesSizeY());
+ assertEquals(5760L, da.getSlideSizeX());
+ assertEquals(4320L, da.getSlideSizeY());
+ assertEquals(4320L, da.getNotesSizeX());
+ assertEquals(5760L, da.getNotesSizeY());
- assertEquals(5l, da.getServerZoomFrom());
- assertEquals(10l, da.getServerZoomTo());
+ assertEquals(5L, da.getServerZoomFrom());
+ assertEquals(10L, da.getServerZoomTo());
}
+
+ @Test
public void testMasterPersist() {
DocumentAtom da = new DocumentAtom(data_a, 0, data_a.length);
- assertEquals(2l, da.getNotesMasterPersist());
- assertEquals(0l, da.getHandoutMasterPersist());
+ assertEquals(2L, da.getNotesMasterPersist());
+ assertEquals(0L, da.getHandoutMasterPersist());
}
+
+ @Test
public void testSlideDetails() {
DocumentAtom da = new DocumentAtom(data_a, 0, data_a.length);
assertEquals(1, da.getFirstSlideNum());
assertEquals(0, da.getSlideSizeType());
}
+
+ @Test
public void testBooleans() {
DocumentAtom da = new DocumentAtom(data_a, 0, data_a.length);
assertFalse(da.getSaveWithFonts());
@@ -66,15 +79,11 @@ public final class TestDocumentAtom extends TestCase {
assertTrue(da.getShowComments());
}
+ @Test
public void testWrite() throws Exception {
DocumentAtom da = new DocumentAtom(data_a, 0, data_a.length);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
da.writeOut(baos);
- byte[] b = baos.toByteArray();
-
- assertEquals(data_a.length, b.length);
- for(int i=0; i<data_a.length; i++) {
- assertEquals(data_a[i],b[i]);
- }
+ assertArrayEquals(data_a, baos.toByteArray());
}
}
diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestExControl.java b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestExControl.java
index 29c7ee2369..b72bc08dc9 100644
--- a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestExControl.java
+++ b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestExControl.java
@@ -19,17 +19,17 @@ package org.apache.poi.hslf.record;
import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
import java.io.ByteArrayOutputStream;
-import junit.framework.TestCase;
+import org.junit.Test;
/**
* Tests that {@link org.apache.poi.hslf.record.ExControl} works properly
- *
- * @author Yegor Kozlov
*/
-public final class TestExControl extends TestCase {
+public final class TestExControl {
// From a real file (embedded SWF control)
/*
@@ -55,7 +55,7 @@ public final class TestExControl extends TestCase {
</CString>
</ExControl>
*/
- private final byte[] data = new byte[] {
+ private final byte[] data = {
0x0F, 0x00, (byte)0xEE, 0x0F, (byte)0xDA, 0x00, 0x00, 0x00, 0x00, 0x00, (byte)0xFB, 0x0F, 0x04, 0x00, 0x00, 0x00,
0x00, 0x01, 0x00, 0x00, 0x01, 0x00, (byte)0xC3, 0x0F, 0x18, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00,
0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, (byte)0x96, 0x13, 0x00,
@@ -71,6 +71,7 @@ public final class TestExControl extends TestCase {
0x65, 0x00, 0x63, 0x00, 0x74, 0x00
};
+ @Test
public void testRead() {
ExControl record = new ExControl(data, 0, data.length);
assertEquals(RecordTypes.ExControl.typeID, record.getRecordType());
@@ -89,15 +90,15 @@ public final class TestExControl extends TestCase {
assertEquals("Shockwave Flash Object", record.getClipboardName());
}
+ @Test
public void testWrite() throws Exception {
ExControl record = new ExControl(data, 0, data.length);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
record.writeOut(baos);
- byte[] b = baos.toByteArray();
-
- assertArrayEquals(data, b);
+ assertArrayEquals(data, baos.toByteArray());
}
+ @Test
public void testNewRecord() throws Exception {
ExControl record = new ExControl();
ExControlAtom ctrl = record.getExControlAtom();
@@ -117,9 +118,6 @@ public final class TestExControl extends TestCase {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
record.writeOut(baos);
- byte[] b = baos.toByteArray();
-
- assertEquals(data.length, b.length);
- assertArrayEquals(data, b);
+ assertArrayEquals(data, baos.toByteArray());
}
}
diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestExHyperlinkAtom.java b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestExHyperlinkAtom.java
index eba79e05a6..f7ed7acf9e 100644
--- a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestExHyperlinkAtom.java
+++ b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestExHyperlinkAtom.java
@@ -18,30 +18,34 @@
package org.apache.poi.hslf.record;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+
import java.io.ByteArrayOutputStream;
+import org.junit.Test;
+
/**
* Tests that ExHyperlinkAtom works properly.
- *
- * @author Nick Burch (nick at torchbox dot com)
*/
-public class TestExHyperlinkAtom extends TestCase {
+public class TestExHyperlinkAtom {
// From a real file
private final byte[] data_a = new byte[] {
- 00, 00, 0xD3-256, 0x0F, 04, 00, 00, 00,
- 01, 00, 00, 00
+ 0, 0, 0xD3-256, 0x0F, 4, 0, 0, 0,
+ 1, 0, 0, 0
};
private final byte[] data_b = new byte[] {
- 00, 00, 0xD3-256, 0x0F, 04, 00, 00, 00,
- 04, 00, 00, 00
+ 0, 0, 0xD3-256, 0x0F, 4, 0, 0, 0,
+ 4, 0, 0, 0
};
+ @Test
public void testRecordType() {
ExHyperlinkAtom eha = new ExHyperlinkAtom(data_a, 0, data_a.length);
- assertEquals(4051l, eha.getRecordType());
+ assertEquals(4051L, eha.getRecordType());
}
+ @Test
public void testGetNumber() {
ExHyperlinkAtom eha = new ExHyperlinkAtom(data_a, 0, data_a.length);
ExHyperlinkAtom ehb = new ExHyperlinkAtom(data_b, 0, data_b.length);
@@ -50,19 +54,16 @@ public class TestExHyperlinkAtom extends TestCase {
assertEquals(4, ehb.getNumber());
}
+ @Test
public void testWrite() throws Exception {
ExHyperlinkAtom eha = new ExHyperlinkAtom(data_a, 0, data_a.length);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
eha.writeOut(baos);
- byte[] b = baos.toByteArray();
-
- assertEquals(data_a.length, b.length);
- for(int i=0; i<data_a.length; i++) {
- assertEquals(data_a[i],b[i]);
- }
+ assertArrayEquals(data_a, baos.toByteArray());
}
// Create A from scratch
+ @Test
public void testCreate() throws Exception {
ExHyperlinkAtom eha = new ExHyperlinkAtom();
@@ -72,15 +73,11 @@ public class TestExHyperlinkAtom extends TestCase {
// Check it's now the same as a
ByteArrayOutputStream baos = new ByteArrayOutputStream();
eha.writeOut(baos);
- byte[] b = baos.toByteArray();
-
- assertEquals(data_a.length, b.length);
- for(int i=0; i<data_a.length; i++) {
- assertEquals(data_a[i],b[i]);
- }
+ assertArrayEquals(data_a, baos.toByteArray());
}
// Try to turn a into b
+ @Test
public void testChange() throws Exception {
ExHyperlinkAtom eha = new ExHyperlinkAtom(data_a, 0, data_a.length);
@@ -90,12 +87,6 @@ public class TestExHyperlinkAtom extends TestCase {
// Check bytes are now the same
ByteArrayOutputStream baos = new ByteArrayOutputStream();
eha.writeOut(baos);
- byte[] b = baos.toByteArray();
-
- // Should now be the same
- assertEquals(data_b.length, b.length);
- for(int i=0; i<data_b.length; i++) {
- assertEquals(data_b[i],b[i]);
- }
+ assertArrayEquals(data_b, baos.toByteArray());
}
}
diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestExMediaAtom.java b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestExMediaAtom.java
index 05c0e678be..8150941299 100644
--- a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestExMediaAtom.java
+++ b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestExMediaAtom.java
@@ -19,22 +19,24 @@ package org.apache.poi.hslf.record;
import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
import java.io.ByteArrayOutputStream;
-import junit.framework.TestCase;
+import org.junit.Test;
/**
* Tests that {@link org.apache.poi.hslf.record.HeadersFootersAtom} works properly
- *
- * @author Yegor Kozlov
*/
-public final class TestExMediaAtom extends TestCase {
+public final class TestExMediaAtom {
// From a real file
private static final byte[] data = {
- 0x00, 0x00, (byte)0x04, 0x10, 0x08, 0x00, 0x00, 00,
+ 0x00, 0x00, (byte)0x04, 0x10, 0x08, 0x00, 0x00, 0,
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
+ @Test
public void testRead() {
ExMediaAtom record = new ExMediaAtom(data, 0, data.length);
assertEquals(RecordTypes.ExMediaAtom.typeID, record.getRecordType());
@@ -45,6 +47,7 @@ public final class TestExMediaAtom extends TestCase {
assertFalse(record.getFlag(ExMediaAtom.fRewind));
}
+ @Test
public void testWrite() throws Exception {
ExMediaAtom record = new ExMediaAtom(data, 0, data.length);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
@@ -54,6 +57,7 @@ public final class TestExMediaAtom extends TestCase {
assertArrayEquals(data, b);
}
+ @Test
public void testNewRecord() throws Exception {
ExMediaAtom ref = new ExMediaAtom(data, 0, data.length);
assertEquals(0, ref.getMask()); //
@@ -71,6 +75,7 @@ public final class TestExMediaAtom extends TestCase {
assertArrayEquals(data, b);
}
+ @Test
public void testFlags() {
ExMediaAtom record = new ExMediaAtom();
diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestExObjListAtom.java b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestExObjListAtom.java
index 7f1110863c..4a6c02696f 100644
--- a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestExObjListAtom.java
+++ b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestExObjListAtom.java
@@ -18,30 +18,34 @@
package org.apache.poi.hslf.record;
-import junit.framework.TestCase;
+import static org.apache.poi.ss.formula.functions.AbstractNumericTestCase.assertEquals;
+import static org.junit.Assert.assertArrayEquals;
+
import java.io.ByteArrayOutputStream;
+import org.junit.Test;
+
/**
* Tests that ExObjListAtom works properly.
- *
- * @author Nick Burch (nick at torchbox dot com)
*/
-public class TestExObjListAtom extends TestCase {
+public class TestExObjListAtom {
// From a real file
private final byte[] data_a = new byte[] {
- 00, 00, 0x0A, 0x04, 04, 00, 00, 00,
- 01, 00, 00, 00
+ 0, 0, 0x0A, 0x04, 4, 0, 0, 0,
+ 1, 0, 0, 0
};
private final byte[] data_b = new byte[] {
- 00, 00, 0x0A, 0x04, 04, 00, 00, 00,
- 04, 00, 00, 00
+ 0, 0, 0x0A, 0x04, 4, 0, 0, 0,
+ 4, 0, 0, 0
};
+ @Test
public void testRecordType() {
ExObjListAtom eoa = new ExObjListAtom(data_a, 0, data_a.length);
- assertEquals(1034l, eoa.getRecordType());
+ assertEquals(1034L, eoa.getRecordType());
}
+ @Test
public void testGetSeed() {
ExObjListAtom eoa = new ExObjListAtom(data_a, 0, data_a.length);
ExObjListAtom eob = new ExObjListAtom(data_b, 0, data_b.length);
@@ -50,19 +54,16 @@ public class TestExObjListAtom extends TestCase {
assertEquals(4, eob.getObjectIDSeed());
}
+ @Test
public void testWrite() throws Exception {
ExObjListAtom eoa = new ExObjListAtom(data_a, 0, data_a.length);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
eoa.writeOut(baos);
- byte[] b = baos.toByteArray();
-
- assertEquals(data_a.length, b.length);
- for(int i=0; i<data_a.length; i++) {
- assertEquals(data_a[i],b[i]);
- }
+ assertArrayEquals(data_a, baos.toByteArray());
}
// Create A from scratch
+ @Test
public void testCreate() throws Exception {
ExObjListAtom eoa = new ExObjListAtom();
@@ -72,15 +73,11 @@ public class TestExObjListAtom extends TestCase {
// Check it's now the same as a
ByteArrayOutputStream baos = new ByteArrayOutputStream();
eoa.writeOut(baos);
- byte[] b = baos.toByteArray();
-
- assertEquals(data_a.length, b.length);
- for(int i=0; i<data_a.length; i++) {
- assertEquals(data_a[i],b[i]);
- }
+ assertArrayEquals(data_a, baos.toByteArray());
}
// Try to turn a into b
+ @Test
public void testChange() throws Exception {
ExObjListAtom eoa = new ExObjListAtom(data_a, 0, data_a.length);
@@ -90,12 +87,6 @@ public class TestExObjListAtom extends TestCase {
// Check bytes are now the same
ByteArrayOutputStream baos = new ByteArrayOutputStream();
eoa.writeOut(baos);
- byte[] b = baos.toByteArray();
-
- // Should now be the same
- assertEquals(data_b.length, b.length);
- for(int i=0; i<data_b.length; i++) {
- assertEquals(data_b[i],b[i]);
- }
+ assertArrayEquals(data_b, baos.toByteArray());
}
}
diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestExOleObjAtom.java b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestExOleObjAtom.java
index ca33bb4d6b..069405b5b3 100644
--- a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestExOleObjAtom.java
+++ b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestExOleObjAtom.java
@@ -18,23 +18,23 @@
package org.apache.poi.hslf.record;
import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
import java.io.ByteArrayOutputStream;
-import junit.framework.TestCase;
+import org.junit.Test;
/**
* Tests that {@link ExOleObjAtom} works properly
- *
- * @author Yegor Kozlov
*/
-public final class TestExOleObjAtom extends TestCase {
+public final class TestExOleObjAtom {
// From a real file (embedded SWF control)
private final byte[] data = {
0x01, 0x00, (byte)0xC3, 0x0F, 0x18, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, (byte)0x96, 0x13, 0x00 };
+ @Test
public void testRead() {
ExOleObjAtom record = new ExOleObjAtom(data, 0, data.length);
assertEquals(RecordTypes.ExOleObjAtom.typeID, record.getRecordType());
@@ -47,15 +47,15 @@ public final class TestExOleObjAtom extends TestCase {
assertEquals(record.getOptions(), 1283584); //ther meaning is unknown
}
+ @Test
public void testWrite() throws Exception {
ExOleObjAtom record = new ExOleObjAtom(data, 0, data.length);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
record.writeOut(baos);
- byte[] b = baos.toByteArray();
-
- assertArrayEquals(data, b);
+ assertArrayEquals(data, baos.toByteArray());
}
+ @Test
public void testNewRecord() throws Exception {
ExOleObjAtom record = new ExOleObjAtom();
record.setDrawAspect(ExOleObjAtom.DRAW_ASPECT_VISIBLE);
@@ -67,8 +67,6 @@ public final class TestExOleObjAtom extends TestCase {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
record.writeOut(baos);
- byte[] b = baos.toByteArray();
-
- assertArrayEquals(data, b);
+ assertArrayEquals(data, baos.toByteArray());
}
}
diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestExVideoContainer.java b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestExVideoContainer.java
index 10dc9404c8..0f143e4fff 100644
--- a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestExVideoContainer.java
+++ b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestExVideoContainer.java
@@ -19,17 +19,20 @@ package org.apache.poi.hslf.record;
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 java.io.ByteArrayOutputStream;
-import junit.framework.TestCase;
+import org.junit.Test;
/**
* Tests that {@link HeadersFootersAtom} works properly
*
* @author Yegor Kozlov
*/
-public final class TestExVideoContainer extends TestCase {
+public final class TestExVideoContainer {
// From a real file
private final byte[] data = new byte[]{
@@ -47,9 +50,7 @@ public final class TestExVideoContainer extends TestCase {
0x73, 0x00, 0x5C, 0x00, 0x63, 0x00, 0x61, 0x00, 0x72, 0x00, 0x64, 0x00, 0x73, 0x00, 0x2E, 0x00,
0x6D, 0x00, 0x70, 0x00, 0x67, 0x00};
-
-
-
+ @Test
public void testRead() {
ExVideoContainer record = new ExVideoContainer(data, 0, data.length);
assertEquals(RecordTypes.ExVideoContainer.typeID, record.getRecordType());
@@ -66,15 +67,15 @@ public final class TestExVideoContainer extends TestCase {
assertEquals("D:\\projects\\SchulerAG\\mcom_v_1_0_4\\view\\data\\tests\\images\\cards.mpg", path.getText());
}
+ @Test
public void testWrite() throws Exception {
ExVideoContainer record = new ExVideoContainer(data, 0, data.length);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
record.writeOut(baos);
- byte[] b = baos.toByteArray();
-
- assertArrayEquals(data, b);
+ assertArrayEquals(data, baos.toByteArray());
}
+ @Test
public void testNewRecord() throws Exception {
ExVideoContainer record = new ExVideoContainer();
record.getExMediaAtom().setObjectId(1);
@@ -82,8 +83,6 @@ public final class TestExVideoContainer extends TestCase {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
record.writeOut(baos);
- byte[] b = baos.toByteArray();
-
- assertArrayEquals(data, b);
+ assertArrayEquals(data, baos.toByteArray());
}
}
diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestHeadersFootersAtom.java b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestHeadersFootersAtom.java
index c694b90d4f..6819356db2 100644
--- a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestHeadersFootersAtom.java
+++ b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestHeadersFootersAtom.java
@@ -19,22 +19,24 @@ package org.apache.poi.hslf.record;
import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
import java.io.ByteArrayOutputStream;
-import junit.framework.TestCase;
+import org.junit.Test;
/**
* Tests that {@link HeadersFootersAtom} works properly
- *
- * @author Yegor Kozlov
*/
-public final class TestHeadersFootersAtom extends TestCase {
+public final class TestHeadersFootersAtom {
// From a real file
private final byte[] data = new byte[] {
- 0x00, 0x00, (byte)0xDA, 0x0F, 0x04, 0x00, 0x00, 00,
+ 0x00, 0x00, (byte)0xDA, 0x0F, 0x04, 0x00, 0x00, 0,
0x00, 0x00, 0x23, 0x00 };
+ @Test
public void testRead() {
HeadersFootersAtom record = new HeadersFootersAtom(data, 0, data.length);
assertEquals(RecordTypes.HeadersFootersAtom.typeID, record.getRecordType());
@@ -50,15 +52,15 @@ public final class TestHeadersFootersAtom extends TestCase {
assertTrue(record.getFlag(HeadersFootersAtom.fHasFooter));
}
+ @Test
public void testWrite() throws Exception {
HeadersFootersAtom record = new HeadersFootersAtom(data, 0, data.length);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
record.writeOut(baos);
- byte[] b = baos.toByteArray();
-
- assertArrayEquals(data, b);
+ assertArrayEquals(data, baos.toByteArray());
}
+ @Test
public void testNewRecord() throws Exception {
HeadersFootersAtom record = new HeadersFootersAtom();
record.setFlag(HeadersFootersAtom.fHasDate, true);
@@ -67,11 +69,10 @@ public final class TestHeadersFootersAtom extends TestCase {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
record.writeOut(baos);
- byte[] b = baos.toByteArray();
-
- assertArrayEquals(data, b);
+ assertArrayEquals(data, baos.toByteArray());
}
+ @Test
public void testFlags() {
HeadersFootersAtom record = new HeadersFootersAtom();
diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestHeadersFootersContainer.java b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestHeadersFootersContainer.java
index 6e787e7c83..3a0c1f5b03 100644
--- a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestHeadersFootersContainer.java
+++ b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestHeadersFootersContainer.java
@@ -19,17 +19,18 @@ package org.apache.poi.hslf.record;
import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
import java.io.ByteArrayOutputStream;
-import junit.framework.TestCase;
+import org.junit.Test;
/**
* Tests that {@link HeadersFootersContainer} works properly
- *
- * @author Yegor Kozlov
*/
-public final class TestHeadersFootersContainer extends TestCase {
+public final class TestHeadersFootersContainer {
// SlideHeadersFootersContainer
private final byte[] slideData = new byte[] {
0x3F, 0x00, (byte)0xD9, 0x0F, 0x2E, 0x00, 0x00, 0x00,
@@ -52,6 +53,7 @@ public final class TestHeadersFootersContainer extends TestCase {
0x6F, 0x00, 0x6F, 0x00, 0x74, 0x00, 0x65, 0x00, 0x72, 0x00
};
+ @Test
public void testReadSlideHeadersFootersContainer() {
HeadersFootersContainer record = new HeadersFootersContainer(slideData, 0, slideData.length);
assertEquals(RecordTypes.HeadersFooters.typeID, record.getRecordType());
@@ -71,15 +73,15 @@ public final class TestHeadersFootersContainer extends TestCase {
assertNull(record.getHeaderAtom());
}
+ @Test
public void testWriteSlideHeadersFootersContainer() throws Exception {
HeadersFootersContainer record = new HeadersFootersContainer(slideData, 0, slideData.length);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
record.writeOut(baos);
- byte[] b = baos.toByteArray();
-
- assertArrayEquals(slideData, b);
+ assertArrayEquals(slideData, baos.toByteArray());
}
+ @Test
public void testNewSlideHeadersFootersContainer() throws Exception {
HeadersFootersContainer record = new HeadersFootersContainer(HeadersFootersContainer.SlideHeadersFootersContainer);
@@ -100,11 +102,10 @@ public final class TestHeadersFootersContainer extends TestCase {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
record.writeOut(baos);
- byte[] b = baos.toByteArray();
-
- assertArrayEquals(slideData, b);
+ assertArrayEquals(slideData, baos.toByteArray());
}
+ @Test
public void testReadNotesHeadersFootersContainer() {
HeadersFootersContainer record = new HeadersFootersContainer(notesData, 0, notesData.length);
assertEquals(RecordTypes.HeadersFooters.typeID, record.getRecordType());
@@ -125,15 +126,15 @@ public final class TestHeadersFootersContainer extends TestCase {
assertEquals("Note Footer", csFooter.getText());
}
+ @Test
public void testWriteNotesHeadersFootersContainer() throws Exception {
HeadersFootersContainer record = new HeadersFootersContainer(notesData, 0, notesData.length);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
record.writeOut(baos);
- byte[] b = baos.toByteArray();
-
- assertArrayEquals(notesData, b);
+ assertArrayEquals(notesData, baos.toByteArray());
}
+ @Test
public void testNewNotesHeadersFootersContainer() throws Exception {
HeadersFootersContainer record = new HeadersFootersContainer(HeadersFootersContainer.NotesHeadersFootersContainer);
@@ -162,9 +163,7 @@ public final class TestHeadersFootersContainer extends TestCase {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
record.writeOut(baos);
- byte[] b = baos.toByteArray();
-
- assertArrayEquals(notesData, b);
+ assertArrayEquals(notesData, baos.toByteArray());
}
}
diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestInteractiveInfo.java b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestInteractiveInfo.java
index 24278fa14e..9350039c23 100644
--- a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestInteractiveInfo.java
+++ b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestInteractiveInfo.java
@@ -21,29 +21,32 @@
package org.apache.poi.hslf.record;
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+
import java.io.ByteArrayOutputStream;
-import junit.framework.TestCase;
+import org.junit.Test;
/**
* Tests that InteractiveInfoAtom works properly.
- *
- * @author Nick Burch (nick at torchbox dot com)
*/
-public class TestInteractiveInfo extends TestCase {
+public class TestInteractiveInfo {
// From a real file
- private final byte[] data_a = new byte[] {
- 0x0F, 00, 0xF2-256, 0x0F, 0x18, 00, 00, 00,
- 00, 00, 0xF3-256, 0x0F, 0x10, 00, 00, 00,
- 00, 00, 00, 00, 01, 00, 00, 00,
- 04, 00, 00, 00, 8, 00, 00, 00
+ private final byte[] data_a = {
+ 0x0F, 0, 0xF2-256, 0x0F, 0x18, 0, 0, 0,
+ 0, 0, 0xF3-256, 0x0F, 0x10, 0, 0, 0,
+ 0, 0, 0, 0, 1, 0, 0, 0,
+ 4, 0, 0, 0, 8, 0, 0, 0
};
+ @Test
public void testRecordType() {
InteractiveInfo ii = new InteractiveInfo(data_a, 0, data_a.length);
assertEquals(4082, ii.getRecordType());
}
+ @Test
public void testGetChildDetails() {
InteractiveInfo ii = new InteractiveInfo(data_a, 0, data_a.length);
InteractiveInfoAtom ia = ii.getInteractiveInfoAtom();
@@ -51,19 +54,16 @@ public class TestInteractiveInfo extends TestCase {
assertEquals(1, ia.getHyperlinkID());
}
+ @Test
public void testWrite() throws Exception {
InteractiveInfo ii = new InteractiveInfo(data_a, 0, data_a.length);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ii.writeOut(baos);
- byte[] b = baos.toByteArray();
-
- assertEquals(data_a.length, b.length);
- for(int i=0; i<data_a.length; i++) {
- assertEquals(data_a[i],b[i]);
- }
+ assertArrayEquals(data_a, baos.toByteArray());
}
// Create A from scratch
+ @Test
public void testCreate() throws Exception {
InteractiveInfo ii = new InteractiveInfo();
InteractiveInfoAtom ia = ii.getInteractiveInfoAtom();
@@ -77,11 +77,6 @@ public class TestInteractiveInfo extends TestCase {
// Check it's now the same as a
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ii.writeOut(baos);
- byte[] b = baos.toByteArray();
-
- assertEquals(data_a.length, b.length);
- for(int i=0; i<data_a.length; i++) {
- assertEquals(data_a[i],b[i]);
- }
+ assertArrayEquals(data_a, baos.toByteArray());
}
}
diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestInteractiveInfoAtom.java b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestInteractiveInfoAtom.java
index cabed2578c..86215792ff 100644
--- a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestInteractiveInfoAtom.java
+++ b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestInteractiveInfoAtom.java
@@ -18,32 +18,36 @@
package org.apache.poi.hslf.record;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+
import java.io.ByteArrayOutputStream;
+import org.junit.Test;
+
/**
* Tests that InteractiveInfoAtom works properly.
- *
- * @author Nick Burch (nick at torchbox dot com)
*/
-public class TestInteractiveInfoAtom extends TestCase {
+public class TestInteractiveInfoAtom {
// From a real file
private final byte[] data_a = new byte[] {
- 00, 00, 0xF3-256, 0x0F, 0x10, 00, 00, 00,
- 00, 00, 00, 00, 01, 00, 00, 00,
- 04, 00, 00, 00, 8, 00, 00, 00
+ 0, 0, 0xF3-256, 0x0F, 0x10, 0, 0, 0,
+ 0, 0, 0, 0, 1, 0, 0, 0,
+ 4, 0, 0, 0, 8, 0, 0, 0
};
private final byte[] data_b = new byte[] {
- 00, 00, 0xF3-256, 0x0F, 0x10, 00, 00, 00,
- 00, 00, 00, 00, 04, 00, 00, 00,
- 04, 00, 00, 00, 8, 00, 00, 00
+ 0, 0, 0xF3-256, 0x0F, 0x10, 0, 0, 0,
+ 0, 0, 0, 0, 4, 0, 0, 0,
+ 4, 0, 0, 0, 8, 0, 0, 0
};
+ @Test
public void testRecordType() {
InteractiveInfoAtom ia = new InteractiveInfoAtom(data_a, 0, data_a.length);
- assertEquals(4083l, ia.getRecordType());
+ assertEquals(4083L, ia.getRecordType());
}
+ @Test
public void testGetNumber() {
InteractiveInfoAtom ia = new InteractiveInfoAtom(data_a, 0, data_a.length);
InteractiveInfoAtom ib = new InteractiveInfoAtom(data_b, 0, data_b.length);
@@ -52,6 +56,7 @@ public class TestInteractiveInfoAtom extends TestCase {
assertEquals(4, ib.getHyperlinkID());
}
+ @Test
public void testGetRest() {
InteractiveInfoAtom ia = new InteractiveInfoAtom(data_a, 0, data_a.length);
InteractiveInfoAtom ib = new InteractiveInfoAtom(data_b, 0, data_b.length);
@@ -66,19 +71,16 @@ public class TestInteractiveInfoAtom extends TestCase {
assertEquals(8, ib.getHyperlinkType());
}
+ @Test
public void testWrite() throws Exception {
InteractiveInfoAtom ia = new InteractiveInfoAtom(data_a, 0, data_a.length);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ia.writeOut(baos);
- byte[] b = baos.toByteArray();
-
- assertEquals(data_a.length, b.length);
- for(int i=0; i<data_a.length; i++) {
- assertEquals(data_a[i],b[i]);
- }
+ assertArrayEquals(data_a, baos.toByteArray());
}
// Create A from scratch
+ @Test
public void testCreate() throws Exception {
InteractiveInfoAtom ia = new InteractiveInfoAtom();
@@ -91,15 +93,11 @@ public class TestInteractiveInfoAtom extends TestCase {
// Check it's now the same as a
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ia.writeOut(baos);
- byte[] b = baos.toByteArray();
-
- assertEquals(data_a.length, b.length);
- for(int i=0; i<data_a.length; i++) {
- assertEquals(data_a[i],b[i]);
- }
+ assertArrayEquals(data_a, baos.toByteArray());
}
// Try to turn a into b
+ @Test
public void testChange() throws Exception {
InteractiveInfoAtom ia = new InteractiveInfoAtom(data_a, 0, data_a.length);
@@ -109,12 +107,6 @@ public class TestInteractiveInfoAtom extends TestCase {
// Check bytes are now the same
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ia.writeOut(baos);
- byte[] b = baos.toByteArray();
-
- // Should now be the same
- assertEquals(data_b.length, b.length);
- for(int i=0; i<data_b.length; i++) {
- assertEquals(data_b[i],b[i]);
- }
+ assertArrayEquals(data_b, baos.toByteArray());
}
}
diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestNotesAtom.java b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestNotesAtom.java
index 796fb6eb2c..86c8088282 100644
--- a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestNotesAtom.java
+++ b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestNotesAtom.java
@@ -18,23 +18,29 @@
package org.apache.poi.hslf.record;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+
import java.io.ByteArrayOutputStream;
+import org.junit.Test;
+
/**
* Tests that NotesAtom works properly
- *
- * @author Nick Burch (nick at torchbox dot com)
*/
-public final class TestNotesAtom extends TestCase {
+public final class TestNotesAtom {
// From a real file
private final byte[] data_a = new byte[] { 1, 0, 0xF1-256, 3, 8, 0, 0, 0,
0, 0, 0, 0x80-256, 0, 0, 0x0D, 0x30 };
+ @Test
public void testRecordType() {
NotesAtom na = new NotesAtom(data_a, 0, data_a.length);
- assertEquals(1009l, na.getRecordType());
+ assertEquals(1009L, na.getRecordType());
}
+
+ @Test
public void testFlags() {
NotesAtom na = new NotesAtom(data_a, 0, data_a.length);
assertEquals(0x80000000, na.getSlideID());
@@ -43,15 +49,11 @@ public final class TestNotesAtom extends TestCase {
assertFalse(na.getFollowMasterBackground());
}
+ @Test
public void testWrite() throws Exception {
NotesAtom na = new NotesAtom(data_a, 0, data_a.length);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
na.writeOut(baos);
- byte[] b = baos.toByteArray();
-
- assertEquals(data_a.length, b.length);
- for(int i=0; i<data_a.length; i++) {
- assertEquals(data_a[i],b[i]);
- }
+ assertArrayEquals(data_a, baos.toByteArray());
}
}
diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestSlidePersistAtom.java b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestSlidePersistAtom.java
index 19d99c4569..10e4018be2 100644
--- a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestSlidePersistAtom.java
+++ b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestSlidePersistAtom.java
@@ -18,24 +18,30 @@
package org.apache.poi.hslf.record;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
import java.io.ByteArrayOutputStream;
+import org.junit.Test;
+
/**
* Tests that SlidePersistAtom works properly
- *
- * @author Nick Burch (nick at torchbox dot com)
*/
-public final class TestSlidePersistAtom extends TestCase {
+public final class TestSlidePersistAtom {
// From a real file
private final byte[] data_a = new byte[] { 0, 0, 0xF3-256, 3, 0x14, 0, 0, 0,
4, 0, 0, 0, 4, 0, 0, 0, 2, 0, 0, 0, 0,
1, 0, 0, 0, 0, 0, 0 };
+ @Test
public void testRecordType() {
SlidePersistAtom spa = new SlidePersistAtom(data_a, 0, data_a.length);
- assertEquals(1011l, spa.getRecordType());
+ assertEquals(1011L, spa.getRecordType());
}
+
+ @Test
public void testFlags() {
SlidePersistAtom spa = new SlidePersistAtom(data_a, 0, data_a.length);
assertEquals(4, spa.getRefID() );
@@ -44,15 +50,11 @@ public final class TestSlidePersistAtom extends TestCase {
assertEquals(256, spa.getSlideIdentifier());
}
+ @Test
public void testWrite() throws Exception {
SlidePersistAtom spa = new SlidePersistAtom(data_a, 0, data_a.length);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
spa.writeOut(baos);
- byte[] b = baos.toByteArray();
-
- assertEquals(data_a.length, b.length);
- for(int i=0; i<data_a.length; i++) {
- assertEquals(data_a[i],b[i]);
- }
+ assertArrayEquals(data_a, baos.toByteArray());
}
}
diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestTextBytesAtom.java b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestTextBytesAtom.java
index 10cc527ed6..a53de76457 100644
--- a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestTextBytesAtom.java
+++ b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestTextBytesAtom.java
@@ -18,65 +18,62 @@
package org.apache.poi.hslf.record;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+
import java.io.ByteArrayOutputStream;
import java.nio.charset.StandardCharsets;
+import org.junit.Test;
+
/**
* Tests that TextBytesAtom works properly
- *
- * @author Nick Burch (nick at torchbox dot com)
*/
-public final class TestTextBytesAtom extends TestCase {
+public final class TestTextBytesAtom {
// From a real file
- private final byte[] data = new byte[] { 0, 0, 0xA8-256, 0x0f, 0x1c, 0, 0, 0,
+ private final byte[] data = { 0, 0, 0xA8-256, 0x0f, 0x1c, 0, 0, 0,
0x54, 0x68, 0x69, 0x73, 0x20, 0x69, 0x73, 0x20, 0x74, 0x68,
0x65, 0x20, 0x74, 0x69, 0x74, 0x6C, 0x65, 0x20, 0x6F, 0x6E,
0x20, 0x70, 0x61, 0x67, 0x65, 0x20, 0x32 };
- private final String data_text = "This is the title on page 2";
- private final byte[] alt_data = new byte[] { 0, 0, 0xA8-256, 0x0F, 0x14, 0, 0, 0,
+ private final byte[] alt_data = { 0, 0, 0xA8-256, 0x0F, 0x14, 0, 0, 0,
0x54, 0x68, 0x69, 0x73, 0x20, 0x69, 0x73, 0x20, 0x61, 0x20,
0x74, 0x65, 0x73, 0x74, 0x20, 0x74, 0x69, 0x74, 0x6C, 0x65 };
private final String alt_text = "This is a test title";
+ @Test
public void testRecordType() {
TextBytesAtom tba = new TextBytesAtom(data,0,data.length);
- assertEquals(4008l, tba.getRecordType());
+ assertEquals(4008L, tba.getRecordType());
}
+ @Test
public void testTextA() {
TextBytesAtom tba = new TextBytesAtom(data,0,data.length);
+ String data_text = "This is the title on page 2";
assertEquals(data_text, tba.getText());
}
+
+ @Test
public void testTextB() {
TextBytesAtom tba = new TextBytesAtom(alt_data,0,alt_data.length);
assertEquals(alt_text, tba.getText());
}
+ @Test
public void testChangeText() throws Exception {
TextBytesAtom tba = new TextBytesAtom(data,0,data.length);
tba.setText(alt_text.getBytes(StandardCharsets.ISO_8859_1));
ByteArrayOutputStream baos = new ByteArrayOutputStream();
tba.writeOut(baos);
- byte[] b = baos.toByteArray();
-
- // Compare the header and the text
- assertEquals(alt_data.length, b.length);
- for(int i=0; i<alt_data.length; i++) {
- assertEquals(alt_data[i],b[i]);
- }
+ assertArrayEquals(alt_data, baos.toByteArray());
}
+ @Test
public void testWrite() throws Exception {
TextBytesAtom tba = new TextBytesAtom(data,0,data.length);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
tba.writeOut(baos);
- byte[] b = baos.toByteArray();
-
- assertEquals(data.length, b.length);
- for(int i=0; i<data.length; i++) {
- assertEquals(data[i],b[i]);
- }
+ assertArrayEquals(data, baos.toByteArray());
}
}
diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestTextCharsAtom.java b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestTextCharsAtom.java
index 8158cb1127..80d861f52b 100644
--- a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestTextCharsAtom.java
+++ b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestTextCharsAtom.java
@@ -18,15 +18,17 @@
package org.apache.poi.hslf.record;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+
import java.io.ByteArrayOutputStream;
+import org.junit.Test;
+
/**
* Tests that TextCharsAtom works properly
- *
- * @author Nick Burch (nick at torchbox dot com)
*/
-public final class TestTextCharsAtom extends TestCase {
+public final class TestTextCharsAtom {
// From a real file
private final byte[] data = new byte[] { 0, 0, 0xA0-256, 0x0f, 0x08, 0, 0, 0,
0x54, 0x00, 0x68, 0x00, 0x69, 0x00, 0x73, 0x00 };
@@ -35,47 +37,43 @@ public final class TestTextCharsAtom extends TestCase {
0x54, 0x00, 0x68, 0x00, 0x69, 0x00, 0x73, 0x00, 0xa3-256, 0x01 };
private final String alt_text = "This\u01A3";
+ @Test
public void testRecordType() {
TextCharsAtom tca = new TextCharsAtom(data,0,data.length);
- assertEquals(4000l, tca.getRecordType());
+ assertEquals(4000L, tca.getRecordType());
}
+ @Test
public void testTextA() {
TextCharsAtom tca = new TextCharsAtom(data,0,data.length);
assertEquals(data_text, tca.getText());
}
+
+ @Test
public void testTextB() {
TextCharsAtom tca = new TextCharsAtom(alt_data,0,alt_data.length);
assertEquals(alt_text, tca.getText());
}
+ @Test
public void testChangeText() throws Exception {
TextCharsAtom tca = new TextCharsAtom(data,0,data.length);
tca.setText(alt_text);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
tca.writeOut(baos);
- byte[] b = baos.toByteArray();
-
- // Compare the header and the text
- assertEquals(alt_data.length, b.length);
- for(int i=0; i<alt_data.length; i++) {
- assertEquals(alt_data[i],b[i]);
- }
+ assertArrayEquals(alt_data, baos.toByteArray());
}
+ @Test
public void testWrite() throws Exception {
TextCharsAtom tca = new TextCharsAtom(data,0,data.length);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
tca.writeOut(baos);
- byte[] b = baos.toByteArray();
-
- assertEquals(data.length, b.length);
- for(int i=0; i<data.length; i++) {
- assertEquals(data[i],b[i]);
- }
+ assertArrayEquals(data, baos.toByteArray());
}
+ @Test
public void testCreateNew() throws Exception {
TextCharsAtom tca = new TextCharsAtom();
assertEquals(0, tca.getText().length());
@@ -86,12 +84,7 @@ public final class TestTextCharsAtom extends TestCase {
// Check it's now like data
ByteArrayOutputStream baos = new ByteArrayOutputStream();
tca.writeOut(baos);
- byte[] b = baos.toByteArray();
-
- assertEquals(data.length, b.length);
- for(int i=0; i<data.length; i++) {
- assertEquals(data[i],b[i]);
- }
+ assertArrayEquals(data, baos.toByteArray());
}
}
diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestTextHeaderAtom.java b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestTextHeaderAtom.java
index fb3c47dc28..417ce16693 100644
--- a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestTextHeaderAtom.java
+++ b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestTextHeaderAtom.java
@@ -18,26 +18,30 @@
package org.apache.poi.hslf.record;
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+
import java.io.ByteArrayOutputStream;
-import junit.framework.TestCase;
import org.apache.poi.sl.usermodel.TextShape.TextPlaceholder;
+import org.junit.Test;
/**
* Tests that TextHeaderAtom works properly
- *
- * @author Nick Burch (nick at torchbox dot com)
*/
-public final class TestTextHeaderAtom extends TestCase {
+public final class TestTextHeaderAtom {
// From a real file
- private final byte[] notes_data = new byte[] { 0, 0, 0x9f-256, 0x0f, 4, 0, 0, 0, 2, 0, 0, 0};
- private final byte[] title_data = new byte[] { 0, 0, 0x9f-256, 0x0f, 4, 0, 0, 0, 0, 0, 0, 0 };
- private final byte[] body_data = new byte[] { 0, 0, 0x9f-256, 0x0f, 4, 0, 0, 0, 1, 0, 0, 0 };
+ private final byte[] notes_data = { 0, 0, 0x9f-256, 0x0f, 4, 0, 0, 0, 2, 0, 0, 0 };
+ private final byte[] title_data = { 0, 0, 0x9f-256, 0x0f, 4, 0, 0, 0, 0, 0, 0, 0 };
+ private final byte[] body_data = { 0, 0, 0x9f-256, 0x0f, 4, 0, 0, 0, 1, 0, 0, 0 };
+ @Test
public void testRecordType() {
TextHeaderAtom tha = new TextHeaderAtom(notes_data,0,12);
- assertEquals(3999l, tha.getRecordType());
+ assertEquals(3999L, tha.getRecordType());
}
+
+ @Test
public void testTypes() {
TextHeaderAtom n_tha = new TextHeaderAtom(notes_data,0,12);
TextHeaderAtom t_tha = new TextHeaderAtom(title_data,0,12);
@@ -47,15 +51,11 @@ public final class TestTextHeaderAtom extends TestCase {
assertEquals(TextPlaceholder.BODY.nativeId, b_tha.getTextType());
}
+ @Test
public void testWrite() throws Exception {
TextHeaderAtom tha = new TextHeaderAtom(notes_data,0,12);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
tha.writeOut(baos);
- byte[] b = baos.toByteArray();
-
- assertEquals(notes_data.length, b.length);
- for(int i=0; i<notes_data.length; i++) {
- assertEquals(notes_data[i],b[i]);
- }
+ assertArrayEquals(notes_data, baos.toByteArray());
}
}
diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestTextSpecInfoAtom.java b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestTextSpecInfoAtom.java
index 4f88d4cfd1..b97f91ad0e 100644
--- a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestTextSpecInfoAtom.java
+++ b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestTextSpecInfoAtom.java
@@ -18,20 +18,21 @@
package org.apache.poi.hslf.record;
import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
import java.io.ByteArrayOutputStream;
-import junit.framework.TestCase;
+import org.junit.Test;
/**
* Tests TextSpecInfoAtom
*
* @author Yegor Kozlov
*/
-public final class TestTextSpecInfoAtom extends TestCase {
+public final class TestTextSpecInfoAtom {
//from a real file
- private final byte[] data_1 = new byte[] {
+ private final byte[] data_1 = {
0x00, 0x00, (byte)0xAA, 0x0F, 0x2C, 0x00, 0x00, 0x00,
0x0A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46, 0x00,
@@ -39,7 +40,7 @@ public final class TestTextSpecInfoAtom extends TestCase {
0x00, 0x00, 0x00, 0x03, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
-
+ @Test
public void testRead() {
TextSpecInfoAtom spec = new TextSpecInfoAtom(data_1, 0, data_1.length);
TextSpecInfoRun[] run = spec.getTextSpecInfoRuns();
@@ -50,18 +51,17 @@ public final class TestTextSpecInfoAtom extends TestCase {
assertEquals(70, run[2].getLength());
assertEquals(9, run[3].getLength());
assertEquals(32, run[4].getLength());
-
}
+ @Test
public void testWrite() throws Exception {
TextSpecInfoAtom spec = new TextSpecInfoAtom(data_1, 0, data_1.length);
ByteArrayOutputStream out = new ByteArrayOutputStream();
spec.writeOut(out);
-
- byte[] result = out.toByteArray();
- assertArrayEquals(result, data_1);
+ assertArrayEquals(data_1, out.toByteArray());
}
+ @Test
public void testReset() throws Exception {
TextSpecInfoAtom spec = new TextSpecInfoAtom(data_1, 0, data_1.length);
spec.reset(32); //length of the parent text
diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestTxInteractiveInfoAtom.java b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestTxInteractiveInfoAtom.java
index 7f6eab12f9..41e24e7369 100644
--- a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestTxInteractiveInfoAtom.java
+++ b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestTxInteractiveInfoAtom.java
@@ -18,26 +18,29 @@
package org.apache.poi.hslf.record;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+
import java.io.ByteArrayOutputStream;
+import org.junit.Test;
+
/**
* Tests that TxInteractiveInfoAtom works properly.
- *
- * @author Yegor Kozlov
*/
-public final class TestTxInteractiveInfoAtom extends TestCase {
+public final class TestTxInteractiveInfoAtom {
// From WithLinks.ppt
- private final byte[] data_a = new byte[] {
- 00, 00, (byte)0xDF, 0x0F, 0x08, 00, 00, 00,
- 0x19, 00, 00, 00, 0x38, 00, 00, 00
+ private final byte[] data_a = {
+ 0, 0, (byte)0xDF, 0x0F, 0x08, 0, 0, 0,
+ 0x19, 0, 0, 0, 0x38, 0, 0, 0
};
- private final byte[] data_b = new byte[] {
- 00, 00, (byte)0xDF, 0x0F, 0x08, 00, 00, 00,
- 0x39, 00, 00, 00, 0x4E, 00, 00, 00
+ private final byte[] data_b = {
+ 0, 0, (byte)0xDF, 0x0F, 0x08, 0, 0, 0,
+ 0x39, 0, 0, 0, 0x4E, 0, 0, 0
};
+ @Test
public void testRead() {
TxInteractiveInfoAtom ia1 = new TxInteractiveInfoAtom(data_a, 0, data_a.length);
@@ -52,19 +55,16 @@ public final class TestTxInteractiveInfoAtom extends TestCase {
assertEquals(78, ia2.getEndIndex());
}
+ @Test
public void testWrite() throws Exception {
TxInteractiveInfoAtom atom = new TxInteractiveInfoAtom(data_a, 0, data_a.length);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
atom.writeOut(baos);
- byte[] b = baos.toByteArray();
-
- assertEquals(data_a.length, b.length);
- for(int i=0; i<data_a.length; i++) {
- assertEquals(data_a[i],b[i]);
- }
+ assertArrayEquals(data_a, baos.toByteArray());
}
// Create A from scratch
+ @Test
public void testCreate() throws Exception {
TxInteractiveInfoAtom ia = new TxInteractiveInfoAtom();
@@ -75,15 +75,11 @@ public final class TestTxInteractiveInfoAtom extends TestCase {
// Check it's now the same as a
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ia.writeOut(baos);
- byte[] b = baos.toByteArray();
-
- assertEquals(data_a.length, b.length);
- for(int i=0; i<data_a.length; i++) {
- assertEquals(data_a[i],b[i]);
- }
+ assertArrayEquals(data_a, baos.toByteArray());
}
// Try to turn a into b
+ @Test
public void testChange() throws Exception {
TxInteractiveInfoAtom ia = new TxInteractiveInfoAtom(data_a, 0, data_a.length);
@@ -94,12 +90,6 @@ public final class TestTxInteractiveInfoAtom extends TestCase {
// Check bytes are now the same
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ia.writeOut(baos);
- byte[] b = baos.toByteArray();
-
- // Should now be the same
- assertEquals(data_b.length, b.length);
- for(int i=0; i<data_b.length; i++) {
- assertEquals(data_b[i],b[i]);
- }
+ assertArrayEquals(data_b, baos.toByteArray());
}
}
diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestTxMasterStyleAtom.java b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestTxMasterStyleAtom.java
index ba49c8cb5f..c08feff3f3 100644
--- a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestTxMasterStyleAtom.java
+++ b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestTxMasterStyleAtom.java
@@ -17,37 +17,43 @@
package org.apache.poi.hslf.record;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.fail;
+
import java.util.ArrayList;
import java.util.List;
-import junit.framework.AssertionFailedError;
-import junit.framework.TestCase;
import org.apache.poi.hslf.model.textproperties.TextProp;
import org.apache.poi.hslf.model.textproperties.TextPropCollection;
import org.apache.poi.hslf.usermodel.HSLFSlideShow;
import org.apache.poi.sl.usermodel.TextShape.TextPlaceholder;
+import org.junit.Before;
+import org.junit.Test;
/**
* Test <code>TestTxMasterStyleAtom</code> record.
* Check master style for the empty ppt which is created
* by the default constructor of <code>SlideShow</code>
- *
- * @author Yegor Kozlov
*/
-public final class TestTxMasterStyleAtom extends TestCase {
- protected HSLFSlideShow _ppt;
+public final class TestTxMasterStyleAtom {
+ private HSLFSlideShow _ppt;
- @Override
+ @Before
public void setUp() {
_ppt = new HSLFSlideShow();
}
+ @Test
public void testDefaultStyles() {
TxMasterStyleAtom[] txmaster = getMasterStyles();
for (final TxMasterStyleAtom atom : txmaster) {
final int txtype = atom.getTextType();
- switch (TextPlaceholder.fromNativeId(txtype)){
+ TextPlaceholder tp = TextPlaceholder.fromNativeId(txtype);
+ assertNotNull(tp);
+ switch (tp) {
case TITLE:
checkTitleType(atom);
break;
@@ -61,11 +67,8 @@ public final class TestTxMasterStyleAtom extends TestCase {
checkOtherType(atom);
break;
case CENTER_BODY:
- break;
case CENTER_TITLE:
- break;
case HALF_BODY:
- break;
case QUARTER_BODY:
break;
default:
@@ -200,7 +203,7 @@ public final class TestTxMasterStyleAtom extends TestCase {
* Collect all TxMasterStyleAtom records contained in the supplied slide show.
* There must be a TxMasterStyleAtom per each type of text defined in TextHeaderAtom
*/
- protected TxMasterStyleAtom[] getMasterStyles(){
+ private TxMasterStyleAtom[] getMasterStyles(){
List<TxMasterStyleAtom> lst = new ArrayList<>();
Record[] coreRecs = _ppt.getMostRecentCoreRecords();
@@ -221,13 +224,12 @@ public final class TestTxMasterStyleAtom extends TestCase {
Record[] rec = doc.getEnvironment().getChildRecords();
for (final Record atom : rec) {
if (atom instanceof TxMasterStyleAtom) {
- if (txstyle != null) fail("Document.Environment must contain 1 TxMasterStyleAtom");
+ assertNull("Document.Environment must contain 1 TxMasterStyleAtom", txstyle);
txstyle = (TxMasterStyleAtom)atom;
}
}
- if (txstyle == null) {
- throw new AssertionFailedError("TxMasterStyleAtom not found in Document.Environment");
- }
+
+ assertNotNull("TxMasterStyleAtom not found in Document.Environment", txstyle);
assertEquals("Document.Environment must contain TxMasterStyleAtom with type=TextHeaderAtom.OTHER_TYPE",
TextPlaceholder.OTHER.nativeId, txstyle.getTextType());
diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestUserEditAtom.java b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestUserEditAtom.java
index fca70287c0..85fd287b39 100644
--- a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestUserEditAtom.java
+++ b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestUserEditAtom.java
@@ -18,25 +18,30 @@
package org.apache.poi.hslf.record;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+
import java.io.ByteArrayOutputStream;
+import org.junit.Test;
+
/**
* Tests that UserEditAtom works properly
- *
- * @author Nick Burch (nick at torchbox dot com)
*/
-public final class TestUserEditAtom extends TestCase {
+public final class TestUserEditAtom {
// From a real file
private final byte[] data_a = new byte[] { 0, 0, 0xF5-256, 0x0F, 0x1C, 0, 0, 0,
- 00, 01, 00, 00, 0xD9-256, 18, 00, 03,
- 00, 00, 00, 00, 00, 0x18, 00, 00, 01, 00, 00, 00,
- 05, 00, 00, 00, 01, 00, 0xF6-256, 77 };
+ 0, 1, 0, 0, 0xD9-256, 18, 0, 3,
+ 0, 0, 0, 0, 0, 0x18, 0, 0, 1, 0, 0, 0,
+ 5, 0, 0, 0, 1, 0, 0xF6-256, 77 };
+ @Test
public void testRecordType() {
UserEditAtom uea = new UserEditAtom(data_a, 0, data_a.length);
- assertEquals(4085l, uea.getRecordType());
+ assertEquals(4085L, uea.getRecordType());
}
+
+ @Test
public void testFlags() {
UserEditAtom uea = new UserEditAtom(data_a, 0, data_a.length);
@@ -49,15 +54,11 @@ public final class TestUserEditAtom extends TestCase {
assertEquals((short)1, uea.getLastViewType() );
}
+ @Test
public void testWrite() throws Exception {
UserEditAtom uea = new UserEditAtom(data_a, 0, data_a.length);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
uea.writeOut(baos);
- byte[] b = baos.toByteArray();
-
- assertEquals(data_a.length, b.length);
- for(int i=0; i<data_a.length; i++) {
- assertEquals(data_a[i],b[i]);
- }
+ assertArrayEquals(data_a, baos.toByteArray());
}
}
diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestMostRecentRecords.java b/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestMostRecentRecords.java
index a7e2a62d51..a952bca5cd 100644
--- a/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestMostRecentRecords.java
+++ b/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestMostRecentRecords.java
@@ -18,28 +18,30 @@
package org.apache.poi.hslf.usermodel;
+import static org.junit.Assert.assertEquals;
+
import org.apache.poi.POIDataSamples;
import org.apache.poi.hslf.record.Record;
-
-import junit.framework.TestCase;
+import org.junit.Before;
+import org.junit.Test;
/**
* Tests that SlideShow finds the right records as its most recent ones
- *
- * @author Nick Burch (nick at torchbox dot com)
*/
-public final class TestMostRecentRecords extends TestCase {
+public final class TestMostRecentRecords {
// HSLFSlideShow primed on the test data
- private final HSLFSlideShowImpl hss;
+ private HSLFSlideShowImpl hss;
// SlideShow primed on the test data
- private final HSLFSlideShow ss;
+ private HSLFSlideShow ss;
- public TestMostRecentRecords() throws Exception {
- POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
+ @Before
+ public void setup() throws Exception {
+ POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
hss = new HSLFSlideShowImpl(slTests.openResourceAsStream("basic_test_ppt_file.ppt"));
ss = new HSLFSlideShow(hss);
}
+ @Test
public void testCount() {
// Most recent core records
Record[] mrcr = ss.getMostRecentCoreRecords();
@@ -48,6 +50,7 @@ public final class TestMostRecentRecords extends TestCase {
assertEquals(7, mrcr.length);
}
+ @Test
public void testRightRecordTypes() {
// Most recent core records
Record[] mrcr = ss.getMostRecentCoreRecords();
@@ -69,6 +72,7 @@ public final class TestMostRecentRecords extends TestCase {
assertEquals(1008, mrcr[6].getRecordType());
}
+ @Test
public void testCorrectRecords() {
// Most recent core records
Record[] mrcr = ss.getMostRecentCoreRecords();
diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestNotesText.java b/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestNotesText.java
index 59c5c65a70..0394f07069 100644
--- a/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestNotesText.java
+++ b/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestNotesText.java
@@ -18,41 +18,41 @@
package org.apache.poi.hslf.usermodel;
-import org.apache.poi.POIDataSamples;
+import static org.junit.Assert.assertArrayEquals;
-import junit.framework.TestCase;
+import org.apache.poi.POIDataSamples;
+import org.junit.Before;
+import org.junit.Test;
/**
* Tests that SlideShow returns MetaSheets which have the right text in them
- *
- * @author Nick Burch (nick at torchbox dot com)
*/
-public final class TestNotesText extends TestCase {
+public final class TestNotesText {
// SlideShow primed on the test data
- private final HSLFSlideShow ss;
+ private HSLFSlideShow ss;
- public TestNotesText() throws Exception {
- POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
+ @Before
+ public void setup() throws Exception {
+ POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
HSLFSlideShowImpl hss = new HSLFSlideShowImpl(slTests.openResourceAsStream("basic_test_ppt_file.ppt"));
ss = new HSLFSlideShow(hss);
}
+ @Test
public void testNotesOne() {
HSLFNotes notes = ss.getNotes().get(0);
-
- String[] expectText = new String[] {"These are the notes for page 1"};
- assertEquals(expectText.length, notes.getTextParagraphs().size());
- for(int i=0; i<expectText.length; i++) {
- assertEquals(expectText[i], HSLFTextParagraph.getRawText(notes.getTextParagraphs().get(i)));
- }
+ String[] expectText = {"These are the notes for page 1"};
+ assertArrayEquals(expectText, toStrings(notes));
}
+ @Test
public void testNotesTwo() {
HSLFNotes notes = ss.getNotes().get(1);
- String[] expectText = new String[] {"These are the notes on page two, again lacking formatting"};
- assertEquals(expectText.length, notes.getTextParagraphs().size());
- for(int i=0; i<expectText.length; i++) {
- assertEquals(expectText[i], HSLFTextParagraph.getRawText(notes.getTextParagraphs().get(i)));
- }
+ String[] expectText = {"These are the notes on page two, again lacking formatting"};
+ assertArrayEquals(expectText, toStrings(notes));
+ }
+
+ private static String[] toStrings(HSLFNotes notes) {
+ return notes.getTextParagraphs().stream().map(HSLFTextParagraph::getRawText).toArray(String[]::new);
}
}
diff --git a/src/scratchpad/testcases/org/apache/poi/hsmf/Test7BitCodepage.java b/src/scratchpad/testcases/org/apache/poi/hsmf/Test7BitCodepage.java
index 0ec5eb7b56..6bc9e3530a 100644
--- a/src/scratchpad/testcases/org/apache/poi/hsmf/Test7BitCodepage.java
+++ b/src/scratchpad/testcases/org/apache/poi/hsmf/Test7BitCodepage.java
@@ -17,28 +17,31 @@
package org.apache.poi.hsmf;
-import java.io.IOException;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
-import junit.framework.TestCase;
+import java.io.IOException;
import org.apache.poi.POIDataSamples;
+import org.junit.Before;
+import org.junit.Test;
/**
* Tests to verify if code page for general properties like subject,
* text body and html body is evaluated correctly.
*/
-public final class Test7BitCodepage extends TestCase {
- private final MAPIMessage ascii_cp1251_lcid1049;
- private final MAPIMessage ascii_utf_8_cp1252_lcid1031;
- private final MAPIMessage ascii_utf_8_cp1252_lcid1031_html;
- private final MAPIMessage htmlbodybinary_cp1251;
- private final MAPIMessage htmlbodybinary_utf_8;
+public final class Test7BitCodepage {
+ private MAPIMessage ascii_cp1251_lcid1049;
+ private MAPIMessage ascii_utf_8_cp1252_lcid1031;
+ private MAPIMessage ascii_utf_8_cp1252_lcid1031_html;
+ private MAPIMessage htmlbodybinary_cp1251;
+ private MAPIMessage htmlbodybinary_utf_8;
/**
* Initialize this test, load up the messages.
- * @throws Exception
*/
- public Test7BitCodepage() throws IOException {
+ @Before
+ public void setup() throws IOException {
POIDataSamples samples = POIDataSamples.getHSMFInstance();
ascii_cp1251_lcid1049 = new MAPIMessage(samples.openResourceAsStream("ASCII_CP1251_LCID1049.msg"));
ascii_utf_8_cp1252_lcid1031 = new MAPIMessage(samples.openResourceAsStream("ASCII_UTF-8_CP1252_LCID1031.msg"));
@@ -50,6 +53,7 @@ public final class Test7BitCodepage extends TestCase {
/**
* Evaluate encoding and check if the subject, text body and html body is decoded correctly.
*/
+ @Test
public void test7BitEncoding() throws Exception {
ascii_cp1251_lcid1049.guess7BitEncoding();
ascii_cp1251_lcid1049.setReturnNullOnMissingChunk(true);
@@ -61,23 +65,23 @@ public final class Test7BitCodepage extends TestCase {
htmlbodybinary_cp1251.setReturnNullOnMissingChunk(true);
htmlbodybinary_utf_8.guess7BitEncoding();
htmlbodybinary_utf_8.setReturnNullOnMissingChunk(true);
-
+
assertEquals("Subject автоматически Subject", ascii_cp1251_lcid1049.getSubject());
assertEquals("Body автоматически Body", ascii_cp1251_lcid1049.getTextBody());
assertEquals("<!DOCTYPE html><html><meta charset=\\\"windows-1251\\\"><body>HTML автоматически</body></html>", ascii_cp1251_lcid1049.getHtmlBody());
-
+
assertEquals("Subject öäü Subject", ascii_utf_8_cp1252_lcid1031.getSubject());
assertEquals("Body öäü Body", ascii_utf_8_cp1252_lcid1031.getTextBody());
assertNull(ascii_utf_8_cp1252_lcid1031.getHtmlBody());
-
+
assertEquals("Subject öäü Subject", ascii_utf_8_cp1252_lcid1031_html.getSubject());
assertEquals("Body öäü Body", ascii_utf_8_cp1252_lcid1031_html.getTextBody());
assertEquals("<!DOCTYPE html><html><meta charset=\\\"utf-8\\\"><body>HTML öäü</body></html>", ascii_utf_8_cp1252_lcid1031_html.getHtmlBody());
-
+
assertEquals("Subject öäü Subject", htmlbodybinary_cp1251.getSubject());
assertNull(htmlbodybinary_cp1251.getTextBody());
assertEquals("<!DOCTYPE html><html><meta charset=\\\"utf-8\\\"><body>HTML автоматически</body></html>", htmlbodybinary_cp1251.getHtmlBody());
-
+
assertEquals("Subject öäü Subject", htmlbodybinary_utf_8.getSubject());
assertNull(htmlbodybinary_utf_8.getTextBody());
assertEquals("<!DOCTYPE html><html><meta charset=\\\"utf-8\\\"><body>HTML öäü</body></html>", htmlbodybinary_utf_8.getHtmlBody());
diff --git a/src/scratchpad/testcases/org/apache/poi/hsmf/TestBasics.java b/src/scratchpad/testcases/org/apache/poi/hsmf/TestBasics.java
index 860f1f5e6c..ffeab21c8c 100644
--- a/src/scratchpad/testcases/org/apache/poi/hsmf/TestBasics.java
+++ b/src/scratchpad/testcases/org/apache/poi/hsmf/TestBasics.java
@@ -19,34 +19,38 @@ package org.apache.poi.hsmf;
import static org.apache.poi.POITestCase.assertContains;
import static org.apache.poi.POITestCase.assertStartsWith;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.io.IOException;
-import junit.framework.TestCase;
-
import org.apache.poi.POIDataSamples;
import org.apache.poi.hsmf.exceptions.ChunkNotFoundException;
+import org.junit.Before;
+import org.junit.Test;
/**
- * Tests to verify that we can perform basic opperations on
+ * Tests to verify that we can perform basic opperations on
* a range of files
*/
-public final class TestBasics extends TestCase {
- private final MAPIMessage simple;
- private final MAPIMessage quick;
- private final MAPIMessage outlook30;
- private final MAPIMessage attachments;
- private final MAPIMessage noRecipientAddress;
- private final MAPIMessage unicode;
- private final MAPIMessage cyrillic;
- private final MAPIMessage chinese;
+public final class TestBasics {
+ private MAPIMessage simple;
+ private MAPIMessage quick;
+ private MAPIMessage outlook30;
+ private MAPIMessage attachments;
+ private MAPIMessage noRecipientAddress;
+ private MAPIMessage unicode;
+ private MAPIMessage cyrillic;
+ private MAPIMessage chinese;
/**
* Initialize this test, load up the blank.msg mapi message.
- * @throws Exception
*/
- public TestBasics() throws IOException {
+ @Before
+ public void setup() throws IOException {
POIDataSamples samples = POIDataSamples.getHSMFInstance();
simple = new MAPIMessage(samples.openResourceAsStream("simple_test_msg.msg"));
quick = new MAPIMessage(samples.openResourceAsStream("quick.msg"));
@@ -61,18 +65,19 @@ public final class TestBasics extends TestCase {
/**
* Can we always get the recipient's email?
*/
+ @Test
public void testRecipientEmail() throws Exception {
assertEquals("travis@overwrittenstack.com", simple.getRecipientEmailAddress());
assertEquals("kevin.roast@alfresco.org", quick.getRecipientEmailAddress());
assertEquals("nicolas1.23456@free.fr", attachments.getRecipientEmailAddress());
-
+
// This one has lots...
assertEquals(18, outlook30.getRecipientEmailAddressList().length);
assertEquals("shawn.bohn@pnl.gov; gus.calapristi@pnl.gov; Richard.Carter@pnl.gov; " +
"barb.cheney@pnl.gov; nick.cramer@pnl.gov; vern.crow@pnl.gov; Laura.Curtis@pnl.gov; " +
"julie.dunkle@pnl.gov; david.gillen@pnl.gov; michelle@pnl.gov; Jereme.Haack@pnl.gov; " +
"Michelle.Hart@pnl.gov; ranata.johnson@pnl.gov; grant.nakamura@pnl.gov; " +
- "debbie.payne@pnl.gov; stuart.rose@pnl.gov; randall.scarberry@pnl.gov; Leigh.Williams@pnl.gov",
+ "debbie.payne@pnl.gov; stuart.rose@pnl.gov; randall.scarberry@pnl.gov; Leigh.Williams@pnl.gov",
outlook30.getRecipientEmailAddress()
);
}
@@ -80,6 +85,7 @@ public final class TestBasics extends TestCase {
/**
* Test subject
*/
+ @Test
public void testSubject() throws Exception {
assertEquals("test message", simple.getSubject());
assertEquals("Test the content transformer", quick.getSubject());
@@ -90,25 +96,26 @@ public final class TestBasics extends TestCase {
/**
* Test message headers
*/
+ @Test
public void testHeaders() throws Exception {
// Simple email first
assertEquals(26, simple.getHeaders().length);
assertStartsWith(simple.getHeaders()[0], "Return-path:");
assertEquals("Envelope-to: travis@overwrittenstack.com", simple.getHeaders()[1]);
assertStartsWith(simple.getHeaders()[25], "X-Antivirus-Scanner: Clean");
-
+
// Quick doesn't have them
try {
quick.getHeaders();
fail("expected ChunkNotFoundException");
} catch(ChunkNotFoundException e) {}
-
+
// Attachments doesn't have them
try {
attachments.getHeaders();
fail("expected ChunkNotFoundException");
} catch(ChunkNotFoundException e) {}
-
+
// Outlook30 has some
assertEquals(33, outlook30.getHeaders().length);
assertStartsWith(outlook30.getHeaders()[0], "Microsoft Mail Internet Headers");
@@ -116,6 +123,7 @@ public final class TestBasics extends TestCase {
assertStartsWith(outlook30.getHeaders()[32], "\t\"Williams"); // May need better parsing in future
}
+ @Test
public void testBody() throws Exception {
// Messages may have their bodies saved as plain text, html, and/or rtf.
assertEquals("This is a test message.", simple.getTextBody());
@@ -123,17 +131,17 @@ public final class TestBasics extends TestCase {
assertStartsWith(outlook30.getTextBody(), "I am shutting down the IN-SPIRE servers now for 30ish minutes.\r\n\r\n");
assertStartsWith(attachments.getTextBody(), "contenu\r\n\r\n");
assertStartsWith(unicode.getTextBody(), "..less you are Nick.....");
-
+
// outlook30 has chunks for all 3 body formats
// Examine one of the paragraphs is present in all 3 formats, surrounded by markup tags
String text = "I am shutting down the IN-SPIRE servers now for 30ish minutes.";
assertStartsWith(outlook30.getTextBody(), text + "\r\n\r\n");
assertEquals(850494485, outlook30.getTextBody().hashCode());
-
+
assertStartsWith(outlook30.getHtmlBody(), "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 3.2//EN\">\r\n<HTML>\r\n<HEAD>");
assertContains(outlook30.getHtmlBody(), "<P DIR=LTR><SPAN LANG=\"en-us\"><FONT FACE=\"Calibri\">" + text + "</FONT></SPAN></P>");
assertEquals(-654938715, outlook30.getHtmlBody().hashCode());
-
+
assertStartsWith(outlook30.getRtfBody(), "{\\rtf1\\adeflang1025\\ansi\\ansicpg1252\\uc1\\adeff3150");
assertContains(outlook30.getRtfBody(), "{\\rtlch\\fcs1 \\af31507 \\ltrch\\fcs0 \\cf0\\insrsid5003910 " + text + "\r\n\\par \r\n\\par");
assertEquals(891652290, outlook30.getRtfBody().hashCode());
@@ -142,7 +150,8 @@ public final class TestBasics extends TestCase {
/**
* Test attachments
*/
- public void testAttachments() throws Exception {
+ @Test
+ public void testAttachments() {
assertEquals(0, simple.getAttachmentFiles().length);
assertEquals(0, quick.getAttachmentFiles().length);
assertEquals(0, outlook30.getAttachmentFiles().length);
@@ -153,6 +162,7 @@ public final class TestBasics extends TestCase {
* Test missing chunks.
* Use a file with no HTML body
*/
+ @Test
public void testMissingChunks() throws Exception {
assertFalse(attachments.isReturnNullOnMissingChunk());
@@ -166,9 +176,9 @@ public final class TestBasics extends TestCase {
attachments.setReturnNullOnMissingChunk(true);
assertNull(attachments.getHtmlBody());
-
+
attachments.setReturnNullOnMissingChunk(false);
-
+
try {
attachments.getHtmlBody();
fail("expected ChunkNotFoundException");
@@ -181,6 +191,7 @@ public final class TestBasics extends TestCase {
* More missing chunk testing, this time for
* missing recipient email address
*/
+ @Test
public void testMissingAddressChunk() throws Exception {
assertFalse(noRecipientAddress.isReturnNullOnMissingChunk());
@@ -196,66 +207,68 @@ public final class TestBasics extends TestCase {
} catch(ChunkNotFoundException e) {
// Good
}
-
+
noRecipientAddress.setReturnNullOnMissingChunk(true);
-
+
noRecipientAddress.getRecipientEmailAddress();
noRecipientAddress.getRecipientEmailAddressList();
assertEquals("", noRecipientAddress.getRecipientEmailAddress());
assertEquals(1, noRecipientAddress.getRecipientEmailAddressList().length);
assertNull(noRecipientAddress.getRecipientEmailAddressList()[0]);
-
+
// Check a few other bits too
assertEquals("Microsoft Outlook 2003 Team", noRecipientAddress.getDisplayFrom());
assertEquals("New Outlook User", noRecipientAddress.getDisplayTo());
-
+
noRecipientAddress.setReturnNullOnMissingChunk(false);
}
/**
* Test the 7 bit detection
*/
- public void test7BitDetection() throws Exception {
+ @Test
+ public void test7BitDetection() {
assertFalse(unicode.has7BitEncodingStrings());
assertTrue(simple.has7BitEncodingStrings());
assertTrue(chinese.has7BitEncodingStrings());
assertTrue(cyrillic.has7BitEncodingStrings());
}
-
+
/**
* We default to CP1252, but can sometimes do better
* if needed.
* This file is really CP1251, according to the person
* who submitted it in bug #49441
*/
+ @Test
public void testEncoding() throws Exception {
assertEquals(2, cyrillic.getRecipientDetailsChunks().length);
assertEquals("CP1252", cyrillic.getRecipientDetailsChunks()[0].recipientDisplayNameChunk.get7BitEncoding());
assertEquals("CP1252", cyrillic.getRecipientDetailsChunks()[1].recipientDisplayNameChunk.get7BitEncoding());
-
+
cyrillic.guess7BitEncoding();
-
+
assertEquals("Cp1251", cyrillic.getRecipientDetailsChunks()[0].recipientDisplayNameChunk.get7BitEncoding());
assertEquals("Cp1251", cyrillic.getRecipientDetailsChunks()[1].recipientDisplayNameChunk.get7BitEncoding());
-
+
// Override it, check it's taken
cyrillic.set7BitEncoding("UTF-8");
assertEquals("UTF-8", cyrillic.getRecipientDetailsChunks()[0].recipientDisplayNameChunk.get7BitEncoding());
assertEquals("UTF-8", cyrillic.getRecipientDetailsChunks()[1].recipientDisplayNameChunk.get7BitEncoding());
-
-
+
+
// Check with a file that has no headers
try {
chinese.getHeaders();
fail("File doesn't have headers!");
} catch(ChunkNotFoundException e) {}
-
+
String html = chinese.getHtmlBody();
assertTrue("Charset not found:\n" + html, html.contains("text/html; charset=big5"));
-
+
// Defaults to CP1251
assertEquals("CP1252", chinese.getRecipientDetailsChunks()[0].recipientDisplayNameChunk.get7BitEncoding());
-
+
// But after guessing goes to the correct one, cp950 (Windows Traditional Chinese)
chinese.guess7BitEncoding();
assertEquals("cp950", chinese.getRecipientDetailsChunks()[0].recipientDisplayNameChunk.get7BitEncoding());
diff --git a/src/scratchpad/testcases/org/apache/poi/hsmf/TestBlankFileRead.java b/src/scratchpad/testcases/org/apache/poi/hsmf/TestBlankFileRead.java
index 0a9a7af8ed..256ed5ced3 100644
--- a/src/scratchpad/testcases/org/apache/poi/hsmf/TestBlankFileRead.java
+++ b/src/scratchpad/testcases/org/apache/poi/hsmf/TestBlankFileRead.java
@@ -17,104 +17,97 @@
package org.apache.poi.hsmf;
+import static org.junit.Assert.assertEquals;
+
import java.io.IOException;
-import org.apache.poi.hsmf.exceptions.ChunkNotFoundException;
import org.apache.poi.POIDataSamples;
-
-import junit.framework.TestCase;
+import org.apache.poi.hsmf.exceptions.ChunkNotFoundException;
+import org.junit.Before;
+import org.junit.Test;
/**
* Tests to verify that the library can read blank msg files.
*/
-public final class TestBlankFileRead extends TestCase {
- private final MAPIMessage mapiMessage;
+public final class TestBlankFileRead {
+ private MAPIMessage mapiMessage;
/**
* Initialize this test, load up the blank.msg mapi message.
*/
- public TestBlankFileRead() throws IOException {
+ @Before
+ public void setup() throws IOException {
POIDataSamples samples = POIDataSamples.getHSMFInstance();
- this.mapiMessage = new MAPIMessage(samples.openResourceAsStream("blank.msg"));
+ mapiMessage = new MAPIMessage(samples.openResourceAsStream("blank.msg"));
}
/**
* Check if we can read the body of the blank message, we expect "".
*/
- public void testReadBody() {
- try {
- mapiMessage.getTextBody();
- } catch(ChunkNotFoundException exp) {
- return;
- }
-
- TestCase.fail("Should have thrown a ChunkNotFoundException but didn't");
+ @Test(expected = ChunkNotFoundException.class)
+ public void testReadBody() throws ChunkNotFoundException {
+ mapiMessage.getTextBody();
}
/**
* Test to see if we can read the CC Chunk.
*/
+ @Test
public void testReadDisplayCC() throws ChunkNotFoundException {
String obtained = mapiMessage.getDisplayCC();
String expected = "";
- TestCase.assertEquals(expected, obtained);
+ assertEquals(expected, obtained);
}
/**
* Test to see if we can read the CC Chunk.
*/
+ @Test
public void testReadDisplayTo() throws ChunkNotFoundException {
String obtained = mapiMessage.getDisplayTo();
String expected = "";
- TestCase.assertEquals(expected, obtained);
+ assertEquals(expected, obtained);
}
/**
* Test to see if we can read the FROM Chunk.
*/
- public void testReadDisplayFrom() {
- try {
- mapiMessage.getDisplayFrom();
- } catch(ChunkNotFoundException exp) {
- return;
- }
-
- TestCase.fail("Should have thrown a ChunkNotFoundException but didn't");
+ @Test(expected = ChunkNotFoundException.class)
+ public void testReadDisplayFrom() throws ChunkNotFoundException {
+ mapiMessage.getDisplayFrom();
}
/**
* Test to see if we can read the CC Chunk.
*/
+ @Test
public void testReadDisplayBCC() throws ChunkNotFoundException {
String obtained = mapiMessage.getDisplayBCC();
String expected = "";
- TestCase.assertEquals(expected, obtained);
+ assertEquals(expected, obtained);
}
/**
* Check if we can read the subject line of the blank message, we expect ""
*/
+ @Test
public void testReadSubject() throws Exception {
String obtained = mapiMessage.getSubject();
- TestCase.assertEquals("", obtained);
+ assertEquals("", obtained);
}
/**
* Check if we can read the subject line of the blank message, we expect ""
*/
- public void testReadConversationTopic() {
- try {
- mapiMessage.getConversationTopic();
- } catch(ChunkNotFoundException exp) {
- return;
- }
- TestCase.fail("We shouldn't have a ConversationTopic node on the blank.msg file.");
+ @Test(expected = ChunkNotFoundException.class)
+ public void testReadConversationTopic() throws ChunkNotFoundException {
+ mapiMessage.getConversationTopic();
}
}
diff --git a/src/scratchpad/testcases/org/apache/poi/hsmf/TestMessageSubmissionChunk.java b/src/scratchpad/testcases/org/apache/poi/hsmf/TestMessageSubmissionChunk.java
index fc218b9125..e82f0b5dd0 100644
--- a/src/scratchpad/testcases/org/apache/poi/hsmf/TestMessageSubmissionChunk.java
+++ b/src/scratchpad/testcases/org/apache/poi/hsmf/TestMessageSubmissionChunk.java
@@ -17,41 +17,45 @@
package org.apache.poi.hsmf;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
import java.io.IOException;
+import java.util.Calendar;
-import org.apache.poi.hsmf.exceptions.ChunkNotFoundException;
import org.apache.poi.POIDataSamples;
+import org.apache.poi.hsmf.exceptions.ChunkNotFoundException;
+import org.junit.Before;
+import org.junit.Test;
-import java.util.Calendar;
-
-import junit.framework.TestCase;
+public final class TestMessageSubmissionChunk {
-public final class TestMessageSubmissionChunk extends TestCase {
-
- private final MAPIMessage mapiMessageExtraHyphenSubmissionChunk;
- private final MAPIMessage mapiMessageNormalSubmissionChunk;
+ private MAPIMessage mapiMessageExtraHyphenSubmissionChunk;
+ private MAPIMessage mapiMessageNormalSubmissionChunk;
/**
* Initialise this test, load up the test messages.
- * @throws Exception
*/
- public TestMessageSubmissionChunk() throws IOException {
+ @Before
+ public void setup() throws IOException {
POIDataSamples samples = POIDataSamples.getHSMFInstance();
this.mapiMessageExtraHyphenSubmissionChunk = new MAPIMessage(samples.openResourceAsStream("message_extra_hyphen_submission_chunk.msg"));
this.mapiMessageNormalSubmissionChunk = new MAPIMessage(samples.openResourceAsStream("message_normal_submission_chunk.msg"));
}
+ @Test
public void testReadMessageDateExtraHyphenSubmissionChunk() throws ChunkNotFoundException {
final Calendar date = mapiMessageExtraHyphenSubmissionChunk.getMessageDate();
- TestCase.assertNotNull(date);
+ assertNotNull(date);
final int year = date.get(Calendar.YEAR);
- TestCase.assertEquals(2007, year);
+ assertEquals(2007, year);
}
+ @Test
public void testReadMessageDateNormalSubmissionChunk() throws ChunkNotFoundException {
final Calendar date = mapiMessageNormalSubmissionChunk.getMessageDate();
- TestCase.assertNotNull(date);
+ assertNotNull(date);
final int year = date.get(Calendar.YEAR);
- TestCase.assertEquals(2007, year);
+ assertEquals(2007, year);
}
}
diff --git a/src/scratchpad/testcases/org/apache/poi/hsmf/TestMessageSubmissionChunkY2KRead.java b/src/scratchpad/testcases/org/apache/poi/hsmf/TestMessageSubmissionChunkY2KRead.java
index 410356b290..bec75504c1 100644
--- a/src/scratchpad/testcases/org/apache/poi/hsmf/TestMessageSubmissionChunkY2KRead.java
+++ b/src/scratchpad/testcases/org/apache/poi/hsmf/TestMessageSubmissionChunkY2KRead.java
@@ -17,50 +17,54 @@
package org.apache.poi.hsmf;
+import static org.junit.Assert.assertEquals;
+
import java.io.IOException;
+import java.util.Calendar;
-import org.apache.poi.hsmf.exceptions.ChunkNotFoundException;
import org.apache.poi.POIDataSamples;
+import org.apache.poi.hsmf.exceptions.ChunkNotFoundException;
+import org.junit.Before;
+import org.junit.Test;
-import java.util.Calendar;
-
-import junit.framework.TestCase;
+public final class TestMessageSubmissionChunkY2KRead {
-public final class TestMessageSubmissionChunkY2KRead extends TestCase {
-
- private final MAPIMessage mapiMessage1979;
- private final MAPIMessage mapiMessage1980;
- private final MAPIMessage mapiMessage1981;
+ private MAPIMessage mapiMessage1979;
+ private MAPIMessage mapiMessage1980;
+ private MAPIMessage mapiMessage1981;
/**
* Initialise this test, load up the three test messages.
- * @throws Exception
*/
- public TestMessageSubmissionChunkY2KRead() throws IOException {
+ @Before
+ public void setup() throws IOException {
POIDataSamples samples = POIDataSamples.getHSMFInstance();
- this.mapiMessage1979 = new MAPIMessage(samples.openResourceAsStream("message_1979.msg"));
- this.mapiMessage1980 = new MAPIMessage(samples.openResourceAsStream("message_1980.msg"));
- this.mapiMessage1981 = new MAPIMessage(samples.openResourceAsStream("message_1981.msg"));
+ mapiMessage1979 = new MAPIMessage(samples.openResourceAsStream("message_1979.msg"));
+ mapiMessage1980 = new MAPIMessage(samples.openResourceAsStream("message_1980.msg"));
+ mapiMessage1981 = new MAPIMessage(samples.openResourceAsStream("message_1981.msg"));
}
// 1979 is one year before our pivot year (so this is an expected "failure")
+ @Test
public void testReadMessageDate1979() throws ChunkNotFoundException {
final Calendar date = mapiMessage1979.getMessageDate();
final int year = date.get(Calendar.YEAR);
- TestCase.assertEquals(2079, year);
+ assertEquals(2079, year);
}
// 1980 is our pivot year (so this is an expected "failure")
+ @Test
public void testReadMessageDate1980() throws ChunkNotFoundException {
final Calendar date = mapiMessage1980.getMessageDate();
final int year = date.get(Calendar.YEAR);
- TestCase.assertEquals(2080, year);
+ assertEquals(2080, year);
}
// 1981 is one year after our pivot year (so this starts working)
+ @Test
public void testReadMessageDate1981() throws ChunkNotFoundException {
final Calendar date = mapiMessage1981.getMessageDate();
final int year = date.get(Calendar.YEAR);
- TestCase.assertEquals(1981, year);
+ assertEquals(1981, year);
}
}
diff --git a/src/scratchpad/testcases/org/apache/poi/hsmf/TestOutlook30FileRead.java b/src/scratchpad/testcases/org/apache/poi/hsmf/TestOutlook30FileRead.java
index 126a265ab4..ce8527f665 100644
--- a/src/scratchpad/testcases/org/apache/poi/hsmf/TestOutlook30FileRead.java
+++ b/src/scratchpad/testcases/org/apache/poi/hsmf/TestOutlook30FileRead.java
@@ -17,45 +17,47 @@
package org.apache.poi.hsmf;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
import java.io.IOException;
-import org.apache.poi.hsmf.exceptions.ChunkNotFoundException;
import org.apache.poi.POIDataSamples;
-
-import junit.framework.TestCase;
+import org.apache.poi.hsmf.exceptions.ChunkNotFoundException;
+import org.junit.Before;
+import org.junit.Test;
/**
* Tests to verify that we can still work on the newer Outlook 3.0 files.
*/
-public final class TestOutlook30FileRead extends TestCase {
- private final MAPIMessage mapiMessage;
+public final class TestOutlook30FileRead {
+ private MAPIMessage mapiMessage;
/**
* Initialize this test, load up the blank.msg mapi message.
- * @throws Exception
*/
- public TestOutlook30FileRead() throws IOException {
+ @Before
+ public void setup() throws IOException {
POIDataSamples samples = POIDataSamples.getHSMFInstance();
this.mapiMessage = new MAPIMessage(samples.openResourceAsStream("outlook_30_msg.msg"));
}
/**
* Test to see if we can read the CC Chunk.
- * @throws ChunkNotFoundException
- *
*/
+ @Test
public void testReadDisplayCC() throws ChunkNotFoundException {
String obtained = mapiMessage.getDisplayCC();
String expected = "";
- TestCase.assertEquals(obtained, expected);
+ assertEquals(obtained, expected);
}
/**
* Test to see if we can read the CC Chunk.
- * @throws ChunkNotFoundException
- *
*/
+ @Test
public void testReadDisplayTo() throws ChunkNotFoundException {
String obtained = mapiMessage.getDisplayTo();
@@ -64,34 +66,31 @@ public final class TestOutlook30FileRead extends TestCase {
/**
* Test to see if we can read the From Chunk.
- * @throws ChunkNotFoundException
- *
*/
+ @Test
public void testReadDisplayFrom() throws ChunkNotFoundException {
String obtained = mapiMessage.getDisplayFrom();
String expected = "Cramer, Nick";
- TestCase.assertEquals(obtained, expected);
+ assertEquals(obtained, expected);
}
/**
* Test to see if we can read the CC Chunk.
- * @throws ChunkNotFoundException
- *
*/
+ @Test
public void testReadDisplayBCC() throws ChunkNotFoundException {
String obtained = mapiMessage.getDisplayBCC();
String expected = "";
- TestCase.assertEquals(obtained, expected);
+ assertEquals(obtained, expected);
}
/**
* Check if we can read the body of the blank message, we expect "".
- *
- * @throws Exception
*/
+ @Test
public void testReadBody() throws Exception {
String obtained = mapiMessage.getTextBody();
assertTrue(obtained.startsWith("I am shutting down"));
@@ -99,39 +98,37 @@ public final class TestOutlook30FileRead extends TestCase {
/**
* Check if we can read the subject line of the blank message, we expect ""
- *
- * @throws Exception
*/
+ @Test
public void testReadSubject() throws Exception {
String obtained = mapiMessage.getSubject();
String expected = "IN-SPIRE servers going down for a bit, back up around 8am";
- TestCase.assertEquals(expected, obtained);
+ assertEquals(expected, obtained);
}
/**
* Check if we can read the subject line of the blank message, we expect ""
- *
- * @throws Exception
*/
+ @Test
public void testReadConversationTopic() throws Exception {
String obtained = mapiMessage.getConversationTopic();
- TestCase.assertEquals("IN-SPIRE servers going down for a bit, back up around 8am", obtained);
+ assertEquals("IN-SPIRE servers going down for a bit, back up around 8am", obtained);
}
/**
* Check if we can read the subject line of the blank message, we expect ""
- *
- * @throws Exception
*/
+ @Test
public void testReadMessageClass() throws Exception {
MAPIMessage.MESSAGE_CLASS obtained = mapiMessage.getMessageClassEnum();
- TestCase.assertEquals(MAPIMessage.MESSAGE_CLASS.NOTE, obtained);
+ assertEquals(MAPIMessage.MESSAGE_CLASS.NOTE, obtained);
}
/**
* Ensure we can get the HTML and RTF versions
*/
+ @Test
public void testReadBodyContents() throws Exception {
String html = mapiMessage.getHtmlBody();
String rtf = mapiMessage.getRtfBody();
diff --git a/src/scratchpad/testcases/org/apache/poi/hsmf/TestSimpleFileRead.java b/src/scratchpad/testcases/org/apache/poi/hsmf/TestSimpleFileRead.java
index a0a1bc731f..314fe14ab4 100644
--- a/src/scratchpad/testcases/org/apache/poi/hsmf/TestSimpleFileRead.java
+++ b/src/scratchpad/testcases/org/apache/poi/hsmf/TestSimpleFileRead.java
@@ -17,15 +17,15 @@
package org.apache.poi.hsmf;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
import java.io.IOException;
-import junit.framework.TestCase;
import org.apache.poi.POIDataSamples;
import org.apache.poi.hsmf.exceptions.ChunkNotFoundException;
import org.junit.Test;
-import static org.junit.Assert.assertTrue;
-
/**
* Tests to verify that we can read a simple msg file, that is in plain/text
* format with no attachments or extra recipents.
@@ -50,7 +50,7 @@ public final class TestSimpleFileRead {
String obtained = mapiMessage.getDisplayCC();
String expected = "";
- TestCase.assertEquals(obtained, expected);
+ assertEquals(obtained, expected);
}
/**
@@ -61,7 +61,7 @@ public final class TestSimpleFileRead {
String obtained = mapiMessage.getDisplayTo();
String expected = "travis@overwrittenstack.com";
- TestCase.assertEquals(obtained, expected);
+ assertEquals(obtained, expected);
}
/**
@@ -72,7 +72,7 @@ public final class TestSimpleFileRead {
String obtained = mapiMessage.getDisplayFrom();
String expected = "Travis Ferguson";
- TestCase.assertEquals(obtained, expected);
+ assertEquals(obtained, expected);
}
/**
@@ -83,7 +83,7 @@ public final class TestSimpleFileRead {
String obtained = mapiMessage.getDisplayBCC();
String expected = "";
- TestCase.assertEquals(obtained, expected);
+ assertEquals(obtained, expected);
}
@@ -95,7 +95,7 @@ public final class TestSimpleFileRead {
String obtained = mapiMessage.getTextBody();
String expected = "This is a test message.";
- TestCase.assertEquals(obtained, expected);
+ assertEquals(obtained, expected);
}
/**
@@ -106,7 +106,7 @@ public final class TestSimpleFileRead {
String obtained = mapiMessage.getSubject();
String expected = "test message";
- TestCase.assertEquals(expected, obtained);
+ assertEquals(expected, obtained);
}
/**
@@ -115,7 +115,7 @@ public final class TestSimpleFileRead {
@Test
public void testReadConversationTopic() throws Exception {
String obtained = mapiMessage.getConversationTopic();
- TestCase.assertEquals("test message", obtained);
+ assertEquals("test message", obtained);
}
@@ -125,7 +125,7 @@ public final class TestSimpleFileRead {
@Test
public void testReadMessageClass() throws Exception {
MAPIMessage.MESSAGE_CLASS obtained = mapiMessage.getMessageClassEnum();
- TestCase.assertEquals(MAPIMessage.MESSAGE_CLASS.NOTE, obtained);
+ assertEquals(MAPIMessage.MESSAGE_CLASS.NOTE, obtained);
}
/**
@@ -133,7 +133,7 @@ public final class TestSimpleFileRead {
*/
@Test
public void testReadMessageClass2() throws Exception {
- TestCase.assertEquals(
+ assertEquals(
MAPIMessage.MESSAGE_CLASS.NOTE, mapiMessage.getMessageClassEnum());
for (String messageClass : new String[]{
diff --git a/src/scratchpad/testcases/org/apache/poi/hsmf/datatypes/TestChunkData.java b/src/scratchpad/testcases/org/apache/poi/hsmf/datatypes/TestChunkData.java
index ea6f8be81b..cf28fa3210 100644
--- a/src/scratchpad/testcases/org/apache/poi/hsmf/datatypes/TestChunkData.java
+++ b/src/scratchpad/testcases/org/apache/poi/hsmf/datatypes/TestChunkData.java
@@ -17,19 +17,19 @@
package org.apache.poi.hsmf.datatypes;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
/**
* Verifies that the Chunks class is actually setup properly and hasn't been changed in ways
* that will break the library.
- *
- * @author Travis Ferguson
- *
*/
-public final class TestChunkData extends TestCase {
+public final class TestChunkData {
+ @Test
public void testChunkCreate() {
Chunk chunk;
-
+
chunk = new StringChunk(0x0200, Types.createCustom(0x001E));
assertEquals("__substg1.0_0200001E", chunk.getEntryName());
assertEquals(0x0200, chunk.getChunkId());
@@ -39,12 +39,12 @@ public final class TestChunkData extends TestCase {
assertEquals("__substg1.0_0200001E", chunk.getEntryName());
assertEquals(0x0200, chunk.getChunkId());
assertEquals(0x001E, chunk.getType().getId());
-
+
chunk = new StringChunk("__substg1.0_", 0x0200, Types.getById(0x001E));
assertEquals("__substg1.0_0200001E", chunk.getEntryName());
assertEquals(0x0200, chunk.getChunkId());
assertEquals(0x001E, chunk.getType().getId());
-
+
/* test the lower and upper limits of the chunk ids */
chunk = new StringChunk(0x0000, Types.createCustom(0x001E));
assertEquals("__substg1.0_0000001E", chunk.getEntryName());
@@ -56,27 +56,32 @@ public final class TestChunkData extends TestCase {
assertEquals("__substg1.0_FFFF001F", chunk.getEntryName());
}
+ @Test
public void testTextBodyChunk() {
StringChunk chunk = new StringChunk(0x1000, Types.UNICODE_STRING);
assertEquals(chunk.getChunkId(), MAPIProperty.BODY.id);
}
+ @Test
public void testDisplayToChunk() {
StringChunk chunk = new StringChunk(0x0E04, Types.UNICODE_STRING);
assertEquals(chunk.getChunkId(), MAPIProperty.DISPLAY_TO.id);
}
+ @Test
public void testDisplayCCChunk() {
StringChunk chunk = new StringChunk(0x0E03, Types.UNICODE_STRING);
assertEquals(chunk.getChunkId(), MAPIProperty.DISPLAY_CC.id);
}
+ @Test
public void testDisplayBCCChunk() {
StringChunk chunk = new StringChunk(0x0E02, Types.UNICODE_STRING);
assertEquals(chunk.getChunkId(), MAPIProperty.DISPLAY_BCC.id);
}
+ @Test
public void testSubjectChunk() {
Chunk chunk = new StringChunk(0x0037, Types.UNICODE_STRING);
assertEquals(chunk.getChunkId(), MAPIProperty.SUBJECT.id);
diff --git a/src/scratchpad/testcases/org/apache/poi/hsmf/datatypes/TestMAPIProperty.java b/src/scratchpad/testcases/org/apache/poi/hsmf/datatypes/TestMAPIProperty.java
index d44980a960..5229ada289 100644
--- a/src/scratchpad/testcases/org/apache/poi/hsmf/datatypes/TestMAPIProperty.java
+++ b/src/scratchpad/testcases/org/apache/poi/hsmf/datatypes/TestMAPIProperty.java
@@ -17,42 +17,50 @@
package org.apache.poi.hsmf.datatypes;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotSame;
+import static org.junit.Assert.assertTrue;
+
import java.util.Collection;
-import junit.framework.TestCase;
+import org.junit.Test;
/**
* Checks various MAPIProperty related logic
*/
-public final class TestMAPIProperty extends TestCase {
- public void testGet() throws Exception {
+public final class TestMAPIProperty {
+ @Test
+ public void testGet() {
assertEquals(MAPIProperty.DISPLAY_NAME, MAPIProperty.get(MAPIProperty.DISPLAY_NAME.id));
assertEquals(MAPIProperty.DISPLAY_BCC, MAPIProperty.get(MAPIProperty.DISPLAY_BCC.id));
assertNotSame(MAPIProperty.DISPLAY_BCC, MAPIProperty.get(MAPIProperty.DISPLAY_CC.id));
}
-
- public void testGetAll() throws Exception {
+
+ @Test
+ public void testGetAll() {
Collection<MAPIProperty> all = MAPIProperty.getAll();
assertTrue(all.contains(MAPIProperty.DISPLAY_NAME));
assertTrue(all.contains(MAPIProperty.DISPLAY_CC));
-
+
// Won't contain custom
assertFalse(all.contains(MAPIProperty.createCustom(1, Types.UNSPECIFIED, "")));
-
+
// Won't contain unknown
assertFalse(all.contains(MAPIProperty.UNKNOWN));
}
-
- public void testCustom() throws Exception {
+
+ @Test
+ public void testCustom() {
MAPIProperty c1 = MAPIProperty.createCustom(1, Types.UNSPECIFIED, "");
MAPIProperty c2a = MAPIProperty.createCustom(2, Types.UNSPECIFIED, "2");
MAPIProperty c2b = MAPIProperty.createCustom(2, Types.UNSPECIFIED, "2");
-
+
// New object each time
assertNotSame(c1, c2a);
assertNotSame(c1, c2b);
assertNotSame(c2a, c2b);
-
+
// Won't be in all list
Collection<MAPIProperty> all = MAPIProperty.getAll();
assertFalse(all.contains(c1));
diff --git a/src/scratchpad/testcases/org/apache/poi/hsmf/datatypes/TestSorters.java b/src/scratchpad/testcases/org/apache/poi/hsmf/datatypes/TestSorters.java
index 815fb2d661..d1d2032069 100644
--- a/src/scratchpad/testcases/org/apache/poi/hsmf/datatypes/TestSorters.java
+++ b/src/scratchpad/testcases/org/apache/poi/hsmf/datatypes/TestSorters.java
@@ -17,21 +17,22 @@
package org.apache.poi.hsmf.datatypes;
+import static org.junit.Assert.assertEquals;
+
import java.util.Arrays;
import org.apache.poi.hsmf.datatypes.AttachmentChunks.AttachmentChunksSorter;
import org.apache.poi.hsmf.datatypes.RecipientChunks.RecipientChunksSorter;
-
-import junit.framework.TestCase;
+import org.junit.Test;
/**
- * Checks that the sorters on the chunk groups order
- * chunks properly.
+ * Checks that the sorters on the chunk groups order chunks properly.
*/
-public final class TestSorters extends TestCase {
+public final class TestSorters {
+ @Test
public void testAttachmentChunksSorter() {
AttachmentChunks[] chunks;
-
+
// Simple
chunks = new AttachmentChunks[] {
new AttachmentChunks("__attach_version1.0_#00000001"),
@@ -40,7 +41,7 @@ public final class TestSorters extends TestCase {
Arrays.sort(chunks, new AttachmentChunksSorter());
assertEquals("__attach_version1.0_#00000000", chunks[0].getPOIFSName());
assertEquals("__attach_version1.0_#00000001", chunks[1].getPOIFSName());
-
+
// Lots, with gaps
chunks = new AttachmentChunks[] {
new AttachmentChunks("__attach_version1.0_#00000101"),
@@ -60,10 +61,11 @@ public final class TestSorters extends TestCase {
assertEquals("__attach_version1.0_#000000AB", chunks[5].getPOIFSName());
assertEquals("__attach_version1.0_#00000101", chunks[6].getPOIFSName());
}
-
+
+ @Test
public void testRecipientChunksSorter() {
RecipientChunks[] chunks;
-
+
// Simple
chunks = new RecipientChunks[] {
new RecipientChunks("__recip_version1.0_#00000001"),
@@ -72,7 +74,7 @@ public final class TestSorters extends TestCase {
Arrays.sort(chunks, new RecipientChunksSorter());
assertEquals(0, chunks[0].recipientNumber);
assertEquals(1, chunks[1].recipientNumber);
-
+
// Lots, with gaps
chunks = new RecipientChunks[] {
new RecipientChunks("__recip_version1.0_#00020001"),
diff --git a/src/scratchpad/testcases/org/apache/poi/hsmf/datatypes/TestTypes.java b/src/scratchpad/testcases/org/apache/poi/hsmf/datatypes/TestTypes.java
index 305de74a8d..381584e8ea 100644
--- a/src/scratchpad/testcases/org/apache/poi/hsmf/datatypes/TestTypes.java
+++ b/src/scratchpad/testcases/org/apache/poi/hsmf/datatypes/TestTypes.java
@@ -17,39 +17,44 @@
package org.apache.poi.hsmf.datatypes;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
/**
* Verifies that the Types class is behaving properly.
* Also check that no changes have been made that will
* break the library.
*/
-public final class TestTypes extends TestCase {
+public final class TestTypes {
+ @Test
public void testTypeIds() {
assertEquals(0x1e, Types.ASCII_STRING.getId());
assertEquals(0x1f, Types.UNICODE_STRING.getId());
-
+
assertEquals(0x0102, Types.BINARY.getId());
assertEquals(0x000B, Types.BOOLEAN.getId());
assertEquals(0x0003, Types.LONG.getId());
assertEquals(0x0040, Types.TIME.getId());
-
+
assertEquals(Types.ASCII_STRING, Types.getById(0x1e));
assertEquals(Types.UNICODE_STRING, Types.getById(0x1f));
-
+
assertEquals(Types.BINARY, Types.getById(0x0102));
assertEquals(Types.BOOLEAN, Types.getById(0x000B));
assertEquals(Types.LONG, Types.getById(0x0003));
assertEquals(Types.TIME, Types.getById(0x0040));
}
-
+
+ @Test
public void testTypeFormatting() {
assertEquals("0000", Types.asFileEnding(0x0000));
assertEquals("0020", Types.asFileEnding(0x0020));
assertEquals("0102", Types.asFileEnding(0x0102));
assertEquals("FEDC", Types.asFileEnding(0xfedc));
}
-
+
+ @Test
public void testName() {
assertEquals("ASCII String", Types.ASCII_STRING.getName());
assertEquals("Boolean", Types.BOOLEAN.getName());
diff --git a/src/scratchpad/testcases/org/apache/poi/hwpf/TestHWPFPictures.java b/src/scratchpad/testcases/org/apache/poi/hwpf/TestHWPFPictures.java
index 902dffc956..da84762332 100644
--- a/src/scratchpad/testcases/org/apache/poi/hwpf/TestHWPFPictures.java
+++ b/src/scratchpad/testcases/org/apache/poi/hwpf/TestHWPFPictures.java
@@ -17,6 +17,11 @@
package org.apache.poi.hwpf;
+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.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.File;
@@ -27,14 +32,13 @@ import javax.imageio.ImageIO;
import org.apache.poi.POIDataSamples;
import org.apache.poi.hwpf.model.PicturesTable;
import org.apache.poi.hwpf.usermodel.Picture;
-
-import junit.framework.TestCase;
+import org.junit.Before;
+import org.junit.Test;
/**
* Test picture support in HWPF
- * @author nick
*/
-public final class TestHWPFPictures extends TestCase {
+public final class TestHWPFPictures {
private String docAFile;
private String docBFile;
private String docCFile;
@@ -45,10 +49,8 @@ public final class TestHWPFPictures extends TestCase {
private String imgCFile;
private String imgDFile;
- @Override
- protected void setUp() throws Exception {
- super.setUp();
-
+ @Before
+ public void setUp() {
docAFile = "testPictures.doc";
docBFile = "two_images.doc";
docCFile = "vector_image.doc";
@@ -68,6 +70,7 @@ public final class TestHWPFPictures extends TestCase {
/**
* Test just opening the files
*/
+ @Test
public void testOpen() {
HWPFTestDataSamples.openSampleFile(docAFile);
HWPFTestDataSamples.openSampleFile(docBFile);
@@ -76,6 +79,7 @@ public final class TestHWPFPictures extends TestCase {
/**
* Test that we have the right numbers of images in each file
*/
+ @Test
public void testImageCount() {
HWPFDocument docA = HWPFTestDataSamples.openSampleFile(docAFile);
HWPFDocument docB = HWPFTestDataSamples.openSampleFile(docBFile);
@@ -96,6 +100,7 @@ public final class TestHWPFPictures extends TestCase {
/**
* Test that we have the right images in at least one file
*/
+ @Test
public void testImageData() {
HWPFDocument docB = HWPFTestDataSamples.openSampleFile(docBFile);
PicturesTable picB = docB.getPicturesTable();
@@ -113,16 +118,14 @@ public final class TestHWPFPictures extends TestCase {
byte[] pic1B = readFile(imgAFile);
byte[] pic2B = readFile(imgBFile);
- assertEquals(pic1B.length, pic1.getContent().length);
- assertEquals(pic2B.length, pic2.getContent().length);
-
- assertBytesSame(pic1B, pic1.getContent());
- assertBytesSame(pic2B, pic2.getContent());
+ assertArrayEquals(pic1B, pic1.getContent());
+ assertArrayEquals(pic2B, pic2.getContent());
}
/**
* Test that compressed image data is correctly returned.
*/
+ @Test
public void testCompressedImageData() {
HWPFDocument docC = HWPFTestDataSamples.openSampleFile(docCFile);
PicturesTable picC = docC.getPicturesTable();
@@ -135,11 +138,10 @@ public final class TestHWPFPictures extends TestCase {
// Check the same
byte[] picBytes = readFile(imgCFile);
-
- assertEquals(picBytes.length, pic.getContent().length);
- assertBytesSame(picBytes, pic.getContent());
+ assertArrayEquals(picBytes, pic.getContent());
}
+ @Test
public void testMacImages() throws Exception {
HWPFDocument docC = HWPFTestDataSamples.openSampleFile("53446.doc");
PicturesTable picturesTable = docC.getPicturesTable();
@@ -168,6 +170,7 @@ public final class TestHWPFPictures extends TestCase {
* Pending the missing files being uploaded to
* bug #44937
*/
+ @Test
public void testEscherDrawing() {
HWPFDocument docD = HWPFTestDataSamples.openSampleFile(docDFile);
List<Picture> allPictures = docD.getPicturesTable().getAllPictures();
@@ -180,14 +183,7 @@ public final class TestHWPFPictures extends TestCase {
assertEquals(picD.length, pic.getContent().length);
- assertBytesSame(picD, pic.getContent());
- }
-
- private void assertBytesSame(byte[] a, byte[] b) {
- assertEquals(a.length, b.length);
- for(int i=0; i<a.length; i++) {
- assertEquals(a[i],b[i]);
- }
+ assertArrayEquals(picD, pic.getContent());
}
private static byte[] readFile(String file) {
diff --git a/src/scratchpad/testcases/org/apache/poi/hwpf/TestHWPFRangeParts.java b/src/scratchpad/testcases/org/apache/poi/hwpf/TestHWPFRangeParts.java
index 8fce4e5587..7a13e6dfb0 100644
--- a/src/scratchpad/testcases/org/apache/poi/hwpf/TestHWPFRangeParts.java
+++ b/src/scratchpad/testcases/org/apache/poi/hwpf/TestHWPFRangeParts.java
@@ -17,15 +17,16 @@
package org.apache.poi.hwpf;
-import org.apache.poi.hwpf.usermodel.Range;
+import static org.junit.Assert.assertEquals;
-import junit.framework.TestCase;
+import org.apache.poi.hwpf.usermodel.Range;
+import org.junit.Before;
+import org.junit.Test;
/**
- * Test that we pull out the right bits of a file into
- * the different ranges
+ * Test that we pull out the right bits of a file into the different ranges
*/
-public final class TestHWPFRangeParts extends TestCase {
+public final class TestHWPFRangeParts {
private static final char page_break = (char)12;
private static final String headerDef =
"\u0003\r\r" +
@@ -93,7 +94,7 @@ public final class TestHWPFRangeParts extends TestCase {
*/
private HWPFDocument docUnicode;
- @Override
+ @Before
public void setUp() {
docUnicode = HWPFTestDataSamples.openSampleFile("HeaderFooterUnicode.doc");
docAscii = HWPFTestDataSamples.openSampleFile("ThreeColHeadFoot.doc");
@@ -104,11 +105,12 @@ public final class TestHWPFRangeParts extends TestCase {
* don't get broken as we write out and read back in again
* TODO - Make this work with 3+ runs
*/
+ @Test
public void testContents() {
HWPFDocument doc = docAscii;
for(int run=0; run<3; run++) {
Range r;
-
+
// Now check the real ranges
r = doc.getRange();
assertEquals(
@@ -117,7 +119,7 @@ public final class TestHWPFRangeParts extends TestCase {
a_page_2,
r.text()
);
-
+
r = doc.getHeaderStoryRange();
assertEquals(
headerDef +
@@ -127,7 +129,7 @@ public final class TestHWPFRangeParts extends TestCase {
endHeaderFooter,
r.text()
);
-
+
r = doc.getOverallRange();
assertEquals(
a_page_1 +
@@ -141,7 +143,7 @@ public final class TestHWPFRangeParts extends TestCase {
"\r",
r.text()
);
-
+
// Write out and read back in again, ready for
// the next run of the test
// TODO run more than once
@@ -150,6 +152,7 @@ public final class TestHWPFRangeParts extends TestCase {
}
}
+ @Test
public void testContentsUnicode() {
Range r;
diff --git a/src/scratchpad/testcases/org/apache/poi/hwpf/converter/AbstractWordUtilsTest.java b/src/scratchpad/testcases/org/apache/poi/hwpf/converter/AbstractWordUtilsTest.java
index 4cb37b8de9..c68d24d4d8 100644
--- a/src/scratchpad/testcases/org/apache/poi/hwpf/converter/AbstractWordUtilsTest.java
+++ b/src/scratchpad/testcases/org/apache/poi/hwpf/converter/AbstractWordUtilsTest.java
@@ -16,25 +16,23 @@
==================================================================== */
package org.apache.poi.hwpf.converter;
-import org.apache.poi.hwpf.usermodel.Range;
+import static org.junit.Assert.assertEquals;
-import junit.framework.TestCase;
import org.apache.poi.hwpf.HWPFDocument;
import org.apache.poi.hwpf.HWPFTestDataSamples;
+import org.apache.poi.hwpf.usermodel.Range;
import org.apache.poi.hwpf.usermodel.Table;
+import org.junit.Test;
/**
* Test cases for {@link AbstractWordUtils}
- *
- * @author Sergey Vladimirov (vlsergey {at} gmail {dot} com)
*/
-public class AbstractWordUtilsTest extends TestCase
-{
+public class AbstractWordUtilsTest {
/**
* Test case for {@link AbstractWordUtils#buildTableCellEdgesArray(Table)}
*/
- public void testBuildTableCellEdgesArray()
- {
+ @Test
+ public void testBuildTableCellEdgesArray() {
HWPFDocument document = HWPFTestDataSamples
.openSampleFile( "table-merges.doc" );
final Range range = document.getRange();
diff --git a/src/scratchpad/testcases/org/apache/poi/hwpf/converter/TestNumberFormatter.java b/src/scratchpad/testcases/org/apache/poi/hwpf/converter/TestNumberFormatter.java
index fdbd51aff0..641540209f 100644
--- a/src/scratchpad/testcases/org/apache/poi/hwpf/converter/TestNumberFormatter.java
+++ b/src/scratchpad/testcases/org/apache/poi/hwpf/converter/TestNumberFormatter.java
@@ -16,13 +16,14 @@
==================================================================== */
package org.apache.poi.hwpf.converter;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
-public class TestNumberFormatter extends TestCase
-{
+import org.junit.Test;
- public void testRoman()
- {
+public class TestNumberFormatter {
+
+ @Test
+ public void testRoman() {
assertEquals( "i", NumberFormatter.getNumber( 1, 2 ) );
assertEquals( "ii", NumberFormatter.getNumber( 2, 2 ) );
assertEquals( "iii", NumberFormatter.getNumber( 3, 2 ) );
@@ -39,44 +40,42 @@ public class TestNumberFormatter extends TestCase
assertEquals( "mcmliv", NumberFormatter.getNumber( 1954, 2 ) );
}
- public void testEnglish()
- {
+ @Test
+ public void testEnglish() {
assertEquals( "a", NumberFormatter.getNumber( 1, 4 ) );
assertEquals( "z", NumberFormatter.getNumber( 26, 4 ) );
- assertEquals( "aa", NumberFormatter.getNumber( 1 * 26 + 1, 4 ) );
- assertEquals( "az", NumberFormatter.getNumber( 1 * 26 + 26, 4 ) );
+ assertEquals( "aa", NumberFormatter.getNumber( 26 + 1, 4 ) );
+ assertEquals( "az", NumberFormatter.getNumber( 26 + 26, 4 ) );
assertEquals( "za", NumberFormatter.getNumber( 26 * 26 + 1, 4 ) );
assertEquals( "zz", NumberFormatter.getNumber( 26 * 26 + 26, 4 ) );
assertEquals( "aaa",
- NumberFormatter.getNumber( 26 * 26 + 1 * 26 + 1, 4 ) );
+ NumberFormatter.getNumber( 26 * 26 + 26 + 1, 4 ) );
assertEquals( "aaz",
- NumberFormatter.getNumber( 26 * 26 + 1 * 26 + 26, 4 ) );
+ NumberFormatter.getNumber( 26 * 26 + 26 + 26, 4 ) );
assertEquals( "aba",
- NumberFormatter.getNumber( 1 * 26 * 26 + 2 * 26 + 1, 4 ) );
+ NumberFormatter.getNumber( 26 * 26 + 2 * 26 + 1, 4 ) );
assertEquals( "aza",
- NumberFormatter.getNumber( 1 * 26 * 26 + 26 * 26 + 1, 4 ) );
+ NumberFormatter.getNumber( 26 * 26 + 26 * 26 + 1, 4 ) );
assertEquals( "azz",
NumberFormatter.getNumber( 26 * 26 + 26 * 26 + 26, 4 ) );
assertEquals( "baa",
- NumberFormatter.getNumber( 2 * 26 * 26 + 1 * 26 + 1, 4 ) );
+ NumberFormatter.getNumber( 2 * 26 * 26 + 26 + 1, 4 ) );
assertEquals( "zaa",
- NumberFormatter.getNumber( 26 * 26 * 26 + 1 * 26 + 1, 4 ) );
+ NumberFormatter.getNumber( 26 * 26 * 26 + 26 + 1, 4 ) );
assertEquals( "zzz",
NumberFormatter.getNumber( 26 * 26 * 26 + 26 * 26 + 26, 4 ) );
assertEquals(
"aaaa",
- NumberFormatter.getNumber( 1 * 26 * 26 * 26 + 1 * 26 * 26 + 1
- * 26 + 1, 4 ) );
+ NumberFormatter.getNumber( 26 * 26 * 26 + 26 * 26 + 26 + 1, 4 ) );
assertEquals(
"azzz",
- NumberFormatter.getNumber( 1 * 26 * 26 * 26 + 26 * 26 * 26 + 26
- * 26 + 26, 4 ) );
+ NumberFormatter.getNumber( 26 * 26 * 26 + 26 * 26 * 26 + 26 * 26 + 26, 4 ) );
assertEquals(
"zzzz",
NumberFormatter.getNumber( 26 * 26 * 26 * 26 + 26 * 26 * 26
diff --git a/src/scratchpad/testcases/org/apache/poi/hwpf/converter/TestWordToTextConverter.java b/src/scratchpad/testcases/org/apache/poi/hwpf/converter/TestWordToTextConverter.java
index 00a46f642c..c6e7e8258a 100644
--- a/src/scratchpad/testcases/org/apache/poi/hwpf/converter/TestWordToTextConverter.java
+++ b/src/scratchpad/testcases/org/apache/poi/hwpf/converter/TestWordToTextConverter.java
@@ -16,45 +16,47 @@
==================================================================== */
package org.apache.poi.hwpf.converter;
-import junit.framework.TestCase;
+import static org.apache.poi.hwpf.HWPFTestDataSamples.openSampleFile;
+import static org.junit.Assert.assertTrue;
+
import org.apache.poi.hwpf.HWPFDocument;
-import org.apache.poi.hwpf.HWPFTestDataSamples;
+import org.junit.Test;
-public class TestWordToTextConverter extends TestCase
-{
+public class TestWordToTextConverter {
/**
* [FAILING] Bug 47731 - Word Extractor considers text copied from some
* website as an embedded object
*/
- public void testBug47731() throws Exception
- {
- HWPFDocument doc = HWPFTestDataSamples.openSampleFile( "Bug47731.doc" );
- String foundText = WordToTextConverter.getText( doc );
+ @Test
+ public void testBug47731() throws Exception {
+ try (HWPFDocument doc = openSampleFile( "Bug47731.doc" )) {
+ String foundText = WordToTextConverter.getText(doc);
- assertTrue( foundText
- .contains( "Soak the rice in water for three to four hours" ) );
+ assertTrue(foundText.contains("Soak the rice in water for three to four hours"));
+ }
}
- public void testBug52311() throws Exception
- {
- HWPFDocument doc = HWPFTestDataSamples.openSampleFile( "Bug52311.doc" );
- String result = WordToTextConverter.getText( doc );
-
- assertTrue( result.contains( "2.1\tHeader 2.1" ) );
- assertTrue( result.contains( "2.2\tHeader 2.2" ) );
- assertTrue( result.contains( "2.3\tHeader 2.3" ) );
- assertTrue( result.contains( "2.3.1\tHeader 2.3.1" ) );
- assertTrue( result.contains( "2.99\tHeader 2.99" ) );
- assertTrue( result.contains( "2.99.1\tHeader 2.99.1" ) );
- assertTrue( result.contains( "2.100\tHeader 2.100" ) );
- assertTrue( result.contains( "2.101\tHeader 2.101" ) );
+ @Test
+ public void testBug52311() throws Exception {
+ try (HWPFDocument doc = openSampleFile( "Bug52311.doc" )) {
+ String result = WordToTextConverter.getText(doc);
+
+ assertTrue(result.contains("2.1\tHeader 2.1"));
+ assertTrue(result.contains("2.2\tHeader 2.2"));
+ assertTrue(result.contains("2.3\tHeader 2.3"));
+ assertTrue(result.contains("2.3.1\tHeader 2.3.1"));
+ assertTrue(result.contains("2.99\tHeader 2.99"));
+ assertTrue(result.contains("2.99.1\tHeader 2.99.1"));
+ assertTrue(result.contains("2.100\tHeader 2.100"));
+ assertTrue(result.contains("2.101\tHeader 2.101"));
+ }
}
- public void testBug53380_3() throws Exception
- {
- HWPFDocument doc = HWPFTestDataSamples
- .openSampleFile( "Bug53380_3.doc" );
- WordToTextConverter.getText( doc );
+ @Test
+ public void testBug53380_3() throws Exception {
+ try (HWPFDocument doc = openSampleFile( "Bug53380_3.doc" )) {
+ WordToTextConverter.getText(doc);
+ }
}
}
diff --git a/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestBookmarksTables.java b/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestBookmarksTables.java
index 4e013b3b7d..567b82e5e8 100644
--- a/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestBookmarksTables.java
+++ b/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestBookmarksTables.java
@@ -16,81 +16,85 @@
==================================================================== */
package org.apache.poi.hwpf.model;
-import org.apache.poi.hwpf.usermodel.Range;
+import static org.apache.poi.hwpf.HWPFTestDataSamples.openSampleFile;
+import static org.junit.Assert.assertEquals;
-import junit.framework.TestCase;
+import java.io.IOException;
import org.apache.poi.hwpf.HWPFDocument;
-import org.apache.poi.hwpf.HWPFTestDataSamples;
import org.apache.poi.hwpf.usermodel.Bookmark;
import org.apache.poi.hwpf.usermodel.Bookmarks;
+import org.apache.poi.hwpf.usermodel.Range;
+import org.junit.Test;
/**
* Test cases for {@link BookmarksTables} and default implementation of
* {@link Bookmarks}
- *
- * @author Sergey Vladimirov (vlsergey {at} gmail {dot} com)
*/
-public class TestBookmarksTables extends TestCase
-{
- public void test()
- {
- HWPFDocument doc = HWPFTestDataSamples.openSampleFile( "pageref.doc" );
- Bookmarks bookmarks = doc.getBookmarks();
-
- assertEquals( 1, bookmarks.getBookmarksCount() );
-
- Bookmark bookmark = bookmarks.getBookmark( 0 );
- assertEquals( "userref", bookmark.getName() );
- assertEquals( 27, bookmark.getStart() );
- assertEquals( 38, bookmark.getEnd() );
+public class TestBookmarksTables {
+ @Test
+ public void test() throws IOException {
+ try (HWPFDocument doc = openSampleFile( "pageref.doc" )) {
+ Bookmarks bookmarks = doc.getBookmarks();
+
+ assertEquals(1, bookmarks.getBookmarksCount());
+
+ Bookmark bookmark = bookmarks.getBookmark(0);
+ assertEquals("userref", bookmark.getName());
+ assertEquals(27, bookmark.getStart());
+ assertEquals(38, bookmark.getEnd());
+ }
}
- public void testDeleteRange()
- {
- HWPFDocument doc = HWPFTestDataSamples.openSampleFile( "pageref.doc" );
- Range range = new Range( 27, 41, doc );
- range.delete();
+ @Test
+ public void testDeleteRange() throws IOException {
+ try (HWPFDocument doc = openSampleFile( "pageref.doc" )) {
+ Range range = new Range(27, 41, doc);
+ range.delete();
- assertEquals( 0, doc.getBookmarks().getBookmarksCount() );
+ assertEquals(0, doc.getBookmarks().getBookmarksCount());
+ }
}
- public void testReplaceTextAfter()
- {
- HWPFDocument doc = HWPFTestDataSamples.openSampleFile( "pageref.doc" );
- Bookmark bookmark = doc.getBookmarks().getBookmark( 0 );
- Range range = new Range( bookmark.getStart(), bookmark.getEnd(), doc );
- range.replaceText( "1destin2ation3", true );
-
- bookmark = doc.getBookmarks().getBookmark( 0 );
- assertEquals( "userref", bookmark.getName() );
- assertEquals( 27, bookmark.getStart() );
- assertEquals( 41, bookmark.getEnd() );
+ @Test
+ public void testReplaceTextAfter() throws IOException {
+ try (HWPFDocument doc = openSampleFile( "pageref.doc" )) {
+ Bookmark bookmark = doc.getBookmarks().getBookmark(0);
+ Range range = new Range(bookmark.getStart(), bookmark.getEnd(), doc);
+ range.replaceText("1destin2ation3", true);
+
+ bookmark = doc.getBookmarks().getBookmark(0);
+ assertEquals("userref", bookmark.getName());
+ assertEquals(27, bookmark.getStart());
+ assertEquals(41, bookmark.getEnd());
+ }
}
- public void testReplaceTextBefore()
- {
- HWPFDocument doc = HWPFTestDataSamples.openSampleFile( "pageref.doc" );
- Bookmark bookmark = doc.getBookmarks().getBookmark( 0 );
- Range range = new Range( bookmark.getStart(), bookmark.getEnd(), doc );
- range.replaceText( "1destin2ation3", false );
-
- bookmark = doc.getBookmarks().getBookmark( 0 );
- assertEquals( "userref", bookmark.getName() );
- assertEquals( 27, bookmark.getStart() );
- assertEquals( 41, bookmark.getEnd() );
+ @Test
+ public void testReplaceTextBefore() throws IOException {
+ try (HWPFDocument doc = openSampleFile( "pageref.doc" )) {
+ Bookmark bookmark = doc.getBookmarks().getBookmark(0);
+ Range range = new Range(bookmark.getStart(), bookmark.getEnd(), doc);
+ range.replaceText("1destin2ation3", false);
+
+ bookmark = doc.getBookmarks().getBookmark(0);
+ assertEquals("userref", bookmark.getName());
+ assertEquals(27, bookmark.getStart());
+ assertEquals(41, bookmark.getEnd());
+ }
}
- public void testUpdateText()
- {
- HWPFDocument doc = HWPFTestDataSamples.openSampleFile( "pageref.doc" );
- Bookmark bookmark = doc.getBookmarks().getBookmark( 0 );
- Range range = new Range( bookmark.getStart(), bookmark.getEnd(), doc );
- range.replaceText( "destination", "1destin2ation3" );
-
- bookmark = doc.getBookmarks().getBookmark( 0 );
- assertEquals( "userref", bookmark.getName() );
- assertEquals( 27, bookmark.getStart() );
- assertEquals( 41, bookmark.getEnd() );
+ @Test
+ public void testUpdateText() throws IOException {
+ try (HWPFDocument doc = openSampleFile( "pageref.doc" )) {
+ Bookmark bookmark = doc.getBookmarks().getBookmark(0);
+ Range range = new Range(bookmark.getStart(), bookmark.getEnd(), doc);
+ range.replaceText("destination", "1destin2ation3");
+
+ bookmark = doc.getBookmarks().getBookmark(0);
+ assertEquals("userref", bookmark.getName());
+ assertEquals(27, bookmark.getStart());
+ assertEquals(41, bookmark.getEnd());
+ }
}
}
diff --git a/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestCHPBinTable.java b/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestCHPBinTable.java
index b3aa64ab9c..47ef71ea51 100644
--- a/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestCHPBinTable.java
+++ b/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestCHPBinTable.java
@@ -17,17 +17,18 @@
package org.apache.poi.hwpf.model;
+import static org.junit.Assert.assertEquals;
+
import java.io.ByteArrayOutputStream;
import java.util.List;
-import junit.framework.TestCase;
-
import org.apache.poi.hwpf.HWPFDocFixture;
import org.apache.poi.hwpf.model.io.HWPFFileSystem;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
-public final class TestCHPBinTable
- extends TestCase
-{
+public final class TestCHPBinTable {
private CHPBinTable _cHPBinTable;
private HWPFDocFixture _hWPFDocFixture;
@@ -38,9 +39,8 @@ public final class TestCHPBinTable
}
};
- public void testReadWrite()
- throws Exception
- {
+ @Test
+ public void testReadWrite() throws Exception {
FileInformationBlock fib = _hWPFDocFixture._fib;
byte[] mainStream = _hWPFDocFixture._mainStream;
byte[] tableStream = _hWPFDocFixture._tableStream;
@@ -73,25 +73,19 @@ public final class TestCHPBinTable
}
}
- @Override
-protected void setUp()
- throws Exception
- {
- super.setUp();
+ @Before
+ public void setUp() throws Exception {
_hWPFDocFixture = new HWPFDocFixture(this, HWPFDocFixture.DEFAULT_TEST_FILE);
_hWPFDocFixture.setUp();
}
- @Override
-protected void tearDown()
- throws Exception
- {
+ @After
+ public void tearDown() throws Exception {
_cHPBinTable = null;
_hWPFDocFixture.tearDown();
_hWPFDocFixture = null;
- super.tearDown();
}
}
diff --git a/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestNotesTables.java b/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestNotesTables.java
index 4679d24f62..3b7ef6f7e3 100644
--- a/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestNotesTables.java
+++ b/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestNotesTables.java
@@ -16,20 +16,19 @@
==================================================================== */
package org.apache.poi.hwpf.model;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
import org.apache.poi.hwpf.HWPFDocument;
import org.apache.poi.hwpf.HWPFTestDataSamples;
import org.apache.poi.hwpf.usermodel.Notes;
+import org.junit.Test;
/**
* Test cases for {@link NotesTables} and default implementation of
* {@link Notes}
- *
- * @author Sergey Vladimirov (vlsergey {at} gmail {dot} com)
*/
-public class TestNotesTables extends TestCase
-{
+public class TestNotesTables {
+ @Test
public void test()
{
HWPFDocument doc = HWPFTestDataSamples
diff --git a/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestPlexOfCps.java b/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestPlexOfCps.java
index 09fefc21e3..abe2ae09d1 100644
--- a/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestPlexOfCps.java
+++ b/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestPlexOfCps.java
@@ -17,17 +17,19 @@
package org.apache.poi.hwpf.model;
-import junit.framework.*;
-import org.apache.poi.hwpf.*;
+import static org.junit.Assert.assertEquals;
+import org.apache.poi.hwpf.HWPFDocFixture;
import org.apache.poi.util.LittleEndian;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
-public final class TestPlexOfCps
- extends TestCase
-{
+public final class TestPlexOfCps {
private PlexOfCps _plexOfCps;
private HWPFDocFixture _hWPFDocFixture;
+ @Test
public void testWriteRead() {
_plexOfCps = new PlexOfCps(4);
@@ -56,26 +58,21 @@ public final class TestPlexOfCps
assertEquals(node.getEnd()-node.getStart(), span);
}
}
- @Override
-protected void setUp()
- throws Exception
- {
- super.setUp();
+
+ @Before
+ public void setUp() throws Exception {
/**@todo verify the constructors*/
_hWPFDocFixture = new HWPFDocFixture(this, HWPFDocFixture.DEFAULT_TEST_FILE);
_hWPFDocFixture.setUp();
}
- @Override
-protected void tearDown()
- throws Exception
- {
+ @After
+ public void tearDown() throws Exception {
_plexOfCps = null;
_hWPFDocFixture.tearDown();
_hWPFDocFixture = null;
- super.tearDown();
}
}
diff --git a/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestSectionTable.java b/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestSectionTable.java
index 1ca57b098b..a50320963b 100644
--- a/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestSectionTable.java
+++ b/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestSectionTable.java
@@ -17,22 +17,22 @@
package org.apache.poi.hwpf.model;
-import junit.framework.*;
+import static org.junit.Assert.assertEquals;
import java.io.ByteArrayOutputStream;
import java.util.List;
-import org.apache.poi.hwpf.*;
-import org.apache.poi.hwpf.model.io.*;
+import org.apache.poi.hwpf.HWPFDocFixture;
+import org.apache.poi.hwpf.model.io.HWPFFileSystem;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
-public final class TestSectionTable
- extends TestCase
-{
+public final class TestSectionTable {
private HWPFDocFixture _hWPFDocFixture;
- public void testReadWrite()
- throws Exception
- {
+ @Test
+ public void testReadWrite() throws Exception {
FileInformationBlock fib = _hWPFDocFixture._fib;
byte[] mainStream = _hWPFDocFixture._mainStream;
byte[] tableStream = _hWPFDocFixture._tableStream;
@@ -85,25 +85,19 @@ public final class TestSectionTable
}
}
- @Override
-protected void setUp()
- throws Exception
- {
- super.setUp();
- /**@todo verify the constructors*/
+ @Before
+ public void setUp() throws Exception {
+ /*@todo verify the constructors*/
_hWPFDocFixture = new HWPFDocFixture(this, HWPFDocFixture.DEFAULT_TEST_FILE);
_hWPFDocFixture.setUp();
}
- @Override
-protected void tearDown()
- throws Exception
- {
+ @After
+ public void tearDown() {
_hWPFDocFixture.tearDown();
_hWPFDocFixture = null;
- super.tearDown();
}
}
diff --git a/src/scratchpad/testcases/org/apache/poi/hwpf/model/types/LFOLVLBaseAbstractTypeTest.java b/src/scratchpad/testcases/org/apache/poi/hwpf/model/types/LFOLVLBaseAbstractTypeTest.java
index 90919cfcc0..450e873fbb 100644
--- a/src/scratchpad/testcases/org/apache/poi/hwpf/model/types/LFOLVLBaseAbstractTypeTest.java
+++ b/src/scratchpad/testcases/org/apache/poi/hwpf/model/types/LFOLVLBaseAbstractTypeTest.java
@@ -16,18 +16,16 @@
==================================================================== */
package org.apache.poi.hwpf.model.types;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
/**
* Test cases for {@link LFOLVLBaseAbstractType}
- *
- * @author Sergey Vladimirov (vlsergey {at} gmail {dot} com)
*/
-public class LFOLVLBaseAbstractTypeTest extends TestCase
-{
-
- public void testGetSize()
- {
+public class LFOLVLBaseAbstractTypeTest {
+ @Test
+ public void testGetSize() {
assertEquals( 8, LFOLVLBaseAbstractType.getSize() );
}
diff --git a/src/scratchpad/testcases/org/apache/poi/hwpf/model/types/LVLFAbstractTypeTest.java b/src/scratchpad/testcases/org/apache/poi/hwpf/model/types/LVLFAbstractTypeTest.java
index b2e96426f8..9a64a33698 100644
--- a/src/scratchpad/testcases/org/apache/poi/hwpf/model/types/LVLFAbstractTypeTest.java
+++ b/src/scratchpad/testcases/org/apache/poi/hwpf/model/types/LVLFAbstractTypeTest.java
@@ -16,18 +16,16 @@
==================================================================== */
package org.apache.poi.hwpf.model.types;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
/**
* Test cases for {@link LVLFAbstractType}
- *
- * @author Sergey Vladimirov (vlsergey {at} gmail {dot} com)
*/
-public class LVLFAbstractTypeTest extends TestCase
-{
-
- public void testGetSize()
- {
+public class LVLFAbstractTypeTest {
+ @Test
+ public void testGetSize() {
assertEquals( 28, LVLFAbstractType.getSize() );
}
diff --git a/src/scratchpad/testcases/org/apache/poi/hwpf/sprm/TableSprmUncompressorTest.java b/src/scratchpad/testcases/org/apache/poi/hwpf/sprm/TableSprmUncompressorTest.java
index 77c6e86c81..881a7b2e43 100644
--- a/src/scratchpad/testcases/org/apache/poi/hwpf/sprm/TableSprmUncompressorTest.java
+++ b/src/scratchpad/testcases/org/apache/poi/hwpf/sprm/TableSprmUncompressorTest.java
@@ -18,14 +18,14 @@
*/
package org.apache.poi.hwpf.sprm;
-import org.apache.poi.hwpf.usermodel.TableProperties;
+import static org.junit.Assert.assertEquals;
-import junit.framework.TestCase;
+import org.apache.poi.hwpf.usermodel.TableProperties;
+import org.junit.Test;
-public class TableSprmUncompressorTest extends TestCase
-{
- public void testSprmTDefTable()
- {
+public class TableSprmUncompressorTest {
+ @Test
+ public void testSprmTDefTable() {
final byte[] example = { (byte) 0x08, (byte) 0xD6, (byte) 0x2F,
(byte) 0x00, (byte) 0x02, (byte) 0x94, (byte) 0xFF,
(byte) 0x53, (byte) 0x03, (byte) 0x60, (byte) 0x13,
diff --git a/src/scratchpad/testcases/org/apache/poi/hwpf/sprm/TestSprms.java b/src/scratchpad/testcases/org/apache/poi/hwpf/sprm/TestSprms.java
index e83dbeeaa7..9af5ff57c0 100644
--- a/src/scratchpad/testcases/org/apache/poi/hwpf/sprm/TestSprms.java
+++ b/src/scratchpad/testcases/org/apache/poi/hwpf/sprm/TestSprms.java
@@ -19,20 +19,22 @@
package org.apache.poi.hwpf.sprm;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Locale;
-import junit.framework.TestCase;
import org.apache.poi.POIDataSamples;
import org.apache.poi.hwpf.HWPFDocument;
import org.apache.poi.hwpf.usermodel.Paragraph;
import org.apache.poi.hwpf.usermodel.Range;
+import org.junit.Test;
-public class TestSprms extends TestCase
-{
+public class TestSprms {
private static HWPFDocument reload( HWPFDocument hwpfDocument )
throws IOException
{
@@ -45,16 +47,18 @@ public class TestSprms extends TestCase
* Test correct processing of "sprmPItap" (0x6649) and "sprmPFInTable"
* (0x2416)
*/
- public void testInnerTable() throws Exception
- {
+ @Test
+ public void testInnerTable() throws Exception {
InputStream resourceAsStream = POIDataSamples.getDocumentInstance()
.openResourceAsStream( "innertable.doc" );
- HWPFDocument hwpfDocument = new HWPFDocument( resourceAsStream );
- resourceAsStream.close();
+ try (HWPFDocument hwpfDocument = new HWPFDocument( resourceAsStream )) {
+ resourceAsStream.close();
- testInnerTable( hwpfDocument );
- hwpfDocument = reload( hwpfDocument );
- testInnerTable( hwpfDocument );
+ testInnerTable(hwpfDocument);
+ try (HWPFDocument hwpfDocument2 = reload(hwpfDocument)) {
+ testInnerTable(hwpfDocument2);
+ }
+ }
}
private void testInnerTable( HWPFDocument hwpfDocument )
@@ -81,20 +85,22 @@ public class TestSprms extends TestCase
/**
* Test correct processing of "sprmPJc" by uncompressor
*/
- public void testSprmPJc() throws IOException
- {
- InputStream resourceAsStream = POIDataSamples.getDocumentInstance()
+ @Test
+ public void testSprmPJc() throws IOException {
+ try (InputStream resourceAsStream = POIDataSamples.getDocumentInstance()
.openResourceAsStream( "Bug49820.doc" );
- HWPFDocument hwpfDocument = new HWPFDocument( resourceAsStream );
- resourceAsStream.close();
+ HWPFDocument hwpfDocument = new HWPFDocument( resourceAsStream )) {
+ resourceAsStream.close();
- assertEquals( 1, hwpfDocument.getStyleSheet().getParagraphStyle( 8 )
- .getJustification() );
+ assertEquals(1, hwpfDocument.getStyleSheet().getParagraphStyle(8)
+ .getJustification());
- hwpfDocument = reload( hwpfDocument );
+ try (HWPFDocument hwpfDocument2 = reload(hwpfDocument)) {
- assertEquals( 1, hwpfDocument.getStyleSheet().getParagraphStyle( 8 )
- .getJustification() );
+ assertEquals(1, hwpfDocument2.getStyleSheet().getParagraphStyle(8)
+ .getJustification());
+ }
+ }
}
}
diff --git a/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestBorderCode.java b/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestBorderCode.java
index fd0102b3b3..b66f814e35 100644
--- a/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestBorderCode.java
+++ b/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestBorderCode.java
@@ -17,19 +17,23 @@
package org.apache.poi.hwpf.usermodel;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
import org.apache.poi.hwpf.HWPFDocument;
import org.apache.poi.hwpf.HWPFTestDataSamples;
+import org.junit.Test;
/**
* API for BorderCode, see Bugzill 49919
*/
-public final class TestBorderCode extends TestCase {
+public final class TestBorderCode {
private int pos;
private Range range;
+ @Test
public void test() {
HWPFDocument doc = HWPFTestDataSamples.openSampleFile("Bug49919.doc");
range = doc.getRange();
@@ -107,7 +111,7 @@ public final class TestBorderCode extends TestCase {
fail("Expected paragraph not found");
// should never come here
- throw null;
+ return null;
}
}
diff --git a/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestBug49820.java b/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestBug49820.java
index 92d99c386c..e4e0c33b47 100644
--- a/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestBug49820.java
+++ b/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestBug49820.java
@@ -17,42 +17,46 @@
package org.apache.poi.hwpf.usermodel;
+import static org.junit.Assert.assertEquals;
+
import java.io.IOException;
-import junit.framework.TestCase;
import org.apache.poi.hwpf.HWPFDocument;
import org.apache.poi.hwpf.HWPFTestDataSamples;
import org.apache.poi.hwpf.model.StyleSheet;
+import org.junit.Test;
-public final class TestBug49820 extends TestCase {
+public final class TestBug49820 {
+ @Test
public void test() throws IOException {
- HWPFDocument doc = HWPFTestDataSamples.openSampleFile("Bug49820.doc");
-
- Range documentRange = doc.getRange();
- StyleSheet styleSheet = doc.getStyleSheet();
-
- // JUnit asserts
- assertLevels(documentRange, styleSheet, 0, 0, 0);
- assertLevels(documentRange, styleSheet, 1, 1, 1);
- assertLevels(documentRange, styleSheet, 2, 2, 2);
- assertLevels(documentRange, styleSheet, 3, 3, 3);
- assertLevels(documentRange, styleSheet, 4, 4, 4);
- assertLevels(documentRange, styleSheet, 5, 5, 5);
- assertLevels(documentRange, styleSheet, 6, 6, 6);
- assertLevels(documentRange, styleSheet, 7, 7, 7);
- assertLevels(documentRange, styleSheet, 8, 8, 8);
- assertLevels(documentRange, styleSheet, 9, 9, 9);
- assertLevels(documentRange, styleSheet, 10, 9, 0);
- assertLevels(documentRange, styleSheet, 11, 9, 4);
-
- // output to console
+ try (HWPFDocument doc = HWPFTestDataSamples.openSampleFile("Bug49820.doc")) {
+
+ Range documentRange = doc.getRange();
+ StyleSheet styleSheet = doc.getStyleSheet();
+
+ // JUnit asserts
+ assertLevels(documentRange, styleSheet, 0, 0, 0);
+ assertLevels(documentRange, styleSheet, 1, 1, 1);
+ assertLevels(documentRange, styleSheet, 2, 2, 2);
+ assertLevels(documentRange, styleSheet, 3, 3, 3);
+ assertLevels(documentRange, styleSheet, 4, 4, 4);
+ assertLevels(documentRange, styleSheet, 5, 5, 5);
+ assertLevels(documentRange, styleSheet, 6, 6, 6);
+ assertLevels(documentRange, styleSheet, 7, 7, 7);
+ assertLevels(documentRange, styleSheet, 8, 8, 8);
+ assertLevels(documentRange, styleSheet, 9, 9, 9);
+ assertLevels(documentRange, styleSheet, 10, 9, 0);
+ assertLevels(documentRange, styleSheet, 11, 9, 4);
+
+ // output to console
/*for (int i=0; i<documentRange.numParagraphs(); i++) {
Paragraph par = documentRange.getParagraph(i);
int styleLvl = styleSheet.getParagraphStyle(par.getStyleIndex()).getLvl();
int parLvl = par.getLvl();
System.out.println("Style level: " + styleLvl + ", paragraph level: " + parLvl + ", text: " + par.text());
}*/
+ }
}
private void assertLevels(Range documentRange, StyleSheet styleSheet, int parIndex, int expectedStyleLvl, int expectedParLvl) {
diff --git a/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestBug50075.java b/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestBug50075.java
index 74867b939c..535f9be52d 100644
--- a/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestBug50075.java
+++ b/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestBug50075.java
@@ -16,26 +16,31 @@
==================================================================== */
package org.apache.poi.hwpf.usermodel;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.io.IOException;
import org.apache.poi.hwpf.HWPFDocument;
import org.apache.poi.hwpf.HWPFTestDataSamples;
import org.apache.poi.hwpf.model.LFO;
import org.apache.poi.hwpf.model.ListLevel;
+import org.junit.Test;
+
+public class TestBug50075 {
-public class TestBug50075 extends TestCase
-{
-
- public void test() {
- HWPFDocument doc = HWPFTestDataSamples.openSampleFile("Bug50075.doc");
- Range range = doc.getRange();
- assertEquals(1, range.numParagraphs());
- ListEntry entry = (ListEntry) range.getParagraph(0);
- LFO override = doc.getListTables().getLfo( entry.getIlfo());
- ListLevel level = doc.getListTables().getLevel(override.getLsid(), entry.getIlvl());
-
- // the bug reproduces, if this call fails with NullPointerException
- level.getNumberText();
+ @Test
+ public void test() throws IOException {
+ try (HWPFDocument doc = HWPFTestDataSamples.openSampleFile("Bug50075.doc")) {
+ Range range = doc.getRange();
+ assertEquals(1, range.numParagraphs());
+ ListEntry entry = (ListEntry) range.getParagraph(0);
+ LFO override = doc.getListTables().getLfo(entry.getIlfo());
+ ListLevel level = doc.getListTables().getLevel(override.getLsid(), entry.getIlvl());
+ assertNotNull(level);
+ // the bug reproduces, if this call fails with NullPointerException
+ assertNotNull(level.getNumberText());
+ }
}
-
+
}
diff --git a/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestHeaderStories.java b/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestHeaderStories.java
index 0aa4b31626..e35b5aa910 100644
--- a/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestHeaderStories.java
+++ b/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestHeaderStories.java
@@ -17,15 +17,20 @@
package org.apache.poi.hwpf.usermodel;
-import junit.framework.TestCase;
+import static org.apache.poi.hwpf.HWPFTestDataSamples.openSampleFile;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
import org.apache.poi.hwpf.HWPFDocument;
-import org.apache.poi.hwpf.HWPFTestDataSamples;
+import org.junit.Before;
+import org.junit.Test;
/**
* Tests for the handling of header stories into headers, footers etc
*/
-public final class TestHeaderStories extends TestCase {
+@SuppressWarnings("deprecation")
+public final class TestHeaderStories {
private HWPFDocument none;
private HWPFDocument header;
private HWPFDocument footer;
@@ -35,19 +40,20 @@ public final class TestHeaderStories extends TestCase {
private HWPFDocument unicode;
private HWPFDocument withFields;
- @Override
- protected void setUp() {
-
- none = HWPFTestDataSamples.openSampleFile("NoHeadFoot.doc");
- header = HWPFTestDataSamples.openSampleFile("ThreeColHead.doc");
- footer = HWPFTestDataSamples.openSampleFile("ThreeColFoot.doc");
- headerFooter = HWPFTestDataSamples.openSampleFile("SimpleHeadThreeColFoot.doc");
- oddEven = HWPFTestDataSamples.openSampleFile("PageSpecificHeadFoot.doc");
- diffFirst = HWPFTestDataSamples.openSampleFile("DiffFirstPageHeadFoot.doc");
- unicode = HWPFTestDataSamples.openSampleFile("HeaderFooterUnicode.doc");
- withFields = HWPFTestDataSamples.openSampleFile("HeaderWithMacros.doc");
+ @Before
+ public void setUp() {
+
+ none = openSampleFile("NoHeadFoot.doc");
+ header = openSampleFile("ThreeColHead.doc");
+ footer = openSampleFile("ThreeColFoot.doc");
+ headerFooter = openSampleFile("SimpleHeadThreeColFoot.doc");
+ oddEven = openSampleFile("PageSpecificHeadFoot.doc");
+ diffFirst = openSampleFile("DiffFirstPageHeadFoot.doc");
+ unicode = openSampleFile("HeaderFooterUnicode.doc");
+ withFields = openSampleFile("HeaderWithMacros.doc");
}
+ @Test
public void testNone() {
HeaderStories hs = new HeaderStories(none);
@@ -55,6 +61,7 @@ public final class TestHeaderStories extends TestCase {
assertEquals(0, hs.getRange().text().length());
}
+ @Test
public void testHeader() {
HeaderStories hs = new HeaderStories(header);
@@ -99,6 +106,7 @@ public final class TestHeaderStories extends TestCase {
assertEquals("", hs.getOddFooter());
}
+ @Test
public void testFooter() {
HeaderStories hs = new HeaderStories(footer);
@@ -111,6 +119,7 @@ public final class TestHeaderStories extends TestCase {
assertEquals("Footer Left\tFooter Middle Footer Right\r\r", hs.getOddFooter());
}
+ @Test
public void testHeaderFooter() {
HeaderStories hs = new HeaderStories(headerFooter);
@@ -123,6 +132,7 @@ public final class TestHeaderStories extends TestCase {
assertEquals("Footer Left\tFooter Middle Footer Right\r\r", hs.getOddFooter());
}
+ @Test
public void testOddEven() {
HeaderStories hs = new HeaderStories(oddEven);
@@ -145,6 +155,7 @@ public final class TestHeaderStories extends TestCase {
assertEquals("Footer Left\tFooter Middle Footer Right\r\r", hs.getFooter(3));
}
+ @Test
public void testFirst() {
HeaderStories hs = new HeaderStories(diffFirst);
@@ -162,6 +173,7 @@ public final class TestHeaderStories extends TestCase {
assertEquals("Footer Left\tFooter Middle Footer Right\r\r", hs.getFooter(3));
}
+ @Test
public void testUnicode() {
HeaderStories hs = new HeaderStories(unicode);
@@ -175,6 +187,7 @@ public final class TestHeaderStories extends TestCase {
assertEquals("The footer, with Moli\u00e8re, has Unicode in it.\r\r", hs.getOddFooter());
}
+ @Test
public void testWithFields() {
HeaderStories hs = new HeaderStories(withFields);
assertFalse(hs.areFieldsStripped());
diff --git a/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestLists.java b/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestLists.java
index 3a594f3cab..7290b0cf95 100644
--- a/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestLists.java
+++ b/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestLists.java
@@ -17,240 +17,257 @@
package org.apache.poi.hwpf.usermodel;
-import java.io.IOException;
+import static org.apache.poi.hwpf.HWPFTestDataSamples.openSampleFile;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
-import junit.framework.TestCase;
+import java.io.IOException;
import org.apache.poi.hwpf.HWPFDocument;
import org.apache.poi.hwpf.HWPFTestDataSamples;
import org.apache.poi.hwpf.model.ListLevel;
+import org.junit.Test;
/**
* Tests for our handling of lists
*/
-public final class TestLists extends TestCase {
- public void testBasics() {
- HWPFDocument doc = HWPFTestDataSamples.openSampleFile("Lists.doc");
- Range r = doc.getRange();
-
- assertEquals(40, r.numParagraphs());
- assertEquals("Heading Level 1\r", r.getParagraph(0).text());
- assertEquals("This document has different lists in it for testing\r", r.getParagraph(1).text());
- assertEquals("The end!\r", r.getParagraph(38).text());
- assertEquals("\r", r.getParagraph(39).text());
-
- assertEquals(0, r.getParagraph(0).getLvl());
- assertEquals(9, r.getParagraph(1).getLvl());
- assertEquals(9, r.getParagraph(38).getLvl());
- assertEquals(9, r.getParagraph(39).getLvl());
- }
-
- public void testUnorderedLists() {
- HWPFDocument doc = HWPFTestDataSamples.openSampleFile("Lists.doc");
- Range r = doc.getRange();
- assertEquals(40, r.numParagraphs());
-
- // Normal bullet points
- assertEquals("This document has different lists in it for testing\r", r.getParagraph(1).text());
- assertEquals("Unordered list 1\r", r.getParagraph(2).text());
- assertEquals("UL 2\r", r.getParagraph(3).text());
- assertEquals("UL 3\r", r.getParagraph(4).text());
- assertEquals("Next up is an ordered list:\r", r.getParagraph(5).text());
-
- assertEquals(9, r.getParagraph(1).getLvl());
- assertEquals(9, r.getParagraph(2).getLvl());
- assertEquals(9, r.getParagraph(3).getLvl());
- assertEquals(9, r.getParagraph(4).getLvl());
- assertEquals(9, r.getParagraph(5).getLvl());
-
- assertEquals(0, r.getParagraph(1).getIlvl());
- assertEquals(0, r.getParagraph(2).getIlvl());
- assertEquals(0, r.getParagraph(3).getIlvl());
- assertEquals(0, r.getParagraph(4).getIlvl());
- assertEquals(0, r.getParagraph(5).getIlvl());
-
- // Tick bullets
- assertEquals("Now for an un-ordered list with a different bullet style:\r", r.getParagraph(9).text());
- assertEquals("Tick 1\r", r.getParagraph(10).text());
- assertEquals("Tick 2\r", r.getParagraph(11).text());
- assertEquals("Multi-level un-ordered list:\r", r.getParagraph(12).text());
-
- assertEquals(9, r.getParagraph(9).getLvl());
- assertEquals(9, r.getParagraph(10).getLvl());
- assertEquals(9, r.getParagraph(11).getLvl());
- assertEquals(9, r.getParagraph(12).getLvl());
-
- assertEquals(0, r.getParagraph(9).getIlvl());
- assertEquals(0, r.getParagraph(10).getIlvl());
- assertEquals(0, r.getParagraph(11).getIlvl());
- assertEquals(0, r.getParagraph(12).getIlvl());
-
- // TODO Test for tick not bullet
- }
-
- public void testOrderedLists() {
- HWPFDocument doc = HWPFTestDataSamples.openSampleFile("Lists.doc");
- Range r = doc.getRange();
- assertEquals(40, r.numParagraphs());
-
- assertEquals("Next up is an ordered list:\r", r.getParagraph(5).text());
- assertEquals("Ordered list 1\r", r.getParagraph(6).text());
- assertEquals("OL 2\r", r.getParagraph(7).text());
- assertEquals("OL 3\r", r.getParagraph(8).text());
- assertEquals("Now for an un-ordered list with a different bullet style:\r", r.getParagraph(9).text());
-
- assertEquals(9, r.getParagraph(5).getLvl());
- assertEquals(9, r.getParagraph(6).getLvl());
- assertEquals(9, r.getParagraph(7).getLvl());
- assertEquals(9, r.getParagraph(8).getLvl());
- assertEquals(9, r.getParagraph(9).getLvl());
-
- assertEquals(0, r.getParagraph(5).getIlvl());
- assertEquals(0, r.getParagraph(6).getIlvl());
- assertEquals(0, r.getParagraph(7).getIlvl());
- assertEquals(0, r.getParagraph(8).getIlvl());
- assertEquals(0, r.getParagraph(9).getIlvl());
- }
-
- public void testMultiLevelLists() {
- HWPFDocument doc = HWPFTestDataSamples.openSampleFile("Lists.doc");
- Range r = doc.getRange();
- assertEquals(40, r.numParagraphs());
-
- assertEquals("Multi-level un-ordered list:\r", r.getParagraph(12).text());
- assertEquals("ML 1:1\r", r.getParagraph(13).text());
- assertEquals("ML 1:2\r", r.getParagraph(14).text());
- assertEquals("ML 2:1\r", r.getParagraph(15).text());
- assertEquals("ML 2:2\r", r.getParagraph(16).text());
- assertEquals("ML 2:3\r", r.getParagraph(17).text());
- assertEquals("ML 3:1\r", r.getParagraph(18).text());
- assertEquals("ML 4:1\r", r.getParagraph(19).text());
- assertEquals("ML 5:1\r", r.getParagraph(20).text());
- assertEquals("ML 5:2\r", r.getParagraph(21).text());
- assertEquals("ML 2:4\r", r.getParagraph(22).text());
- assertEquals("ML 1:3\r", r.getParagraph(23).text());
- assertEquals("Multi-level ordered list:\r", r.getParagraph(24).text());
- assertEquals("OL 1\r", r.getParagraph(25).text());
- assertEquals("OL 2\r", r.getParagraph(26).text());
- assertEquals("OL 2.1\r", r.getParagraph(27).text());
- assertEquals("OL 2.2\r", r.getParagraph(28).text());
- assertEquals("OL 2.2.1\r", r.getParagraph(29).text());
- assertEquals("OL 2.2.2\r", r.getParagraph(30).text());
- assertEquals("OL 2.2.2.1\r", r.getParagraph(31).text());
- assertEquals("OL 2.2.3\r", r.getParagraph(32).text());
- assertEquals("OL 3\r", r.getParagraph(33).text());
- assertEquals("Finally we want some indents, to tell the difference\r", r.getParagraph(34).text());
-
- for(int i=12; i<=34; i++) {
- assertEquals(9, r.getParagraph(12).getLvl());
- }
- assertEquals(0, r.getParagraph(12).getIlvl());
- assertEquals(0, r.getParagraph(13).getIlvl());
- assertEquals(0, r.getParagraph(14).getIlvl());
- assertEquals(1, r.getParagraph(15).getIlvl());
- assertEquals(1, r.getParagraph(16).getIlvl());
- assertEquals(1, r.getParagraph(17).getIlvl());
- assertEquals(2, r.getParagraph(18).getIlvl());
- assertEquals(3, r.getParagraph(19).getIlvl());
- assertEquals(4, r.getParagraph(20).getIlvl());
- assertEquals(4, r.getParagraph(21).getIlvl());
- assertEquals(1, r.getParagraph(22).getIlvl());
- assertEquals(0, r.getParagraph(23).getIlvl());
- assertEquals(0, r.getParagraph(24).getIlvl());
- assertEquals(0, r.getParagraph(25).getIlvl());
- assertEquals(0, r.getParagraph(26).getIlvl());
- assertEquals(1, r.getParagraph(27).getIlvl());
- assertEquals(1, r.getParagraph(28).getIlvl());
- assertEquals(2, r.getParagraph(29).getIlvl());
- assertEquals(2, r.getParagraph(30).getIlvl());
- assertEquals(3, r.getParagraph(31).getIlvl());
- assertEquals(2, r.getParagraph(32).getIlvl());
- assertEquals(0, r.getParagraph(33).getIlvl());
- assertEquals(0, r.getParagraph(34).getIlvl());
- }
-
- public void testIndentedText() {
- HWPFDocument doc = HWPFTestDataSamples.openSampleFile("Lists.doc");
- Range r = doc.getRange();
-
- assertEquals(40, r.numParagraphs());
- assertEquals("Finally we want some indents, to tell the difference\r", r.getParagraph(34).text());
- assertEquals("Indented once\r", r.getParagraph(35).text());
- assertEquals("Indented twice\r", r.getParagraph(36).text());
- assertEquals("Indented three times\r", r.getParagraph(37).text());
- assertEquals("The end!\r", r.getParagraph(38).text());
-
- assertEquals(9, r.getParagraph(34).getLvl());
- assertEquals(9, r.getParagraph(35).getLvl());
- assertEquals(9, r.getParagraph(36).getLvl());
- assertEquals(9, r.getParagraph(37).getLvl());
- assertEquals(9, r.getParagraph(38).getLvl());
- assertEquals(9, r.getParagraph(39).getLvl());
-
- assertEquals(0, r.getParagraph(34).getIlvl());
- assertEquals(0, r.getParagraph(35).getIlvl());
- assertEquals(0, r.getParagraph(36).getIlvl());
- assertEquals(0, r.getParagraph(37).getIlvl());
- assertEquals(0, r.getParagraph(38).getIlvl());
- assertEquals(0, r.getParagraph(39).getIlvl());
-
- // TODO Test the indent
- }
-
- public void testWriteRead() throws IOException {
- HWPFDocument doc = HWPFTestDataSamples.openSampleFile("Lists.doc");
- doc = HWPFTestDataSamples.writeOutAndReadBack(doc);
-
- Range r = doc.getRange();
-
- // Check a couple at random
- assertEquals(4, r.getParagraph(21).getIlvl());
- assertEquals(1, r.getParagraph(22).getIlvl());
- assertEquals(0, r.getParagraph(23).getIlvl());
-
- // Try to read numCharacterRuns, see bug 50060
- assertEquals(1, r.getParagraph(0).numCharacterRuns());
- }
-
- public void testSpecificNumberedOrderedListFeatures() throws IOException {
- HWPFDocument doc = HWPFTestDataSamples.openSampleFile("Lists.doc");
-
- Range r = doc.getRange();
- //these are in the numbered ordered list
- //26 = OL 2
- //27 = OL 2.1
- //28 = OL 2.2
- //29 = OL 2.2.1
- for (int i = 26; i < 30; i++) {
- Paragraph p = r.getParagraph(i);
- assertTrue(p.isInList());
- HWPFList list = p.getList();
- ListLevel level = list.getLVL((char) p.getIlvl());
- assertFalse(level.isLegalNumbering());
- assertEquals(-1, level.getRestart());
- }
- Paragraph p = r.getParagraph(26);
- HWPFList list = p.getList();
- ListLevel level = list.getLVL((char) p.getIlvl());
- byte[] lvl = level.getLevelNumberingPlaceholderOffsets();
-
- assertEquals((byte)1, lvl[0]);
- assertEquals((byte)0, lvl[1]);
-
- p = r.getParagraph(27);
- list = p.getList();
- level = list.getLVL((char) p.getIlvl());
- lvl = level.getLevelNumberingPlaceholderOffsets();
- assertEquals((byte)1, lvl[0]);
- assertEquals((byte)3, lvl[1]);
-
- p = r.getParagraph(29);
- list = p.getList();
- level = list.getLVL((char) p.getIlvl());
- lvl = level.getLevelNumberingPlaceholderOffsets();
-
- assertEquals((byte)1, lvl[0]);
- assertEquals((byte)3, lvl[1]);
- assertEquals((byte)5, lvl[2]);
- }
+public final class TestLists {
+ @Test
+ public void testBasics() throws IOException {
+ try (HWPFDocument doc = openSampleFile("Lists.doc")) {
+ Range r = doc.getRange();
+
+ assertEquals(40, r.numParagraphs());
+ assertEquals("Heading Level 1\r", r.getParagraph(0).text());
+ assertEquals("This document has different lists in it for testing\r", r.getParagraph(1).text());
+ assertEquals("The end!\r", r.getParagraph(38).text());
+ assertEquals("\r", r.getParagraph(39).text());
+
+ assertEquals(0, r.getParagraph(0).getLvl());
+ assertEquals(9, r.getParagraph(1).getLvl());
+ assertEquals(9, r.getParagraph(38).getLvl());
+ assertEquals(9, r.getParagraph(39).getLvl());
+ }
+ }
+
+ @Test
+ public void testUnorderedLists() throws IOException {
+ try (HWPFDocument doc = openSampleFile("Lists.doc")) {
+ Range r = doc.getRange();
+ assertEquals(40, r.numParagraphs());
+
+ // Normal bullet points
+ assertEquals("This document has different lists in it for testing\r", r.getParagraph(1).text());
+ assertEquals("Unordered list 1\r", r.getParagraph(2).text());
+ assertEquals("UL 2\r", r.getParagraph(3).text());
+ assertEquals("UL 3\r", r.getParagraph(4).text());
+ assertEquals("Next up is an ordered list:\r", r.getParagraph(5).text());
+
+ assertEquals(9, r.getParagraph(1).getLvl());
+ assertEquals(9, r.getParagraph(2).getLvl());
+ assertEquals(9, r.getParagraph(3).getLvl());
+ assertEquals(9, r.getParagraph(4).getLvl());
+ assertEquals(9, r.getParagraph(5).getLvl());
+
+ assertEquals(0, r.getParagraph(1).getIlvl());
+ assertEquals(0, r.getParagraph(2).getIlvl());
+ assertEquals(0, r.getParagraph(3).getIlvl());
+ assertEquals(0, r.getParagraph(4).getIlvl());
+ assertEquals(0, r.getParagraph(5).getIlvl());
+
+ // Tick bullets
+ assertEquals("Now for an un-ordered list with a different bullet style:\r", r.getParagraph(9).text());
+ assertEquals("Tick 1\r", r.getParagraph(10).text());
+ assertEquals("Tick 2\r", r.getParagraph(11).text());
+ assertEquals("Multi-level un-ordered list:\r", r.getParagraph(12).text());
+
+ assertEquals(9, r.getParagraph(9).getLvl());
+ assertEquals(9, r.getParagraph(10).getLvl());
+ assertEquals(9, r.getParagraph(11).getLvl());
+ assertEquals(9, r.getParagraph(12).getLvl());
+
+ assertEquals(0, r.getParagraph(9).getIlvl());
+ assertEquals(0, r.getParagraph(10).getIlvl());
+ assertEquals(0, r.getParagraph(11).getIlvl());
+ assertEquals(0, r.getParagraph(12).getIlvl());
+ }
+ // TODO Test for tick not bullet
+ }
+
+ @Test
+ public void testOrderedLists() throws IOException {
+ try (HWPFDocument doc = openSampleFile("Lists.doc")) {
+ Range r = doc.getRange();
+ assertEquals(40, r.numParagraphs());
+
+ assertEquals("Next up is an ordered list:\r", r.getParagraph(5).text());
+ assertEquals("Ordered list 1\r", r.getParagraph(6).text());
+ assertEquals("OL 2\r", r.getParagraph(7).text());
+ assertEquals("OL 3\r", r.getParagraph(8).text());
+ assertEquals("Now for an un-ordered list with a different bullet style:\r", r.getParagraph(9).text());
+
+ assertEquals(9, r.getParagraph(5).getLvl());
+ assertEquals(9, r.getParagraph(6).getLvl());
+ assertEquals(9, r.getParagraph(7).getLvl());
+ assertEquals(9, r.getParagraph(8).getLvl());
+ assertEquals(9, r.getParagraph(9).getLvl());
+
+ assertEquals(0, r.getParagraph(5).getIlvl());
+ assertEquals(0, r.getParagraph(6).getIlvl());
+ assertEquals(0, r.getParagraph(7).getIlvl());
+ assertEquals(0, r.getParagraph(8).getIlvl());
+ assertEquals(0, r.getParagraph(9).getIlvl());
+ }
+ }
+
+ @Test
+ public void testMultiLevelLists() throws IOException {
+ try (HWPFDocument doc = openSampleFile("Lists.doc")) {
+ Range r = doc.getRange();
+ assertEquals(40, r.numParagraphs());
+
+ assertEquals("Multi-level un-ordered list:\r", r.getParagraph(12).text());
+ assertEquals("ML 1:1\r", r.getParagraph(13).text());
+ assertEquals("ML 1:2\r", r.getParagraph(14).text());
+ assertEquals("ML 2:1\r", r.getParagraph(15).text());
+ assertEquals("ML 2:2\r", r.getParagraph(16).text());
+ assertEquals("ML 2:3\r", r.getParagraph(17).text());
+ assertEquals("ML 3:1\r", r.getParagraph(18).text());
+ assertEquals("ML 4:1\r", r.getParagraph(19).text());
+ assertEquals("ML 5:1\r", r.getParagraph(20).text());
+ assertEquals("ML 5:2\r", r.getParagraph(21).text());
+ assertEquals("ML 2:4\r", r.getParagraph(22).text());
+ assertEquals("ML 1:3\r", r.getParagraph(23).text());
+ assertEquals("Multi-level ordered list:\r", r.getParagraph(24).text());
+ assertEquals("OL 1\r", r.getParagraph(25).text());
+ assertEquals("OL 2\r", r.getParagraph(26).text());
+ assertEquals("OL 2.1\r", r.getParagraph(27).text());
+ assertEquals("OL 2.2\r", r.getParagraph(28).text());
+ assertEquals("OL 2.2.1\r", r.getParagraph(29).text());
+ assertEquals("OL 2.2.2\r", r.getParagraph(30).text());
+ assertEquals("OL 2.2.2.1\r", r.getParagraph(31).text());
+ assertEquals("OL 2.2.3\r", r.getParagraph(32).text());
+ assertEquals("OL 3\r", r.getParagraph(33).text());
+ assertEquals("Finally we want some indents, to tell the difference\r", r.getParagraph(34).text());
+
+ for (int i = 12; i <= 34; i++) {
+ assertEquals(9, r.getParagraph(12).getLvl());
+ }
+ assertEquals(0, r.getParagraph(12).getIlvl());
+ assertEquals(0, r.getParagraph(13).getIlvl());
+ assertEquals(0, r.getParagraph(14).getIlvl());
+ assertEquals(1, r.getParagraph(15).getIlvl());
+ assertEquals(1, r.getParagraph(16).getIlvl());
+ assertEquals(1, r.getParagraph(17).getIlvl());
+ assertEquals(2, r.getParagraph(18).getIlvl());
+ assertEquals(3, r.getParagraph(19).getIlvl());
+ assertEquals(4, r.getParagraph(20).getIlvl());
+ assertEquals(4, r.getParagraph(21).getIlvl());
+ assertEquals(1, r.getParagraph(22).getIlvl());
+ assertEquals(0, r.getParagraph(23).getIlvl());
+ assertEquals(0, r.getParagraph(24).getIlvl());
+ assertEquals(0, r.getParagraph(25).getIlvl());
+ assertEquals(0, r.getParagraph(26).getIlvl());
+ assertEquals(1, r.getParagraph(27).getIlvl());
+ assertEquals(1, r.getParagraph(28).getIlvl());
+ assertEquals(2, r.getParagraph(29).getIlvl());
+ assertEquals(2, r.getParagraph(30).getIlvl());
+ assertEquals(3, r.getParagraph(31).getIlvl());
+ assertEquals(2, r.getParagraph(32).getIlvl());
+ assertEquals(0, r.getParagraph(33).getIlvl());
+ assertEquals(0, r.getParagraph(34).getIlvl());
+ }
+ }
+
+ @Test
+ public void testIndentedText() throws IOException {
+ try (HWPFDocument doc = openSampleFile("Lists.doc")) {
+ Range r = doc.getRange();
+
+ assertEquals(40, r.numParagraphs());
+ assertEquals("Finally we want some indents, to tell the difference\r", r.getParagraph(34).text());
+ assertEquals("Indented once\r", r.getParagraph(35).text());
+ assertEquals("Indented twice\r", r.getParagraph(36).text());
+ assertEquals("Indented three times\r", r.getParagraph(37).text());
+ assertEquals("The end!\r", r.getParagraph(38).text());
+
+ assertEquals(9, r.getParagraph(34).getLvl());
+ assertEquals(9, r.getParagraph(35).getLvl());
+ assertEquals(9, r.getParagraph(36).getLvl());
+ assertEquals(9, r.getParagraph(37).getLvl());
+ assertEquals(9, r.getParagraph(38).getLvl());
+ assertEquals(9, r.getParagraph(39).getLvl());
+
+ assertEquals(0, r.getParagraph(34).getIlvl());
+ assertEquals(0, r.getParagraph(35).getIlvl());
+ assertEquals(0, r.getParagraph(36).getIlvl());
+ assertEquals(0, r.getParagraph(37).getIlvl());
+ assertEquals(0, r.getParagraph(38).getIlvl());
+ assertEquals(0, r.getParagraph(39).getIlvl());
+ }
+
+ // TODO Test the indent
+ }
+
+ @Test
+ public void testWriteRead() throws IOException {
+ try (HWPFDocument doc = openSampleFile("Lists.doc");
+ HWPFDocument doc2 = HWPFTestDataSamples.writeOutAndReadBack(doc)) {
+
+ Range r = doc2.getRange();
+
+ // Check a couple at random
+ assertEquals(4, r.getParagraph(21).getIlvl());
+ assertEquals(1, r.getParagraph(22).getIlvl());
+ assertEquals(0, r.getParagraph(23).getIlvl());
+
+ // Try to read numCharacterRuns, see bug 50060
+ assertEquals(1, r.getParagraph(0).numCharacterRuns());
+ }
+ }
+
+ @Test
+ public void testSpecificNumberedOrderedListFeatures() throws IOException {
+ try (HWPFDocument doc = openSampleFile("Lists.doc")) {
+
+ Range r = doc.getRange();
+ //these are in the numbered ordered list
+ //26 = OL 2
+ //27 = OL 2.1
+ //28 = OL 2.2
+ //29 = OL 2.2.1
+ for (int i = 26; i < 30; i++) {
+ Paragraph p = r.getParagraph(i);
+ assertTrue(p.isInList());
+ HWPFList list = p.getList();
+ ListLevel level = list.getLVL((char) p.getIlvl());
+ assertFalse(level.isLegalNumbering());
+ assertEquals(-1, level.getRestart());
+ }
+ Paragraph p = r.getParagraph(26);
+ HWPFList list = p.getList();
+ ListLevel level = list.getLVL((char) p.getIlvl());
+ byte[] lvl = level.getLevelNumberingPlaceholderOffsets();
+
+ assertEquals((byte) 1, lvl[0]);
+ assertEquals((byte) 0, lvl[1]);
+
+ p = r.getParagraph(27);
+ list = p.getList();
+ level = list.getLVL((char) p.getIlvl());
+ lvl = level.getLevelNumberingPlaceholderOffsets();
+ assertEquals((byte) 1, lvl[0]);
+ assertEquals((byte) 3, lvl[1]);
+
+ p = r.getParagraph(29);
+ list = p.getList();
+ level = list.getLVL((char) p.getIlvl());
+ lvl = level.getLevelNumberingPlaceholderOffsets();
+
+ assertEquals((byte) 1, lvl[0]);
+ assertEquals((byte) 3, lvl[1]);
+ assertEquals((byte) 5, lvl[2]);
+ }
+ }
}
diff --git a/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestOfficeDrawings.java b/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestOfficeDrawings.java
index 1f222b6b27..2dd5737bd9 100644
--- a/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestOfficeDrawings.java
+++ b/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestOfficeDrawings.java
@@ -16,40 +16,34 @@
==================================================================== */
package org.apache.poi.hwpf.usermodel;
-import junit.framework.TestCase;
+import static org.apache.poi.hwpf.HWPFTestDataSamples.openSampleFile;
+import static org.junit.Assert.assertEquals;
import org.apache.poi.ddf.EscherComplexProperty;
import org.apache.poi.ddf.EscherContainerRecord;
import org.apache.poi.ddf.EscherOptRecord;
import org.apache.poi.hwpf.HWPFDocument;
-import org.apache.poi.hwpf.HWPFTestDataSamples;
import org.apache.poi.util.StringUtil;
+import org.junit.Test;
/**
* Test cases for {@link OfficeDrawing} and {@link OfficeDrawingsImpl} classes.
- *
- * @author Sergey Vladimirov (vlsergey {at} gmail {dot} com)
*/
-public class TestOfficeDrawings extends TestCase
-{
+public class TestOfficeDrawings {
/**
* Tests watermark text extraction
*/
- public void testWatermark() throws Exception
- {
- HWPFDocument hwpfDocument = HWPFTestDataSamples
- .openSampleFile( "watermark.doc" );
- OfficeDrawing drawing = hwpfDocument.getOfficeDrawingsHeaders()
- .getOfficeDrawings().iterator().next();
- EscherContainerRecord escherContainerRecord = drawing
- .getOfficeArtSpContainer();
+ @Test
+ public void testWatermark() throws Exception {
+ try (HWPFDocument hwpfDocument = openSampleFile("watermark.doc")) {
+ OfficeDrawing drawing = hwpfDocument.getOfficeDrawingsHeaders().getOfficeDrawings().iterator().next();
+ EscherContainerRecord escherContainerRecord = drawing.getOfficeArtSpContainer();
- EscherOptRecord officeArtFOPT = escherContainerRecord
- .getChildById( (short) 0xF00B );
- EscherComplexProperty gtextUNICODE = officeArtFOPT
- .lookup( 0x00c0 );
+ EscherOptRecord officeArtFOPT = escherContainerRecord.getChildById((short) 0xF00B);
+ EscherComplexProperty gtextUNICODE = officeArtFOPT.lookup(0x00c0);
- String text = StringUtil.getFromUnicodeLE(gtextUNICODE.getComplexData());
- assertEquals( "DRAFT CONTRACT\0", text );
+ String text = StringUtil.getFromUnicodeLE(gtextUNICODE.getComplexData());
+ assertEquals("DRAFT CONTRACT\0", text);
+ }
}
}
diff --git a/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestRangeDelete.java b/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestRangeDelete.java
index bf52606d31..012b4cbff1 100644
--- a/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestRangeDelete.java
+++ b/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestRangeDelete.java
@@ -17,223 +17,225 @@
package org.apache.poi.hwpf.usermodel;
+import static org.apache.poi.hwpf.HWPFTestDataSamples.openSampleFile;
+import static org.junit.Assert.assertEquals;
+
+import java.io.IOException;
+
import org.apache.poi.hwpf.HWPFDocument;
-import org.apache.poi.hwpf.HWPFTestDataSamples;
import org.apache.poi.hwpf.model.PAPX;
-
-import junit.framework.TestCase;
+import org.junit.Test;
/**
* Test to see if Range.delete() works even if the Range contains a
* CharacterRun that uses Unicode characters.
*/
-public final class TestRangeDelete extends TestCase {
+public final class TestRangeDelete {
// u201c and u201d are "smart-quotes"
- private final String introText =
+ private static final String introText =
"Introduction\r";
- private final String fillerText =
+ private static final String fillerText =
"${delete} This is an MS-Word 97 formatted document created using NeoOffice v. 2.2.4 Patch 0 (OpenOffice.org v. 2.2.1).\r";
- private final String originalText =
+ private static final String originalText =
"It is used to confirm that text delete works even if Unicode characters (such as \u201c\u2014\u201d (U+2014), \u201c\u2e8e\u201d (U+2E8E), or \u201c\u2714\u201d (U+2714)) are present. Everybody should be thankful to the ${organization} ${delete} and all the POI contributors for their assistance in this matter.\r";
- private final String lastText =
+ private static final String lastText =
"Thank you, ${organization} ${delete}!\r";
- private final String searchText = "${delete}";
- private final String expectedText1 = " This is an MS-Word 97 formatted document created using NeoOffice v. 2.2.4 Patch 0 (OpenOffice.org v. 2.2.1).\r";
- private final String expectedText2 =
+ private static final String searchText = "${delete}";
+ private static final String expectedText1 = " This is an MS-Word 97 formatted document created using NeoOffice v. 2.2.4 Patch 0 (OpenOffice.org v. 2.2.1).\r";
+ private static final String expectedText2 =
"It is used to confirm that text delete works even if Unicode characters (such as \u201c\u2014\u201d (U+2014), \u201c\u2e8e\u201d (U+2E8E), or \u201c\u2714\u201d (U+2714)) are present. Everybody should be thankful to the ${organization} and all the POI contributors for their assistance in this matter.\r";
- private final String expectedText3 = "Thank you, ${organization} !\r";
-
- private String illustrativeDocFile;
+ private static final String expectedText3 = "Thank you, ${organization} !\r";
- @Override
- protected void setUp() {
- illustrativeDocFile = "testRangeDelete.doc";
- }
+ private static final String illustrativeDocFile = "testRangeDelete.doc";
/**
* Test just opening the files
*/
- public void testOpen() {
-
- HWPFTestDataSamples.openSampleFile(illustrativeDocFile);
+ @Test
+ public void testOpen() throws IOException {
+ openSampleFile(illustrativeDocFile).close();
}
/**
* Test (more "confirm" than test) that we have the general structure that we expect to have.
*/
- public void testDocStructure() {
+ @Test
+ public void testDocStructure() throws IOException {
- HWPFDocument daDoc = HWPFTestDataSamples.openSampleFile(illustrativeDocFile);
- Range range;
- Section section;
- Paragraph para;
- PAPX paraDef;
+ try (HWPFDocument daDoc = openSampleFile(illustrativeDocFile)) {
+ Range range;
+ Section section;
+ Paragraph para;
+ PAPX paraDef;
- // First, check overall
- range = daDoc.getOverallRange();
- assertEquals(1, range.numSections());
- assertEquals(5, range.numParagraphs());
+ // First, check overall
+ range = daDoc.getOverallRange();
+ assertEquals(1, range.numSections());
+ assertEquals(5, range.numParagraphs());
- // Now, onto just the doc bit
- range = daDoc.getRange();
+ // Now, onto just the doc bit
+ range = daDoc.getRange();
- assertEquals(1, range.numSections());
- assertEquals(1, daDoc.getSectionTable().getSections().size());
- section = range.getSection(0);
+ assertEquals(1, range.numSections());
+ assertEquals(1, daDoc.getSectionTable().getSections().size());
+ section = range.getSection(0);
- assertEquals(5, section.numParagraphs());
+ assertEquals(5, section.numParagraphs());
- para = section.getParagraph(0);
- assertEquals(1, para.numCharacterRuns());
- assertEquals(introText, para.text());
+ para = section.getParagraph(0);
+ assertEquals(1, para.numCharacterRuns());
+ assertEquals(introText, para.text());
- para = section.getParagraph(1);
- assertEquals(5, para.numCharacterRuns());
- assertEquals(fillerText, para.text());
+ para = section.getParagraph(1);
+ assertEquals(5, para.numCharacterRuns());
+ assertEquals(fillerText, para.text());
- paraDef = daDoc.getParagraphTable().getParagraphs().get(2);
- assertEquals(132, paraDef.getStart());
- assertEquals(400, paraDef.getEnd());
+ paraDef = daDoc.getParagraphTable().getParagraphs().get(2);
+ assertEquals(132, paraDef.getStart());
+ assertEquals(400, paraDef.getEnd());
- para = section.getParagraph(2);
- assertEquals(5, para.numCharacterRuns());
- assertEquals(originalText, para.text());
+ para = section.getParagraph(2);
+ assertEquals(5, para.numCharacterRuns());
+ assertEquals(originalText, para.text());
- paraDef = daDoc.getParagraphTable().getParagraphs().get(3);
- assertEquals(400, paraDef.getStart());
- assertEquals(438, paraDef.getEnd());
+ paraDef = daDoc.getParagraphTable().getParagraphs().get(3);
+ assertEquals(400, paraDef.getStart());
+ assertEquals(438, paraDef.getEnd());
- para = section.getParagraph(3);
- assertEquals(1, para.numCharacterRuns());
- assertEquals(lastText, para.text());
+ para = section.getParagraph(3);
+ assertEquals(1, para.numCharacterRuns());
+ assertEquals(lastText, para.text());
- // Check things match on text length
- assertEquals(439, range.text().length());
- assertEquals(439, section.text().length());
- assertEquals(439,
- section.getParagraph(0).text().length() +
- section.getParagraph(1).text().length() +
- section.getParagraph(2).text().length() +
- section.getParagraph(3).text().length() +
- section.getParagraph(4).text().length()
- );
+ // Check things match on text length
+ assertEquals(439, range.text().length());
+ assertEquals(439, section.text().length());
+ assertEquals(439,
+ section.getParagraph(0).text().length() +
+ section.getParagraph(1).text().length() +
+ section.getParagraph(2).text().length() +
+ section.getParagraph(3).text().length() +
+ section.getParagraph(4).text().length()
+ );
+ }
}
/**
* Test that we can delete text (one instance) from our Range with Unicode text.
*/
- public void testRangeDeleteOne() {
+ @Test
+ public void testRangeDeleteOne() throws IOException {
+ try (HWPFDocument daDoc = openSampleFile(illustrativeDocFile)) {
- HWPFDocument daDoc = HWPFTestDataSamples.openSampleFile(illustrativeDocFile);
+ Range range = daDoc.getOverallRange();
+ assertEquals(1, range.numSections());
- Range range = daDoc.getOverallRange();
- assertEquals(1, range.numSections());
+ Section section = range.getSection(0);
+ assertEquals(5, section.numParagraphs());
- Section section = range.getSection(0);
- assertEquals(5, section.numParagraphs());
+ Paragraph para = section.getParagraph(2);
- Paragraph para = section.getParagraph(2);
+ String text = para.text();
+ assertEquals(originalText, text);
- String text = para.text();
- assertEquals(originalText, text);
+ int offset = text.indexOf(searchText);
+ assertEquals(192, offset);
- int offset = text.indexOf(searchText);
- assertEquals(192, offset);
+ int absOffset = para.getStartOffset() + offset;
+ Range subRange = new Range(absOffset, (absOffset + searchText.length()), para.getDocument());
- int absOffset = para.getStartOffset() + offset;
- Range subRange = new Range(absOffset, (absOffset + searchText.length()), para.getDocument());
+ assertEquals(searchText, subRange.text());
- assertEquals(searchText, subRange.text());
+ subRange.delete();
+ daDoc.getOverallRange().sanityCheck();
+ daDoc.getRange().sanityCheck();
- subRange.delete();
- daDoc.getOverallRange().sanityCheck();
- daDoc.getRange().sanityCheck();
-
- // we need to let the model re-calculate the Range before we evaluate it
- range = daDoc.getRange();
+ // we need to let the model re-calculate the Range before we evaluate it
+ range = daDoc.getRange();
- assertEquals(1, range.numSections());
- section = range.getSection(0);
+ assertEquals(1, range.numSections());
+ section = range.getSection(0);
- assertEquals(5, section.numParagraphs());
- para = section.getParagraph(2);
+ assertEquals(5, section.numParagraphs());
+ para = section.getParagraph(2);
- text = para.text();
- assertEquals(expectedText2, text);
+ text = para.text();
+ assertEquals(expectedText2, text);
- // this can lead to a StringBufferOutOfBoundsException, so we will add it
- // even though we don't have an assertion for it
- Range daRange = daDoc.getRange();
- daRange.sanityCheck();
- daRange.text();
+ // this can lead to a StringBufferOutOfBoundsException, so we will add it
+ // even though we don't have an assertion for it
+ Range daRange = daDoc.getRange();
+ daRange.sanityCheck();
+ daRange.text();
+ }
}
/**
* Test that we can delete text (all instances of) from our Range with Unicode text.
*/
- public void testRangeDeleteAll() {
-
- HWPFDocument daDoc = HWPFTestDataSamples.openSampleFile(illustrativeDocFile);
+ @Test
+ public void testRangeDeleteAll() throws IOException {
+ try (HWPFDocument daDoc = openSampleFile(illustrativeDocFile)) {
- Range range = daDoc.getRange();
- assertEquals(1, range.numSections());
+ Range range = daDoc.getRange();
+ assertEquals(1, range.numSections());
- Section section = range.getSection(0);
- assertEquals(5, section.numParagraphs());
+ Section section = range.getSection(0);
+ assertEquals(5, section.numParagraphs());
- Paragraph para = section.getParagraph(2);
+ Paragraph para = section.getParagraph(2);
- String text = para.text();
- assertEquals(originalText, text);
+ String text = para.text();
+ assertEquals(originalText, text);
- boolean keepLooking = true;
- while (keepLooking) {
- // Reload the range every time
- range = daDoc.getRange();
- int offset = range.text().indexOf(searchText);
- if (offset >= 0) {
+ boolean keepLooking = true;
+ while (keepLooking) {
+ // Reload the range every time
+ range = daDoc.getRange();
+ int offset = range.text().indexOf(searchText);
+ if (offset >= 0) {
- int absOffset = range.getStartOffset() + offset;
+ int absOffset = range.getStartOffset() + offset;
- Range subRange = new Range(
- absOffset, (absOffset + searchText.length()), range.getDocument());
+ Range subRange = new Range(
+ absOffset, (absOffset + searchText.length()), range.getDocument());
- assertEquals(searchText, subRange.text());
+ assertEquals(searchText, subRange.text());
- subRange.delete();
+ subRange.delete();
- } else {
- keepLooking = false;
+ } else {
+ keepLooking = false;
+ }
}
- }
- // we need to let the model re-calculate the Range before we use it
- range = daDoc.getRange();
+ // we need to let the model re-calculate the Range before we use it
+ range = daDoc.getRange();
- assertEquals(1, range.numSections());
- section = range.getSection(0);
+ assertEquals(1, range.numSections());
+ section = range.getSection(0);
- assertEquals(5, section.numParagraphs());
+ assertEquals(5, section.numParagraphs());
- para = section.getParagraph(0);
- text = para.text();
- assertEquals(introText, text);
+ para = section.getParagraph(0);
+ text = para.text();
+ assertEquals(introText, text);
- para = section.getParagraph(1);
- text = para.text();
- assertEquals(expectedText1, text);
+ para = section.getParagraph(1);
+ text = para.text();
+ assertEquals(expectedText1, text);
- para = section.getParagraph(2);
- text = para.text();
- assertEquals(expectedText2, text);
+ para = section.getParagraph(2);
+ text = para.text();
+ assertEquals(expectedText2, text);
- para = section.getParagraph(3);
- text = para.text();
- assertEquals(expectedText3, text);
+ para = section.getParagraph(3);
+ text = para.text();
+ assertEquals(expectedText3, text);
+ }
}
}
diff --git a/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestRangeInsertion.java b/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestRangeInsertion.java
index 18ae0e7ac5..9271ef2c64 100644
--- a/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestRangeInsertion.java
+++ b/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestRangeInsertion.java
@@ -17,10 +17,13 @@
package org.apache.poi.hwpf.usermodel;
-import junit.framework.TestCase;
+import static org.apache.poi.hwpf.HWPFTestDataSamples.openSampleFile;
+import static org.junit.Assert.assertEquals;
+
+import java.io.IOException;
import org.apache.poi.hwpf.HWPFDocument;
-import org.apache.poi.hwpf.HWPFTestDataSamples;
+import org.junit.Test;
/**
* Test to see if Range.insertBefore() works even if the Range contains a
@@ -28,63 +31,58 @@ import org.apache.poi.hwpf.HWPFTestDataSamples;
*
* TODO - re-enable me when unicode paragraph stuff is fixed!
*/
-public final class TestRangeInsertion extends TestCase {
+public final class TestRangeInsertion {
// u201c and u201d are "smart-quotes"
- private final String originalText =
+ private static final String originalText =
"It is used to confirm that text insertion works even if Unicode characters (such as \u201c\u2014\u201d (U+2014), \u201c\u2e8e\u201d (U+2E8E), or \u201c\u2714\u201d (U+2714)) are present.\r";
- private final String textToInsert = "Look at me! I'm cool! ";
- private final int insertionPoint = 122;
-
- private String illustrativeDocFile;
+ private static final String textToInsert = "Look at me! I'm cool! ";
+ private static final int insertionPoint = 122;
- @Override
- protected void setUp() {
- illustrativeDocFile = "testRangeInsertion.doc";
- }
+ private static final String illustrativeDocFile = "testRangeInsertion.doc";
/**
* Test just opening the files
*/
- public void testOpen() {
-
- HWPFTestDataSamples.openSampleFile(illustrativeDocFile);
+ @Test
+ public void testOpen() throws IOException {
+ openSampleFile(illustrativeDocFile).close();
}
/**
* Test (more "confirm" than test) that we have the general structure that we expect to have.
*/
- public void testDocStructure() {
+ @Test
+ public void testDocStructure() throws IOException {
+ try (HWPFDocument daDoc = openSampleFile(illustrativeDocFile)) {
- HWPFDocument daDoc = HWPFTestDataSamples.openSampleFile(illustrativeDocFile);
+ Range range = daDoc.getRange();
- Range range = daDoc.getRange();
+ assertEquals(1, range.numSections());
+ Section section = range.getSection(0);
- assertEquals(1, range.numSections());
- Section section = range.getSection(0);
+ assertEquals(3, section.numParagraphs());
+ Paragraph para = section.getParagraph(2);
+ assertEquals(originalText, para.text());
- assertEquals(3, section.numParagraphs());
- Paragraph para = section.getParagraph(2);
- assertEquals(originalText, para.text());
+ assertEquals(3, para.numCharacterRuns());
+ String text =
+ para.getCharacterRun(0).text() +
+ para.getCharacterRun(1).text() +
+ para.getCharacterRun(2).text();
- assertEquals(3, para.numCharacterRuns());
- String text =
- para.getCharacterRun(0).text() +
- para.getCharacterRun(1).text() +
- para.getCharacterRun(2).text()
- ;
+ assertEquals(originalText, text);
- assertEquals(originalText, text);
-
- assertEquals(insertionPoint, para.getStartOffset());
+ assertEquals(insertionPoint, para.getStartOffset());
+ }
}
/**
* Test that we can insert text in our CharacterRun with Unicode text.
*/
- public void testRangeInsertion() {
-
- HWPFDocument daDoc = HWPFTestDataSamples.openSampleFile(illustrativeDocFile);
+ @Test
+ public void testRangeInsertion() throws IOException {
+ try (HWPFDocument daDoc = openSampleFile(illustrativeDocFile)) {
// if (false) { // TODO - delete or resurrect this code
// Range range = daDoc.getRange();
@@ -96,28 +94,26 @@ public final class TestRangeInsertion extends TestCase {
// System.out.println(text);
// }
- Range range = new Range(insertionPoint, (insertionPoint + 2), daDoc);
- range.insertBefore(textToInsert);
-
- // we need to let the model re-calculate the Range before we evaluate it
- range = daDoc.getRange();
+ Range range = new Range(insertionPoint, (insertionPoint + 2), daDoc);
+ range.insertBefore(textToInsert);
- assertEquals(1, range.numSections());
- Section section = range.getSection(0);
+ // we need to let the model re-calculate the Range before we evaluate it
+ range = daDoc.getRange();
- assertEquals(3, section.numParagraphs());
- Paragraph para = section.getParagraph(2);
- assertEquals((textToInsert + originalText), para.text());
+ assertEquals(1, range.numSections());
+ Section section = range.getSection(0);
- assertEquals(3, para.numCharacterRuns());
- String text =
- para.getCharacterRun(0).text() +
- para.getCharacterRun(1).text() +
- para.getCharacterRun(2).text()
- ;
+ assertEquals(3, section.numParagraphs());
+ Paragraph para = section.getParagraph(2);
+ assertEquals((textToInsert + originalText), para.text());
- // System.out.println(text);
+ assertEquals(3, para.numCharacterRuns());
+ String text =
+ para.getCharacterRun(0).text() +
+ para.getCharacterRun(1).text() +
+ para.getCharacterRun(2).text();
- assertEquals((textToInsert + originalText), text);
+ assertEquals((textToInsert + originalText), text);
+ }
}
}
diff --git a/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestRangeProperties.java b/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestRangeProperties.java
index 0865189a22..423aa9081c 100644
--- a/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestRangeProperties.java
+++ b/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestRangeProperties.java
@@ -17,21 +17,25 @@
package org.apache.poi.hwpf.usermodel;
-import java.util.List;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
-import junit.framework.TestCase;
+import java.util.List;
import org.apache.poi.hwpf.HWPFDocument;
import org.apache.poi.hwpf.HWPFTestDataSamples;
import org.apache.poi.hwpf.model.PAPX;
import org.apache.poi.hwpf.model.StyleSheet;
+import org.junit.Before;
+import org.junit.Test;
/**
* Tests to ensure that our ranges end up with
* the right text in them, and the right font/styling
* properties applied to them.
*/
-public final class TestRangeProperties extends TestCase {
+public final class TestRangeProperties {
private static final char page_break = (char)12;
private static final String u_page_1 =
@@ -64,13 +68,13 @@ public final class TestRangeProperties extends TestCase {
private HWPFDocument u;
private HWPFDocument a;
- @Override
- protected void setUp() {
+ @Before
+ public void setUp() {
u = HWPFTestDataSamples.openSampleFile("HeaderFooterUnicode.doc");
a = HWPFTestDataSamples.openSampleFile("SampleDoc.doc");
}
-
+ @Test
public void testAsciiTextParagraphs() {
Range r = a.getRange();
assertEquals(
@@ -126,6 +130,7 @@ public final class TestRangeProperties extends TestCase {
assertEquals( p2_parts[2] + "\r", r.getParagraph( 7 ).text() );
}
+ @Test
public void testAsciiStyling() {
Range r = a.getRange();
@@ -168,10 +173,10 @@ public final class TestRangeProperties extends TestCase {
* Tests the raw definitions of the paragraphs of
* a unicode document
*/
+ @Test
public void testUnicodeParagraphDefinitions() {
Range r = u.getRange();
String[] p1_parts = u_page_1.split("\r");
- String[] p2_parts = u_page_2.split("\r");
assertEquals(
u_page_1 + page_break + "\r" + u_page_2,
@@ -204,7 +209,7 @@ public final class TestRangeProperties extends TestCase {
// Check that the last paragraph ends where it should do
assertEquals(531, u.getOverallRange().text().length());
PAPX pLast = pDefs.get(34);
- // assertEquals(530, pLast.getEnd());
+ assertEquals(530, pLast.getEnd());
// Only care about the first few really though
PAPX p0 = pDefs.get(0);
@@ -261,6 +266,7 @@ public final class TestRangeProperties extends TestCase {
/**
* Tests the paragraph text of a unicode document
*/
+ @Test
public void testUnicodeTextParagraphs() {
Range r = u.getRange();
assertEquals(
@@ -296,6 +302,8 @@ public final class TestRangeProperties extends TestCase {
assertEquals( "\r", r.getParagraph( 11 ).text() );
assertEquals( p2_parts[0] + "\r", r.getParagraph( 12 ).text() );
}
+
+ @Test
public void testUnicodeStyling() {
Range r = u.getRange();
String[] p1_parts = u_page_1.split("\r");
diff --git a/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestRangeReplacement.java b/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestRangeReplacement.java
index 370c4f3f41..7e4f1584f5 100644
--- a/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestRangeReplacement.java
+++ b/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestRangeReplacement.java
@@ -17,10 +17,13 @@
package org.apache.poi.hwpf.usermodel;
-import junit.framework.TestCase;
+import static org.apache.poi.hwpf.HWPFTestDataSamples.openSampleFile;
+import static org.junit.Assert.assertEquals;
+
+import java.io.IOException;
import org.apache.poi.hwpf.HWPFDocument;
-import org.apache.poi.hwpf.HWPFTestDataSamples;
+import org.junit.Test;
/**
* Test to see if Range.replaceText() works even if the Range contains a
@@ -28,125 +31,126 @@ import org.apache.poi.hwpf.HWPFTestDataSamples;
*
* TODO - re-enable me when unicode paragraph stuff is fixed!
*/
-public final class TestRangeReplacement extends TestCase {
+public final class TestRangeReplacement {
// u201c and u201d are "smart-quotes"
- private final String originalText =
+ private static final String originalText =
"It is used to confirm that text replacement works even if Unicode characters (such as \u201c\u2014\u201d (U+2014), \u201c\u2e8e\u201d (U+2E8E), or \u201c\u2714\u201d (U+2714)) are present. Everybody should be thankful to the ${organization} and all the POI contributors for their assistance in this matter.\r";
- private final String searchText = "${organization}";
- private final String replacementText = "Apache Software Foundation";
- private final String expectedText2 =
+ private static final String searchText = "${organization}";
+ private static final String replacementText = "Apache Software Foundation";
+ private static final String expectedText2 =
"It is used to confirm that text replacement works even if Unicode characters (such as \u201c\u2014\u201d (U+2014), \u201c\u2e8e\u201d (U+2E8E), or \u201c\u2714\u201d (U+2714)) are present. Everybody should be thankful to the Apache Software Foundation and all the POI contributors for their assistance in this matter.\r";
- private final String expectedText3 = "Thank you, Apache Software Foundation!\r";
+ private static final String expectedText3 = "Thank you, Apache Software Foundation!\r";
- private final String illustrativeDocFile = "testRangeReplacement.doc";
+ private static final String illustrativeDocFile = "testRangeReplacement.doc";
/**
* Test just opening the files
*/
public void testOpen() {
-
- HWPFTestDataSamples.openSampleFile(illustrativeDocFile);
+ openSampleFile(illustrativeDocFile);
}
/**
* Test (more "confirm" than test) that we have the general structure that we expect to have.
*/
- public void testDocStructure() {
-
- HWPFDocument daDoc = HWPFTestDataSamples.openSampleFile(illustrativeDocFile);
-
- Range range = daDoc.getRange();
- assertEquals(414, range.text().length());
-
- assertEquals(1, range.numSections());
- Section section = range.getSection(0);
- assertEquals(414, section.text().length());
-
- assertEquals(5, section.numParagraphs());
- Paragraph para = section.getParagraph(2);
-
- assertEquals(5, para.numCharacterRuns());
- String text =
- para.getCharacterRun(0).text() +
- para.getCharacterRun(1).text() +
- para.getCharacterRun(2).text() +
- para.getCharacterRun(3).text() +
- para.getCharacterRun(4).text()
- ;
-
- assertEquals(originalText, text);
+ @Test
+ public void testDocStructure() throws IOException {
+ try (HWPFDocument daDoc = openSampleFile(illustrativeDocFile)) {
+
+ Range range = daDoc.getRange();
+ assertEquals(414, range.text().length());
+
+ assertEquals(1, range.numSections());
+ Section section = range.getSection(0);
+ assertEquals(414, section.text().length());
+
+ assertEquals(5, section.numParagraphs());
+ Paragraph para = section.getParagraph(2);
+
+ assertEquals(5, para.numCharacterRuns());
+ String text =
+ para.getCharacterRun(0).text() +
+ para.getCharacterRun(1).text() +
+ para.getCharacterRun(2).text() +
+ para.getCharacterRun(3).text() +
+ para.getCharacterRun(4).text();
+
+ assertEquals(originalText, text);
+ }
}
/**
* Test that we can replace text in our Range with Unicode text.
*/
- public void testRangeReplacementOne() {
+ @Test
+ public void testRangeReplacementOne() throws IOException {
+ try (HWPFDocument daDoc = openSampleFile(illustrativeDocFile)) {
- HWPFDocument daDoc = HWPFTestDataSamples.openSampleFile(illustrativeDocFile);
+ // Has one section
+ Range range = daDoc.getRange();
+ assertEquals(1, range.numSections());
- // Has one section
- Range range = daDoc.getRange();
- assertEquals(1, range.numSections());
+ // The first section has 5 paragraphs
+ Section section = range.getSection(0);
+ assertEquals(5, section.numParagraphs());
- // The first section has 5 paragraphs
- Section section = range.getSection(0);
- assertEquals(5, section.numParagraphs());
-
- // Change some text
- Paragraph para = section.getParagraph(2);
+ // Change some text
+ Paragraph para = section.getParagraph(2);
- String text = para.text();
- assertEquals(originalText, text);
+ String text = para.text();
+ assertEquals(originalText, text);
- int offset = text.indexOf(searchText);
- assertEquals(181, offset);
+ int offset = text.indexOf(searchText);
+ assertEquals(181, offset);
- para.replaceText(searchText, replacementText, offset);
+ para.replaceText(searchText, replacementText, offset);
- // Ensure we still have one section, 5 paragraphs
- assertEquals(1, range.numSections());
- section = range.getSection(0);
+ // Ensure we still have one section, 5 paragraphs
+ assertEquals(1, range.numSections());
+ section = range.getSection(0);
- assertEquals(5, section.numParagraphs());
- para = section.getParagraph(2);
+ assertEquals(5, section.numParagraphs());
+ para = section.getParagraph(2);
- // Ensure the text is what we should now have
- text = para.text();
- assertEquals(expectedText2, text);
+ // Ensure the text is what we should now have
+ text = para.text();
+ assertEquals(expectedText2, text);
+ }
}
/**
* Test that we can replace text in our Range with Unicode text.
*/
- public void testRangeReplacementAll() {
-
- HWPFDocument daDoc = HWPFTestDataSamples.openSampleFile(illustrativeDocFile);
+ @Test
+ public void testRangeReplacementAll() throws IOException {
+ try (HWPFDocument daDoc = openSampleFile(illustrativeDocFile)) {
- Range range = daDoc.getRange();
- assertEquals(1, range.numSections());
+ Range range = daDoc.getRange();
+ assertEquals(1, range.numSections());
- Section section = range.getSection(0);
- assertEquals(5, section.numParagraphs());
+ Section section = range.getSection(0);
+ assertEquals(5, section.numParagraphs());
- Paragraph para = section.getParagraph(2);
+ Paragraph para = section.getParagraph(2);
- String text = para.text();
- assertEquals(originalText, text);
+ String text = para.text();
+ assertEquals(originalText, text);
- range.replaceText(searchText, replacementText);
+ range.replaceText(searchText, replacementText);
- assertEquals(1, range.numSections());
- section = range.getSection(0);
- assertEquals(5, section.numParagraphs());
+ assertEquals(1, range.numSections());
+ section = range.getSection(0);
+ assertEquals(5, section.numParagraphs());
- para = section.getParagraph(2);
- text = para.text();
- assertEquals(expectedText2, text);
+ para = section.getParagraph(2);
+ text = para.text();
+ assertEquals(expectedText2, text);
- para = section.getParagraph(3);
- text = para.text();
- assertEquals(expectedText3, text);
+ para = section.getParagraph(3);
+ text = para.text();
+ assertEquals(expectedText3, text);
+ }
}
}