tidy up some test code

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1808944 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
PJ Fanning 2017-09-19 21:04:30 +00:00
parent 01b1005379
commit a9ec0770f0
5 changed files with 29 additions and 61 deletions

View File

@ -332,7 +332,7 @@ public class TestExtractorFactory {
// Text
try {
ExtractorFactory.createExtractor(txt);
fail();
fail("expected IllegalArgumentException");
} catch(IllegalArgumentException e) {
// Good
}
@ -480,14 +480,9 @@ public class TestExtractorFactory {
extractor.close();
// Text
try {
FileInputStream stream = new FileInputStream(txt);
try {
ExtractorFactory.createExtractor(stream);
fail();
} finally {
IOUtils.closeQuietly(stream);
}
try (FileInputStream stream = new FileInputStream(txt)) {
ExtractorFactory.createExtractor(stream);
fail("expected IllegalArgumentException");
} catch(IllegalArgumentException e) {
// Good
}
@ -568,7 +563,7 @@ public class TestExtractorFactory {
// Text
try {
ExtractorFactory.createExtractor(new POIFSFileSystem(new FileInputStream(txt)));
fail();
fail("expected IllegalArgumentException");
} catch(IOException e) {
// Good
}
@ -650,7 +645,7 @@ public class TestExtractorFactory {
// Text
try {
ExtractorFactory.createExtractor(new OPOIFSFileSystem(new FileInputStream(txt)));
fail();
fail("expected IllegalArgumentException");
} catch(IOException e) {
// Good
}

View File

@ -86,16 +86,9 @@ public abstract class BaseTestXSSFPivotTable {
/**
* Verify that it's not possible to create a row label outside of the referenced area.
*/
@Test
@Test(expected = IndexOutOfBoundsException.class)
public void testAddRowLabelOutOfRangeThrowsException() {
int columnIndex = 5;
try {
pivotTable.addRowLabel(columnIndex);
} catch(IndexOutOfBoundsException e) {
return;
}
fail();
pivotTable.addRowLabel(5);
}
/**
@ -197,16 +190,9 @@ public abstract class BaseTestXSSFPivotTable {
/**
* Verify that it's not possible to create a column label outside of the referenced area.
*/
@Test
@Test(expected = IndexOutOfBoundsException.class)
public void testAddColumnLabelOutOfRangeThrowsException() {
int columnIndex = 5;
try {
pivotTable.addColumnLabel(DataConsolidateFunction.SUM, columnIndex);
} catch(IndexOutOfBoundsException e) {
return;
}
fail();
pivotTable.addColumnLabel(DataConsolidateFunction.SUM, 5);
}
/**
@ -226,17 +212,9 @@ public abstract class BaseTestXSSFPivotTable {
/**
* Verify that it's not possible to create a data column outside of the referenced area.
*/
@Test
@Test(expected = IndexOutOfBoundsException.class)
public void testAddDataColumnOutOfRangeThrowsException() {
int columnIndex = 5;
boolean isDataField = true;
try {
pivotTable.addDataColumn(columnIndex, isDataField);
} catch(IndexOutOfBoundsException e) {
return;
}
fail();
pivotTable.addDataColumn(5, true);
}
/**
@ -257,15 +235,9 @@ public abstract class BaseTestXSSFPivotTable {
/**
* Verify that it's not possible to create a new filter outside of the referenced area.
*/
@Test
@Test(expected = IndexOutOfBoundsException.class)
public void testAddReportFilterOutOfRangeThrowsException() {
int columnIndex = 5;
try {
pivotTable.addReportFilter(columnIndex);
} catch(IndexOutOfBoundsException e) {
return;
}
fail();
pivotTable.addReportFilter(5);
}
/**

View File

@ -19,6 +19,7 @@ package org.apache.poi.hsmf;
import static org.apache.poi.POITestCase.assertContains;
import static org.apache.poi.POITestCase.assertStartsWith;
import static org.junit.Assert.fail;
import java.io.IOException;
@ -99,13 +100,13 @@ public final class TestBasics extends TestCase {
// Quick doesn't have them
try {
quick.getHeaders();
fail();
fail("expected ChunkNotFoundException");
} catch(ChunkNotFoundException e) {}
// Attachments doesn't have them
try {
attachments.getHeaders();
fail();
fail("expected ChunkNotFoundException");
} catch(ChunkNotFoundException e) {}
// Outlook30 has some
@ -157,7 +158,7 @@ public final class TestBasics extends TestCase {
try {
attachments.getHtmlBody();
fail();
fail("expected ChunkNotFoundException");
} catch(ChunkNotFoundException e) {
// Good
}
@ -170,7 +171,7 @@ public final class TestBasics extends TestCase {
try {
attachments.getHtmlBody();
fail();
fail("expected ChunkNotFoundException");
} catch(ChunkNotFoundException e) {
// Good
}
@ -185,13 +186,13 @@ public final class TestBasics extends TestCase {
try {
noRecipientAddress.getRecipientEmailAddress();
fail();
fail("expected ChunkNotFoundException");
} catch(ChunkNotFoundException e) {
// Good
}
try {
noRecipientAddress.getRecipientEmailAddressList();
fail();
fail("expected ChunkNotFoundException");
} catch(ChunkNotFoundException e) {
// Good
}

View File

@ -301,13 +301,13 @@ public final class TestHSSFCell extends BaseTestCell {
styB.verifyBelongsToWorkbook(wbB);
try {
styA.verifyBelongsToWorkbook(wbB);
fail();
fail("expected IllegalArgumentException");
} catch (IllegalArgumentException e) {
// expected during successful test
}
try {
styB.verifyBelongsToWorkbook(wbA);
fail();
fail("expected IllegalArgumentException");
} catch (IllegalArgumentException e) {
// expected during successful test
}
@ -319,13 +319,13 @@ public final class TestHSSFCell extends BaseTestCell {
cellB.setCellStyle(styB);
try {
cellA.setCellStyle(styB);
fail();
fail("expected IllegalArgumentException");
} catch (IllegalArgumentException e) {
// expected during successful test
}
try {
cellB.setCellStyle(styA);
fail();
fail("expected IllegalArgumentException");
} catch (IllegalArgumentException e) {
// expected during successful test
}
@ -352,7 +352,7 @@ public final class TestHSSFCell extends BaseTestCell {
Record[] recs = RecordInspector.getRecords(sheet, 0);
if (recs.length == 28 && recs[23] instanceof StringRecord) {
wb.close();
throw new AssertionFailedError("Identified bug - leftover StringRecord");
fail("Identified bug - leftover StringRecord");
}
confirmStringRecord(sheet, false);

View File

@ -126,19 +126,19 @@ public final class TestAreaReference extends TestCase {
new AreaReference(ref2D, SpreadsheetVersion.EXCEL97);
try {
new AreaReference(refDCSimple, SpreadsheetVersion.EXCEL97);
fail();
fail("expected IllegalArgumentException");
} catch(IllegalArgumentException e) {
// expected during successful test
}
try {
new AreaReference(refDC2D, SpreadsheetVersion.EXCEL97);
fail();
fail("expected IllegalArgumentException");
} catch(IllegalArgumentException e) {
// expected during successful test
}
try {
new AreaReference(refDC3D, SpreadsheetVersion.EXCEL97);
fail();
fail("expected IllegalArgumentException");
} catch(IllegalArgumentException e) {
// expected during successful test
}