diff options
author | Javen O'Neal <onealj@apache.org> | 2017-04-19 23:51:03 +0000 |
---|---|---|
committer | Javen O'Neal <onealj@apache.org> | 2017-04-19 23:51:03 +0000 |
commit | fc23277dd4c598fc1dec936fe9bd8ace2c808ce6 (patch) | |
tree | d621dcdc33391a9a1ad1f99091a22e3b69640d7d /src/scratchpad | |
parent | 6971b1ee60c96b979e2eb8de4129791cd0520750 (diff) | |
download | poi-fc23277dd4c598fc1dec936fe9bd8ace2c808ce6.tar.gz poi-fc23277dd4c598fc1dec936fe9bd8ace2c808ce6.zip |
Use assertContains instead of assertTrue(text.contains) for better error messages on failure
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1792007 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/scratchpad')
4 files changed, 61 insertions, 69 deletions
diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/extractor/TestExtractor.java b/src/scratchpad/testcases/org/apache/poi/hslf/extractor/TestExtractor.java index d62e954842..36332259e4 100644 --- a/src/scratchpad/testcases/org/apache/poi/hslf/extractor/TestExtractor.java +++ b/src/scratchpad/testcases/org/apache/poi/hslf/extractor/TestExtractor.java @@ -19,6 +19,7 @@ package org.apache.poi.hslf.extractor; import static org.apache.poi.POITestCase.assertContains; import static org.apache.poi.POITestCase.assertContainsIgnoreCase; +import static org.apache.poi.POITestCase.assertNotContained; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; @@ -160,7 +161,7 @@ public final class TestExtractor { assertEquals(nText.length(), 0); // Slide records were fine - assertTrue(text.startsWith("Using Disease Surveillance and Response")); + assertContains(text, "Using Disease Surveillance and Response"); ppe.close(); } @@ -347,10 +348,10 @@ public final class TestExtractor { // Enable, shows up ppe1.setMasterByDefault(true); text = ppe1.getText(); - assertTrue(text.contains("Text that I added to the master slide")); + assertContains(text, "Text that I added to the master slide"); // Make sure placeholder text does not come out - assertFalse(text.contains("Click to edit Master")); + assertNotContained(text, "Click to edit Master"); ppe1.close(); // Now with another file only containing master text diff --git a/src/scratchpad/testcases/org/apache/poi/hwpf/extractor/TestWordExtractor.java b/src/scratchpad/testcases/org/apache/poi/hwpf/extractor/TestWordExtractor.java index f13daf326d..90270cd18a 100644 --- a/src/scratchpad/testcases/org/apache/poi/hwpf/extractor/TestWordExtractor.java +++ b/src/scratchpad/testcases/org/apache/poi/hwpf/extractor/TestWordExtractor.java @@ -18,6 +18,7 @@ package org.apache.poi.hwpf.extractor; 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.assertNotNull; import static org.junit.Assert.assertTrue; @@ -265,18 +266,18 @@ public final class TestWordExtractor { } @Test - public void testWord95() throws Exception { - // Can work with the special one + public void testWord95() throws Exception { + // Can work with the special one InputStream is = docTests.openResourceAsStream("Word95.doc"); - Word6Extractor w6e = new Word6Extractor(is); - is.close(); - - String text = w6e.getText(); - - assertTrue(text.contains("The quick brown fox jumps over the lazy dog")); - assertTrue(text.contains("Paragraph 2")); - assertTrue(text.contains("Paragraph 3. Has some RED text and some BLUE BOLD text in it")); - assertTrue(text.contains("Last (4th) paragraph")); + Word6Extractor w6e = new Word6Extractor(is); + is.close(); + + String text = w6e.getText(); + + assertContains(text, "The quick brown fox jumps over the lazy dog"); + assertContains(text, "Paragraph 2"); + assertContains(text, "Paragraph 3. Has some RED text and some BLUE BOLD text in it"); + assertContains(text, "Last (4th) paragraph"); String[] tp = w6e.getParagraphText(); assertEquals(7, tp.length); @@ -288,8 +289,8 @@ public final class TestWordExtractor { assertEquals("\r\n", tp[5]); assertEquals("Last (4th) paragraph.\r\n", tp[6]); w6e.close(); - } - + } + @Test(expected=OldWordFileFormatException.class) public void testWord6_WordExtractor() throws IOException { // Too old for the default @@ -297,27 +298,27 @@ public final class TestWordExtractor { } @Test - public void testWord6() throws Exception { + public void testWord6() throws Exception { InputStream is = docTests.openResourceAsStream("Word6.doc"); Word6Extractor w6e = new Word6Extractor(is); is.close(); String text = w6e.getText(); - assertTrue(text.contains("The quick brown fox jumps over the lazy dog")); + assertContains(text, "The quick brown fox jumps over the lazy dog"); String[] tp = w6e.getParagraphText(); assertEquals(1, tp.length); assertEquals("The quick brown fox jumps over the lazy dog\r\n", tp[0]); w6e.close(); - } + } @Test public void testFastSaved() throws Exception { WordExtractor extractor = openExtractor("rasp.doc"); String text = extractor.getText(); - assertTrue(text.contains("\u0425\u0425\u0425\u0425\u0425")); - assertTrue(text.contains("\u0423\u0423\u0423\u0423\u0423")); + assertContains(text, "\u0425\u0425\u0425\u0425\u0425"); + assertContains(text, "\u0423\u0423\u0423\u0423\u0423"); extractor.close(); } @@ -328,7 +329,7 @@ public final class TestWordExtractor { String text = extractor.getText(); - assertTrue(text.startsWith("\u041f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435")); + assertStartsWith(text, "\u041f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435"); extractor.close(); } diff --git a/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestBug46610.java b/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestBug46610.java index be231dad21..d43aa3172e 100644 --- a/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestBug46610.java +++ b/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestBug46610.java @@ -17,7 +17,10 @@ package org.apache.poi.hwpf.usermodel; -import junit.framework.TestCase; +import static org.junit.Assert.assertNotNull; +import static org.apache.poi.POITestCase.assertContains; + +import org.junit.Test; import org.apache.poi.hwpf.usermodel.CharacterRun; import org.apache.poi.hwpf.usermodel.Paragraph; @@ -25,22 +28,27 @@ import org.apache.poi.hwpf.usermodel.Range; import org.apache.poi.hwpf.HWPFDocument; import org.apache.poi.hwpf.HWPFTestDataSamples; -public final class TestBug46610 extends TestCase { +public final class TestBug46610 { - public void testUtf() { - runExtract("Bug46610_1.doc"); + @Test + public void testUtf() throws Exception { + String text = runExtract("Bug46610_1.doc"); + assertNotNull(text); } - public void testUtf2() { - runExtract("Bug46610_2.doc"); + @Test + public void testUtf2() throws Exception { + String text = runExtract("Bug46610_2.doc"); + assertNotNull(text); } - public void testExtraction() { + @Test + public void testExtraction() throws Exception { String text = runExtract("Bug46610_3.doc"); - assertTrue(text.contains("\u0421\u0412\u041e\u042e")); + assertContains(text, "\u0421\u0412\u041e\u042e"); } - private static String runExtract(String sampleName) { + private static String runExtract(String sampleName) throws Exception { HWPFDocument doc = HWPFTestDataSamples.openSampleFile(sampleName); StringBuffer out = new StringBuffer(); @@ -53,6 +61,7 @@ public final class TestBug46610 extends TestCase { CharacterRun characterRun = p.getCharacterRun(j); characterRun.text(); } + doc.close(); } return out.toString(); } diff --git a/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestBugs.java b/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestBugs.java index 06cfcb44a0..e91906ce3e 100644 --- a/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestBugs.java +++ b/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestBugs.java @@ -17,9 +17,9 @@ package org.apache.poi.hwpf.usermodel; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.apache.poi.POITestCase.assertContains; +import static org.apache.poi.POITestCase.assertNotContained; import java.io.ByteArrayOutputStream; import java.io.File; @@ -300,9 +300,9 @@ public class TestBugs{ { String text = getText("Bug46817.doc").trim(); - assertTrue(text.contains("Nazwa wykonawcy")); - assertTrue(text.contains("kujawsko-pomorskie")); - assertTrue(text.contains("ekomel@ekomel.com.pl")); + assertContains(text, "Nazwa wykonawcy"); + assertContains(text, "kujawsko-pomorskie"); + assertContains(text, "ekomel@ekomel.com.pl"); } /** @@ -421,11 +421,11 @@ public class TestBugs{ String docText = r.text(); - assertTrue(docText.contains("1-1")); - assertTrue(docText.contains("1-12")); + assertContains(docText, "1-1"); + assertContains(docText, "1-12"); - assertFalse(docText.contains("1-13")); - assertFalse(docText.contains("1-15")); + assertNotContained(docText, "1-13"); + assertNotContained(docText, "1-15"); } /** @@ -437,8 +437,7 @@ public class TestBugs{ { String foundText = getText("Bug47731.doc"); - assertTrue(foundText - .contains("Soak the rice in water for three to four hours")); + assertContains(foundText, "Soak the rice in water for three to four hours"); } /** @@ -500,43 +499,25 @@ public class TestBugs{ { String text = getTextOldFile("Bug49933.doc"); - assertTrue( text.contains( "best.wine.jump.ru" ) ); + assertContains(text, "best.wine.jump.ru"); } /** * Bug 50936 - Exception parsing MS Word 8.0 file */ @Test - public void test50936_1() + public void test50936() throws Exception { - HWPFDocument hwpfDocument = HWPFTestDataSamples - .openSampleFile("Bug50936_1.doc"); - hwpfDocument.getPicturesTable().getAllPictures(); - } + String[] filenames = {"Bug50936_1.doc", "Bug50936_2.doc", "Bug50936_3.doc"}; + for (String filename : filenames) { + HWPFDocument hwpfDocument = HWPFTestDataSamples.openSampleFile(filename); - /** - * Bug 50936 - Exception parsing MS Word 8.0 file - */ - @Test - public void test50936_2() - { - HWPFDocument hwpfDocument = HWPFTestDataSamples - .openSampleFile("Bug50936_2.doc"); - hwpfDocument.getPicturesTable().getAllPictures(); - } - - /** - * Bug 50936 - Exception parsing MS Word 8.0 file - */ - @Test - public void test50936_3() - { - HWPFDocument hwpfDocument = HWPFTestDataSamples - .openSampleFile("Bug50936_3.doc"); - hwpfDocument.getPicturesTable().getAllPictures(); + assertNotNull(filename, hwpfDocument.getPicturesTable().getAllPictures()); + + hwpfDocument.close(); + } } - /** * [RESOLVED FIXED] Bug 51604 - replace text fails for doc (poi 3.8 beta * release from download site ) |