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
This commit is contained in:
Javen O'Neal 2017-04-19 23:51:03 +00:00
parent 6e0a5916b5
commit 3cbf4740b1
7 changed files with 95 additions and 101 deletions

View File

@ -17,6 +17,8 @@
package org.apache.poi.xssf.eventusermodel;
import static org.apache.poi.POITestCase.assertContains;
import java.io.InputStream;
import java.util.Iterator;
import java.util.List;
@ -181,9 +183,9 @@ public final class TestXSSFReader extends TestCase {
XSSFReader.SheetIterator it = (XSSFReader.SheetIterator) r.getSheetsData();
String text = getShapesString(it);
assertTrue(text.contains("Line 1"));
assertTrue(text.contains("Line 2"));
assertTrue(text.contains("Line 3"));
assertContains(text, "Line 1");
assertContains(text, "Line 2");
assertContains(text, "Line 3");
}
private String getShapesString(XSSFReader.SheetIterator it) {
@ -213,16 +215,16 @@ public final class TestXSSFReader extends TestCase {
r = new XSSFReader(pkg);
fail("This will fail until bug 57699 is fixed");
} catch (POIXMLException e) {
assertTrue("Had " + e, e.getMessage().contains("57699"));
assertContains(e.getMessage(), "57699");
return;
}
XSSFReader.SheetIterator it = (XSSFReader.SheetIterator) r.getSheetsData();
String text = getShapesString(it);
assertTrue(text.contains("Line 1"));
assertTrue(text.contains("Line 2"));
assertTrue(text.contains("Line 3"));
assertContains(text, "Line 1");
assertContains(text, "Line 2");
assertContains(text, "Line 3");
}
/**

View File

@ -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

View File

@ -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;
@ -273,10 +274,10 @@ public final class TestWordExtractor {
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"));
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);
@ -303,7 +304,7 @@ public final class TestWordExtractor {
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);
@ -316,8 +317,8 @@ public final class TestWordExtractor {
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();
}

View File

@ -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();
}

View File

@ -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,42 +499,24 @@ 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();
}
assertNotNull(filename, 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();
hwpfDocument.close();
}
}
/**
* [RESOLVED FIXED] Bug 51604 - replace text fails for doc (poi 3.8 beta

View File

@ -20,6 +20,8 @@ package org.apache.poi.hssf.extractor;
import static org.junit.Assert.assertEquals;
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.assertStartsWith;
import java.io.File;
import java.io.IOException;
@ -105,8 +107,6 @@ public final class TestExcelExtractor {
ExcelExtractor extractor = createExtractor("StringContinueRecords.xls");
extractor.getText();
// Has masses of text
// Until we fixed bug #41064, this would've
// failed by now
@ -231,19 +231,19 @@ public final class TestExcelExtractor {
extractor.setIncludeBlankCells(true);
String padded = extractor.getText();
assertTrue(def.startsWith(
assertStartsWith(def,
"Sheet1\n" +
"&[TAB]\t\n" +
"Hello\n" +
"11\t23\n"
));
);
assertTrue(padded.startsWith(
assertStartsWith(padded,
"Sheet1\n" +
"&[TAB]\t\n" +
"Hello\n" +
"11\t\t\t23\n"
));
);
extractor.close();
}
@ -262,17 +262,14 @@ public final class TestExcelExtractor {
// actually quite match what they claim to
// be, as some are auto-local builtins...
assertTrue(text.startsWith(
"Dates, all 24th November 2006\n"
));
assertTrue(text.contains("yyyy/mm/dd\t2006/11/24\n"));
assertTrue(text.contains("yyyy-mm-dd\t2006-11-24\n"));
assertTrue(text.contains("dd-mm-yy\t24-11-06\n"));
assertStartsWith(text, "Dates, all 24th November 2006\n");
assertContains(text, "yyyy/mm/dd\t2006/11/24\n");
assertContains(text, "yyyy-mm-dd\t2006-11-24\n");
assertContains(text, "dd-mm-yy\t24-11-06\n");
assertTrue("Had: " + text + ", but should contain 'nn.nn\\t10.52\\n'",
text.contains("nn.nn\t10.52\n"));
assertTrue(text.contains("nn.nnn\t10.520\n"));
assertTrue(text.contains("\u00a3nn.nn\t\u00a310.52\n"));
assertContains(text, "nn.nn\t10.52\n");
assertContains(text, "nn.nnn\t10.520\n");
assertContains(text, "\u00a3nn.nn\t\u00a310.52\n");
extractor.close();
} finally {
LocaleUtil.setUserLocale(userLocale);
@ -367,8 +364,8 @@ public final class TestExcelExtractor {
for (String file : files) {
ExcelExtractor extractor = createExtractor(file);
String text = extractor.getText();
assertTrue("Unable to find expected word in text\n" + text, text.contains("testdoc"));
assertTrue("Unable to find expected word in text\n" + text, text.contains("test phrase"));
assertContains(file, text, "testdoc");
assertContains(file, text, "test phrase");
extractor.close();
}
}
@ -380,7 +377,7 @@ public final class TestExcelExtractor {
String text = extractor.getText();
Biff8EncryptionKey.setCurrentUserPassword(null);
assertTrue(text.contains("ZIP"));
assertContains(text, "ZIP");
extractor.close();
}

View File

@ -21,8 +21,10 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.apache.poi.POITestCase.assertContains;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
@ -999,6 +1001,7 @@ public final class TestBugs extends BaseTestBugzillaIssues {
// Check that asking for the same font
// multiple times gives you the same thing.
// Otherwise, our tests wouldn't work!
assertSame(wb.getFontAt((short)0), wb.getFontAt((short)0));
assertEquals(
wb.getFontAt((short)0),
wb.getFontAt((short)0)
@ -2354,10 +2357,10 @@ public final class TestBugs extends BaseTestBugzillaIssues {
// Extract and check
ExcelExtractor ex = new ExcelExtractor(wb);
String text = ex.getText();
assertTrue(text.contains("Top Left Cell"));
assertTrue(text.contains("Top Right Cell"));
assertTrue(text.contains("Bottom Left Cell"));
assertTrue(text.contains("Bottom Right Cell"));
assertContains(text, "Top Left Cell");
assertContains(text, "Top Right Cell");
assertContains(text, "Bottom Left Cell");
assertContains(text, "Bottom Right Cell");
ex.close();
}
}
@ -2467,8 +2470,8 @@ public final class TestBugs extends BaseTestBugzillaIssues {
list.add(r.getSid());
}
});
assertTrue(list.get(list.size()-1).intValue() == UnknownRecord.BITMAP_00E9);
assertTrue(list.get(list.size()-2).intValue() == UnknownRecord.HEADER_FOOTER_089C);
assertEquals(UnknownRecord.BITMAP_00E9, list.get(list.size()-1).intValue());
assertEquals(UnknownRecord.HEADER_FOOTER_089C, list.get(list.size()-2).intValue());
wb.close();
}