convert junit3 to junit4

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1715752 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Javen O'Neal 2015-11-23 10:26:06 +00:00
parent dbba80c3fc
commit ae9bcd8e82
5 changed files with 43 additions and 17 deletions

View File

@ -44,7 +44,7 @@ import org.junit.runners.Suite;
TestCommentsTable.class,
TestSharedStringsTable.class,
TestStylesTable.class,
TestCellReference.class,
//TestCellReference.class, //converted to junit4
TestCTColComparator.class,
TestNumericRanges.class,
TestCellFormatPart.class

View File

@ -30,7 +30,7 @@ public class AllHSSFUtilTests {
public static Test suite() {
TestSuite result = new TestSuite(AllHSSFUtilTests.class.getName());
result.addTestSuite(TestAreaReference.class);
result.addTestSuite(TestCellReference.class);
// result.addTestSuite(TestCellReference.class); //converted to junit4
result.addTestSuite(TestHSSFColor.class);
result.addTestSuite(TestRKUtil.class);
return result;

View File

@ -17,7 +17,9 @@
package org.apache.poi.hssf.util;
import junit.framework.TestCase;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import org.apache.poi.ss.util.CellReference;
import org.apache.poi.ss.util.CellReference.NameType;
@ -27,7 +29,8 @@ import org.apache.poi.ss.SpreadsheetVersion;
* Tests for the HSSF and SS versions of CellReference.
* See also {@link org.apache.poi.ss.util.TestCellReference}
*/
public final class TestCellReference extends TestCase {
public final class TestCellReference {
@Test
public void testColNumConversion() {
assertEquals(0, CellReference.convertColStringToIndex("A"));
assertEquals(1, CellReference.convertColStringToIndex("B"));
@ -59,46 +62,55 @@ public final class TestCellReference extends TestCase {
} catch (IllegalArgumentException e) {}
}
@Test
public void testAbsRef1(){
CellReference cf = new CellReference("$B$5");
confirmCell(cf, null, 4, 1, true, true, "$B$5");
}
@Test
public void testAbsRef2(){
CellReference cf = new CellReference(4,1,true,true);
confirmCell(cf, null, 4, 1, true, true, "$B$5");
}
@Test
public void testAbsRef3(){
CellReference cf = new CellReference("B$5");
confirmCell(cf, null, 4, 1, true, false, "B$5");
}
@Test
public void testAbsRef4(){
CellReference cf = new CellReference(4,1,true,false);
confirmCell(cf, null, 4, 1, true, false, "B$5");
}
@Test
public void testAbsRef5(){
CellReference cf = new CellReference("$B5");
confirmCell(cf, null, 4, 1, false, true, "$B5");
}
@Test
public void testAbsRef6(){
CellReference cf = new CellReference(4,1,false,true);
confirmCell(cf, null, 4, 1, false, true, "$B5");
}
@Test
public void testAbsRef7(){
CellReference cf = new CellReference("B5");
confirmCell(cf, null, 4, 1, false, false, "B5");
}
@Test
public void testAbsRef8(){
CellReference cf = new CellReference(4,1,false,false);
confirmCell(cf, null, 4, 1, false, false, "B5");
}
@Test
public void testSpecialSheetNames() {
CellReference cf;
cf = new CellReference("'profit + loss'!A1");
@ -122,6 +134,7 @@ public final class TestCellReference extends TestCase {
assertEquals("text is wrong", expText, cf.formatAsString());
}
@Test
public void testClassifyCellReference() {
confirmNameType("a1", NameType.CELL);
confirmNameType("pfy1", NameType.NAMED_RANGE);
@ -136,6 +149,7 @@ public final class TestCellReference extends TestCase {
confirmNameType("A1.", NameType.NAMED_RANGE);
}
@Test
public void testClassificationOfRowReferences(){
confirmNameType("10", NameType.ROW);
confirmNameType("$10", NameType.ROW);

View File

@ -28,7 +28,7 @@ import org.junit.runners.Suite;
@Suite.SuiteClasses({
TestAreaReference.class,
TestCellRangeAddress.class,
TestCellReference.class,
//TestCellReference.class, //converted to junit4
TestDateFormatConverter.class,
TestExpandedDouble.class,
TestNumberComparer.class,

View File

@ -20,15 +20,20 @@ package org.apache.poi.ss.util;
import org.apache.poi.ss.SpreadsheetVersion;
import org.apache.poi.ss.util.CellReference;
import junit.framework.AssertionFailedError;
import junit.framework.TestCase;
import org.junit.Test;
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.junit.Assert.fail;
/**
* Tests that the common CellReference works as we need it to.
* Note - some additional testing is also done in the HSSF class,
* {@link org.apache.poi.hssf.util.TestCellReference}
*/
public final class TestCellReference extends TestCase {
public final class TestCellReference {
@Test
public void testConstructors() {
CellReference cellReference;
final String sheet = "Sheet1";
@ -54,6 +59,7 @@ public final class TestCellReference extends TestCase {
assertEquals("Sheet1!A$1", cellReference.formatAsString());
}
@Test
public void testFormatAsString() {
CellReference cellReference;
@ -73,6 +79,7 @@ public final class TestCellReference extends TestCase {
assertEquals("'Sheet 1'!A$1", cellReference.formatAsString());
}
@Test
public void testGetCellRefParts() {
CellReference cellReference;
String[] parts;
@ -140,6 +147,7 @@ public final class TestCellReference extends TestCase {
assertEquals("AABC", parts[2]);
}
@Test
public void testGetColNumFromRef() {
String cellRef = "A1";
CellReference cellReference = new CellReference(cellRef);
@ -183,6 +191,7 @@ public final class TestCellReference extends TestCase {
assertEquals(54, cellReference.getCol());
}
@Test
public void testGetRowNumFromRef() {
String cellRef = "A1";
CellReference cellReference = new CellReference(cellRef);
@ -197,6 +206,7 @@ public final class TestCellReference extends TestCase {
assertEquals(120, cellReference.getRow());
}
@Test
public void testConvertNumToColString() {
short col = 702;
String collRef = new CellReference(0, col).formatAsString();
@ -215,6 +225,7 @@ public final class TestCellReference extends TestCase {
assertEquals("CBA1", collRef4);
}
@Test
public void testBadRowNumber() {
SpreadsheetVersion v97 = SpreadsheetVersion.EXCEL97;
SpreadsheetVersion v2007 = SpreadsheetVersion.EXCEL2007;
@ -229,29 +240,28 @@ public final class TestCellReference extends TestCase {
confirmCrInRange(false, "XFD", "1048577", v2007);
confirmCrInRange(false, "XFE", "1048576", v2007);
if (CellReference.cellReferenceIsWithinRange("B", "0", v97)) {
throw new AssertionFailedError("Identified bug 47312a");
}
assertFalse("Identified bug 47312a", CellReference.cellReferenceIsWithinRange("B", "0", v97));
confirmCrInRange(false, "A", "0", v97);
confirmCrInRange(false, "A", "0", v2007);
}
@Test
public void testInvalidReference() {
try {
new CellReference("Sheet1!#REF!");
fail("Shouldn't be able to create a #REF! refence");
} catch(IllegalArgumentException e) {}
} catch(IllegalArgumentException expected) {}
try {
new CellReference("'MySheetName'!#REF!");
fail("Shouldn't be able to create a #REF! refence");
} catch(IllegalArgumentException e) {}
} catch(IllegalArgumentException expected) {}
try {
new CellReference("#REF!");
fail("Shouldn't be able to create a #REF! refence");
} catch(IllegalArgumentException e) {}
} catch(IllegalArgumentException expected) {}
}
private static void confirmCrInRange(boolean expResult, String colStr, String rowStr,
@ -259,10 +269,11 @@ public final class TestCellReference extends TestCase {
if (expResult == CellReference.cellReferenceIsWithinRange(colStr, rowStr, sv)) {
return;
}
throw new AssertionFailedError("expected (c='" + colStr + "', r='" + rowStr + "' to be "
fail("expected (c='" + colStr + "', r='" + rowStr + "' to be "
+ (expResult ? "within" : "out of") + " bounds for version " + sv.name());
}
@Test
public void testConvertColStringToIndex() {
assertEquals(0, CellReference.convertColStringToIndex("A"));
assertEquals(1, CellReference.convertColStringToIndex("B"));
@ -276,11 +287,12 @@ public final class TestCellReference extends TestCase {
try {
CellReference.convertColStringToIndex("A$");
fail("Should throw exception here");
} catch (IllegalArgumentException e) {
assertTrue(e.getMessage().contains("A$"));
} catch (IllegalArgumentException expected) {
assertTrue(expected.getMessage().contains("A$"));
}
}
@Test
public void testConvertNumColColString() {
assertEquals("A", CellReference.convertNumToColString(0));
assertEquals("AV", CellReference.convertNumToColString(47));