You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ki...@apache.org on 2019/12/27 23:00:20 UTC
svn commit: r1872041 [5/23] - in /poi/trunk/src:
excelant/testcases/org/apache/poi/ss/examples/formula/
excelant/testcases/org/apache/poi/ss/excelant/
excelant/testcases/org/apache/poi/ss/excelant/util/
java/org/apache/poi/hssf/record/aggregates/ java/...
Modified: poi/trunk/src/scratchpad/testcases/org/apache/poi/hsmf/Test7BitCodepage.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hsmf/Test7BitCodepage.java?rev=1872041&r1=1872040&r2=1872041&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hsmf/Test7BitCodepage.java (original)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hsmf/Test7BitCodepage.java Fri Dec 27 23:00:13 2019
@@ -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 exte
/**
* 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 exte
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());
Modified: poi/trunk/src/scratchpad/testcases/org/apache/poi/hsmf/TestBasics.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hsmf/TestBasics.java?rev=1872041&r1=1872040&r2=1872041&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hsmf/TestBasics.java (original)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hsmf/TestBasics.java Fri Dec 27 23:00:13 2019
@@ -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 Te
/**
* 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 Te
/**
* 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 Te
/**
* 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 Te
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 Te
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 Te
/**
* 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 Te
* 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 Te
attachments.setReturnNullOnMissingChunk(true);
assertNull(attachments.getHtmlBody());
-
+
attachments.setReturnNullOnMissingChunk(false);
-
+
try {
attachments.getHtmlBody();
fail("expected ChunkNotFoundException");
@@ -181,6 +191,7 @@ public final class TestBasics extends Te
* 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 Te
} 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());
Modified: poi/trunk/src/scratchpad/testcases/org/apache/poi/hsmf/TestBlankFileRead.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hsmf/TestBlankFileRead.java?rev=1872041&r1=1872040&r2=1872041&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hsmf/TestBlankFileRead.java (original)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hsmf/TestBlankFileRead.java Fri Dec 27 23:00:13 2019
@@ -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();
}
}
Modified: poi/trunk/src/scratchpad/testcases/org/apache/poi/hsmf/TestMessageSubmissionChunk.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hsmf/TestMessageSubmissionChunk.java?rev=1872041&r1=1872040&r2=1872041&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hsmf/TestMessageSubmissionChunk.java (original)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hsmf/TestMessageSubmissionChunk.java Fri Dec 27 23:00:13 2019
@@ -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);
}
}
Modified: poi/trunk/src/scratchpad/testcases/org/apache/poi/hsmf/TestMessageSubmissionChunkY2KRead.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hsmf/TestMessageSubmissionChunkY2KRead.java?rev=1872041&r1=1872040&r2=1872041&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hsmf/TestMessageSubmissionChunkY2KRead.java (original)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hsmf/TestMessageSubmissionChunkY2KRead.java Fri Dec 27 23:00:13 2019
@@ -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);
}
}
Modified: poi/trunk/src/scratchpad/testcases/org/apache/poi/hsmf/TestOutlook30FileRead.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hsmf/TestOutlook30FileRead.java?rev=1872041&r1=1872040&r2=1872041&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hsmf/TestOutlook30FileRead.java (original)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hsmf/TestOutlook30FileRead.java Fri Dec 27 23:00:13 2019
@@ -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
/**
* 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
/**
* 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();
Modified: poi/trunk/src/scratchpad/testcases/org/apache/poi/hsmf/TestSimpleFileRead.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hsmf/TestSimpleFileRead.java?rev=1872041&r1=1872040&r2=1872041&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hsmf/TestSimpleFileRead.java (original)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hsmf/TestSimpleFileRead.java Fri Dec 27 23:00:13 2019
@@ -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[]{
Modified: poi/trunk/src/scratchpad/testcases/org/apache/poi/hsmf/datatypes/TestChunkData.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hsmf/datatypes/TestChunkData.java?rev=1872041&r1=1872040&r2=1872041&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hsmf/datatypes/TestChunkData.java (original)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hsmf/datatypes/TestChunkData.java Fri Dec 27 23:00:13 2019
@@ -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
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
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);
Modified: poi/trunk/src/scratchpad/testcases/org/apache/poi/hsmf/datatypes/TestMAPIProperty.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hsmf/datatypes/TestMAPIProperty.java?rev=1872041&r1=1872040&r2=1872041&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hsmf/datatypes/TestMAPIProperty.java (original)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hsmf/datatypes/TestMAPIProperty.java Fri Dec 27 23:00:13 2019
@@ -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));
Modified: poi/trunk/src/scratchpad/testcases/org/apache/poi/hsmf/datatypes/TestSorters.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hsmf/datatypes/TestSorters.java?rev=1872041&r1=1872040&r2=1872041&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hsmf/datatypes/TestSorters.java (original)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hsmf/datatypes/TestSorters.java Fri Dec 27 23:00:13 2019
@@ -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 T
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 T
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 T
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"),
Modified: poi/trunk/src/scratchpad/testcases/org/apache/poi/hsmf/datatypes/TestTypes.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hsmf/datatypes/TestTypes.java?rev=1872041&r1=1872040&r2=1872041&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hsmf/datatypes/TestTypes.java (original)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hsmf/datatypes/TestTypes.java Fri Dec 27 23:00:13 2019
@@ -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());
Modified: poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/TestHWPFPictures.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/TestHWPFPictures.java?rev=1872041&r1=1872040&r2=1872041&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/TestHWPFPictures.java (original)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/TestHWPFPictures.java Fri Dec 27 23:00:13 2019
@@ -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 exte
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 exte
/**
* Test just opening the files
*/
+ @Test
public void testOpen() {
HWPFTestDataSamples.openSampleFile(docAFile);
HWPFTestDataSamples.openSampleFile(docBFile);
@@ -76,6 +79,7 @@ public final class TestHWPFPictures exte
/**
* 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 exte
/**
* 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 exte
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 exte
// 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 exte
* 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 exte
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) {
Modified: poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/TestHWPFRangeParts.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/TestHWPFRangeParts.java?rev=1872041&r1=1872040&r2=1872041&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/TestHWPFRangeParts.java (original)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/TestHWPFRangeParts.java Fri Dec 27 23:00:13 2019
@@ -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 ex
*/
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 ex
* 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 ex
a_page_2,
r.text()
);
-
+
r = doc.getHeaderStoryRange();
assertEquals(
headerDef +
@@ -127,7 +129,7 @@ public final class TestHWPFRangeParts ex
endHeaderFooter,
r.text()
);
-
+
r = doc.getOverallRange();
assertEquals(
a_page_1 +
@@ -141,7 +143,7 @@ public final class TestHWPFRangeParts ex
"\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 ex
}
}
+ @Test
public void testContentsUnicode() {
Range r;
Modified: poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/converter/AbstractWordUtilsTest.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/converter/AbstractWordUtilsTest.java?rev=1872041&r1=1872040&r2=1872041&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/converter/AbstractWordUtilsTest.java (original)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/converter/AbstractWordUtilsTest.java Fri Dec 27 23:00:13 2019
@@ -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();
Modified: poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/converter/TestNumberFormatter.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/converter/TestNumberFormatter.java?rev=1872041&r1=1872040&r2=1872041&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/converter/TestNumberFormatter.java (original)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/converter/TestNumberFormatter.java Fri Dec 27 23:00:13 2019
@@ -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
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
Modified: poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/converter/TestWordToTextConverter.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/converter/TestWordToTextConverter.java?rev=1872041&r1=1872040&r2=1872041&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/converter/TestWordToTextConverter.java (original)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/converter/TestWordToTextConverter.java Fri Dec 27 23:00:13 2019
@@ -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);
+ }
}
}
Modified: poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestBookmarksTables.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestBookmarksTables.java?rev=1872041&r1=1872040&r2=1872041&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestBookmarksTables.java (original)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestBookmarksTables.java Fri Dec 27 23:00:13 2019
@@ -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());
+ }
}
}
Modified: poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestCHPBinTable.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestCHPBinTable.java?rev=1872041&r1=1872040&r2=1872041&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestCHPBinTable.java (original)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestCHPBinTable.java Fri Dec 27 23:00:13 2019
@@ -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();
}
}
Modified: poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestNotesTables.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestNotesTables.java?rev=1872041&r1=1872040&r2=1872041&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestNotesTables.java (original)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestNotesTables.java Fri Dec 27 23:00:13 2019
@@ -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
Modified: poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestPlexOfCps.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestPlexOfCps.java?rev=1872041&r1=1872040&r2=1872041&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestPlexOfCps.java (original)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestPlexOfCps.java Fri Dec 27 23:00:13 2019
@@ -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();
}
}
Modified: poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestSectionTable.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestSectionTable.java?rev=1872041&r1=1872040&r2=1872041&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestSectionTable.java (original)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestSectionTable.java Fri Dec 27 23:00:13 2019
@@ -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();
}
}
Modified: poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/model/types/LFOLVLBaseAbstractTypeTest.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/model/types/LFOLVLBaseAbstractTypeTest.java?rev=1872041&r1=1872040&r2=1872041&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/model/types/LFOLVLBaseAbstractTypeTest.java (original)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/model/types/LFOLVLBaseAbstractTypeTest.java Fri Dec 27 23:00:13 2019
@@ -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() );
}
Modified: poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/model/types/LVLFAbstractTypeTest.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/model/types/LVLFAbstractTypeTest.java?rev=1872041&r1=1872040&r2=1872041&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/model/types/LVLFAbstractTypeTest.java (original)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/model/types/LVLFAbstractTypeTest.java Fri Dec 27 23:00:13 2019
@@ -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() );
}
Modified: poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/sprm/TableSprmUncompressorTest.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/sprm/TableSprmUncompressorTest.java?rev=1872041&r1=1872040&r2=1872041&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/sprm/TableSprmUncompressorTest.java (original)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/sprm/TableSprmUncompressorTest.java Fri Dec 27 23:00:13 2019
@@ -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,
Modified: poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/sprm/TestSprms.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/sprm/TestSprms.java?rev=1872041&r1=1872040&r2=1872041&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/sprm/TestSprms.java (original)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/sprm/TestSprms.java Fri Dec 27 23:00:13 2019
@@ -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());
+ }
+ }
}
}
Modified: poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestBorderCode.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestBorderCode.java?rev=1872041&r1=1872040&r2=1872041&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestBorderCode.java (original)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestBorderCode.java Fri Dec 27 23:00:13 2019
@@ -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 extend
fail("Expected paragraph not found");
// should never come here
- throw null;
+ return null;
}
}
Modified: poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestBug49820.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestBug49820.java?rev=1872041&r1=1872040&r2=1872041&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestBug49820.java (original)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestBug49820.java Fri Dec 27 23:00:13 2019
@@ -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) {
Modified: poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestBug50075.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestBug50075.java?rev=1872041&r1=1872040&r2=1872041&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestBug50075.java (original)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestBug50075.java Fri Dec 27 23:00:13 2019
@@ -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 extends TestCase
-{
+public class TestBug50075 {
- 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());
+ }
}
-
+
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org