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, TestCommentsTable.class,
TestSharedStringsTable.class, TestSharedStringsTable.class,
TestStylesTable.class, TestStylesTable.class,
TestCellReference.class, //TestCellReference.class, //converted to junit4
TestCTColComparator.class, TestCTColComparator.class,
TestNumericRanges.class, TestNumericRanges.class,
TestCellFormatPart.class TestCellFormatPart.class

View File

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

View File

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

View File

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