aboutsummaryrefslogtreecommitdiffstats
path: root/src/testcases/org/apache/poi/hssf/util
diff options
context:
space:
mode:
authorAndreas Beeker <kiwiwings@apache.org>2020-12-24 18:42:29 +0000
committerAndreas Beeker <kiwiwings@apache.org>2020-12-24 18:42:29 +0000
commita0fa9e19b1196bc10034f15474d27ce23bf5865a (patch)
tree499c1eb427ebff72f7e447d13dd1de1552df8146 /src/testcases/org/apache/poi/hssf/util
parentfb012041e8dd788637e68737199bc313b3e90098 (diff)
downloadpoi-a0fa9e19b1196bc10034f15474d27ce23bf5865a.tar.gz
poi-a0fa9e19b1196bc10034f15474d27ce23bf5865a.zip
#65026 - Migrate tests to Junit 5
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1884783 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/testcases/org/apache/poi/hssf/util')
-rw-r--r--src/testcases/org/apache/poi/hssf/util/AllHSSFUtilTests.java34
-rw-r--r--src/testcases/org/apache/poi/hssf/util/TestAreaReference.java58
-rw-r--r--src/testcases/org/apache/poi/hssf/util/TestCellReference.java32
-rw-r--r--src/testcases/org/apache/poi/hssf/util/TestHSSFColor.java14
-rw-r--r--src/testcases/org/apache/poi/hssf/util/TestRKUtil.java4
5 files changed, 45 insertions, 97 deletions
diff --git a/src/testcases/org/apache/poi/hssf/util/AllHSSFUtilTests.java b/src/testcases/org/apache/poi/hssf/util/AllHSSFUtilTests.java
deleted file mode 100644
index 7e71fb2de1..0000000000
--- a/src/testcases/org/apache/poi/hssf/util/AllHSSFUtilTests.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/* ====================================================================
- Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements. See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You under the Apache License, Version 2.0
- (the "License"); you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-==================================================================== */
-
-package org.apache.poi.hssf.util;
-
-import org.junit.runner.RunWith;
-import org.junit.runners.Suite;
-
-/**
- * Collects all tests for org.apache.poi.hssf.util.
- */
-@RunWith(Suite.class)
-@Suite.SuiteClasses({
- TestAreaReference.class,
- TestCellReference.class,
- TestHSSFColor.class,
- TestRKUtil.class
-})
-public class AllHSSFUtilTests {
-}
diff --git a/src/testcases/org/apache/poi/hssf/util/TestAreaReference.java b/src/testcases/org/apache/poi/hssf/util/TestAreaReference.java
index fddd1e7603..c3c68a3dca 100644
--- a/src/testcases/org/apache/poi/hssf/util/TestAreaReference.java
+++ b/src/testcases/org/apache/poi/hssf/util/TestAreaReference.java
@@ -17,12 +17,12 @@
package org.apache.poi.hssf.util;
-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.assertTrue;
-import static org.junit.Assert.fail;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.InputStream;
@@ -44,27 +44,27 @@ import org.apache.poi.ss.formula.ptg.Ptg;
import org.apache.poi.ss.formula.ptg.UnionPtg;
import org.apache.poi.ss.util.AreaReference;
import org.apache.poi.ss.util.CellReference;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
public final class TestAreaReference {
@Test
public void testAreaRef1() {
AreaReference ar = new AreaReference("$A$1:$B$2", SpreadsheetVersion.EXCEL97);
- assertFalse("Two cells expected", ar.isSingleCell());
+ assertFalse(ar.isSingleCell(), "Two cells expected");
CellReference cf = ar.getFirstCell();
- assertEquals("row is 4", 0, cf.getRow());
- assertEquals("col is 1", 0, cf.getCol());
- assertTrue("row is abs", cf.isRowAbsolute());
- assertTrue("col is abs", cf.isColAbsolute());
- assertEquals("string is $A$1", "$A$1", cf.formatAsString());
+ assertEquals(0, cf.getRow(), "row is 4");
+ assertEquals(0, cf.getCol(), "col is 1");
+ assertTrue(cf.isRowAbsolute(), "row is abs");
+ assertTrue(cf.isColAbsolute(), "col is abs");
+ assertEquals("$A$1", cf.formatAsString(), "string is $A$1");
cf = ar.getLastCell();
- assertEquals("row is 4", 1, cf.getRow());
- assertEquals("col is 1", 1, cf.getCol());
- assertTrue("row is abs", cf.isRowAbsolute());
- assertTrue("col is abs", cf.isColAbsolute());
- assertEquals("string is $B$2", "$B$2", cf.formatAsString());
+ assertEquals(1, cf.getRow(), "row is 4");
+ assertEquals(1, cf.getCol(), "col is 1");
+ assertTrue(cf.isRowAbsolute(), "row is abs");
+ assertTrue(cf.isColAbsolute(), "col is abs");
+ assertEquals("$B$2", cf.formatAsString(), "string is $B$2");
CellReference[] refs = ar.getAllReferencedCells();
assertEquals(4, refs.length);
@@ -136,24 +136,9 @@ public final class TestAreaReference {
// Check we can only create contiguous entries
new AreaReference(refSimple, SpreadsheetVersion.EXCEL97);
new AreaReference(ref2D, SpreadsheetVersion.EXCEL97);
- try {
- new AreaReference(refDCSimple, SpreadsheetVersion.EXCEL97);
- fail("expected IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // expected during successful test
- }
- try {
- new AreaReference(refDC2D, SpreadsheetVersion.EXCEL97);
- fail("expected IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // expected during successful test
- }
- try {
- new AreaReference(refDC3D, SpreadsheetVersion.EXCEL97);
- fail("expected IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // expected during successful test
- }
+ assertThrows(IllegalArgumentException.class, () -> new AreaReference(refDCSimple, SpreadsheetVersion.EXCEL97));
+ assertThrows(IllegalArgumentException.class, () -> new AreaReference(refDC2D, SpreadsheetVersion.EXCEL97));
+ assertThrows(IllegalArgumentException.class, () -> new AreaReference(refDC3D, SpreadsheetVersion.EXCEL97));
// Test that we split as expected
AreaReference[] refs;
@@ -251,6 +236,7 @@ public final class TestAreaReference {
HSSFName aNamedCell = wb.getName("test");
// Should have 2 references
+ assertNotNull(aNamedCell);
String formulaRefs = aNamedCell.getRefersToFormula();
assertNotNull(formulaRefs);
assertEquals(ref, formulaRefs);
diff --git a/src/testcases/org/apache/poi/hssf/util/TestCellReference.java b/src/testcases/org/apache/poi/hssf/util/TestCellReference.java
index c7a7e10aa5..ab23476c1d 100644
--- a/src/testcases/org/apache/poi/hssf/util/TestCellReference.java
+++ b/src/testcases/org/apache/poi/hssf/util/TestCellReference.java
@@ -17,13 +17,13 @@
package org.apache.poi.hssf.util;
-import org.junit.Test;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import org.apache.poi.ss.SpreadsheetVersion;
import org.apache.poi.ss.util.CellReference;
import org.apache.poi.ss.util.CellReference.NameType;
-import org.apache.poi.ss.SpreadsheetVersion;
+import org.junit.jupiter.api.Test;
/**
* Tests for the HSSF and SS versions of CellReference.
@@ -41,7 +41,7 @@ public final class TestCellReference {
assertEquals(701, CellReference.convertColStringToIndex("ZZ"));
assertEquals(702, CellReference.convertColStringToIndex("AAA"));
assertEquals(18277, CellReference.convertColStringToIndex("ZZZ"));
-
+
assertEquals("A", CellReference.convertNumToColString(0));
assertEquals("B", CellReference.convertNumToColString(1));
assertEquals("Z", CellReference.convertNumToColString(25));
@@ -49,19 +49,15 @@ public final class TestCellReference {
assertEquals("ZZ", CellReference.convertNumToColString(701));
assertEquals("AAA", CellReference.convertNumToColString(702));
assertEquals("ZZZ", CellReference.convertNumToColString(18277));
-
+
// Absolute references are allowed for the string ones
assertEquals(0, CellReference.convertColStringToIndex("$A"));
assertEquals(25, CellReference.convertColStringToIndex("$Z"));
assertEquals(26, CellReference.convertColStringToIndex("$AA"));
-
+
// $ sign isn't allowed elsewhere though
- try {
- CellReference.convertColStringToIndex("A$B$");
- fail("Column reference is invalid and shouldn't be accepted");
- } catch (IllegalArgumentException e) {
- // expected here
- }
+ assertThrows(IllegalArgumentException.class, () -> CellReference.convertColStringToIndex("A$B$"),
+ "Column reference is invalid and shouldn't be accepted");
}
@Test
@@ -129,11 +125,11 @@ public final class TestCellReference {
int expCol, boolean expIsRowAbs, boolean expIsColAbs, String expText) {
assertEquals(expSheetName, cf.getSheetName());
- assertEquals("row index is wrong", expRow, cf.getRow());
- assertEquals("col index is wrong", expCol, cf.getCol());
- assertEquals("isRowAbsolute is wrong", expIsRowAbs, cf.isRowAbsolute());
- assertEquals("isColAbsolute is wrong", expIsColAbs, cf.isColAbsolute());
- assertEquals("text is wrong", expText, cf.formatAsString());
+ assertEquals(expRow, cf.getRow(), "row index is wrong");
+ assertEquals(expCol, cf.getCol(), "col index is wrong");
+ assertEquals(expIsRowAbs, cf.isRowAbsolute(), "isRowAbsolute is wrong");
+ assertEquals(expIsColAbs, cf.isColAbsolute(), "isColAbsolute is wrong");
+ assertEquals(expText, cf.formatAsString(), "text is wrong");
}
@Test
diff --git a/src/testcases/org/apache/poi/hssf/util/TestHSSFColor.java b/src/testcases/org/apache/poi/hssf/util/TestHSSFColor.java
index eb484a775e..ac636c8f5c 100644
--- a/src/testcases/org/apache/poi/hssf/util/TestHSSFColor.java
+++ b/src/testcases/org/apache/poi/hssf/util/TestHSSFColor.java
@@ -17,13 +17,13 @@
package org.apache.poi.hssf.util;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.Map;
import org.apache.poi.hssf.util.HSSFColor.HSSFColorPredefined;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
public final class TestHSSFColor {
@Test
@@ -31,7 +31,7 @@ public final class TestHSSFColor {
assertTrue(HSSFColorPredefined.YELLOW.getIndex() > 0);
assertTrue(HSSFColorPredefined.YELLOW.getIndex2() > 0);
}
-
+
@Test
public void testContents() {
short[] triplet = HSSFColorPredefined.YELLOW.getTriplet();
@@ -39,14 +39,14 @@ public final class TestHSSFColor {
assertEquals(255, triplet[0]);
assertEquals(255, triplet[1]);
assertEquals(0, triplet[2]);
-
+
assertEquals("FFFF:FFFF:0", HSSFColorPredefined.YELLOW.getHexString());
}
-
+
@Test
public void testTripletHash() {
Map<String, HSSFColor> triplets = HSSFColor.getTripletHash();
-
+
assertEquals(
HSSFColorPredefined.MAROON.getColor(),
triplets.get(HSSFColorPredefined.MAROON.getHexString())
diff --git a/src/testcases/org/apache/poi/hssf/util/TestRKUtil.java b/src/testcases/org/apache/poi/hssf/util/TestRKUtil.java
index 09fcaa40cf..28e1964ff7 100644
--- a/src/testcases/org/apache/poi/hssf/util/TestRKUtil.java
+++ b/src/testcases/org/apache/poi/hssf/util/TestRKUtil.java
@@ -17,9 +17,9 @@
package org.apache.poi.hssf.util;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Tests the {@link RKUtil} class.