From: Javen O'Neal Date: Mon, 23 Nov 2015 10:26:06 +0000 (+0000) Subject: convert junit3 to junit4 X-Git-Tag: REL_3_14_BETA1~110 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=8c3db2edd5b0fbdbe3df70690a10eab47e20fb1d;p=poi.git convert junit3 to junit4 git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1715752 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/ooxml/testcases/org/apache/poi/xssf/AllXSSFTests.java b/src/ooxml/testcases/org/apache/poi/xssf/AllXSSFTests.java index 3079970f08..1b87b95e88 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/AllXSSFTests.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/AllXSSFTests.java @@ -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 diff --git a/src/testcases/org/apache/poi/hssf/util/AllHSSFUtilTests.java b/src/testcases/org/apache/poi/hssf/util/AllHSSFUtilTests.java index d38b7306f8..6faba78461 100644 --- a/src/testcases/org/apache/poi/hssf/util/AllHSSFUtilTests.java +++ b/src/testcases/org/apache/poi/hssf/util/AllHSSFUtilTests.java @@ -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; diff --git a/src/testcases/org/apache/poi/hssf/util/TestCellReference.java b/src/testcases/org/apache/poi/hssf/util/TestCellReference.java index 9e48fc385e..ee08781e88 100644 --- a/src/testcases/org/apache/poi/hssf/util/TestCellReference.java +++ b/src/testcases/org/apache/poi/hssf/util/TestCellReference.java @@ -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); diff --git a/src/testcases/org/apache/poi/ss/util/AllSSUtilTests.java b/src/testcases/org/apache/poi/ss/util/AllSSUtilTests.java index d0935af6ca..5d239a17f8 100644 --- a/src/testcases/org/apache/poi/ss/util/AllSSUtilTests.java +++ b/src/testcases/org/apache/poi/ss/util/AllSSUtilTests.java @@ -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, diff --git a/src/testcases/org/apache/poi/ss/util/TestCellReference.java b/src/testcases/org/apache/poi/ss/util/TestCellReference.java index 0e56153321..421e95492a 100644 --- a/src/testcases/org/apache/poi/ss/util/TestCellReference.java +++ b/src/testcases/org/apache/poi/ss/util/TestCellReference.java @@ -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));