From f458a9ac41326a44191cbda06b2f259d7e96d24b Mon Sep 17 00:00:00 2001 From: Javen O'Neal Date: Mon, 2 Jan 2017 23:23:16 +0000 Subject: [PATCH] convert TestColumnHelper from junit3 to junit4 git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1777038 13f79535-47bb-0310-9956-ffa450edef68 --- .../usermodel/helpers/TestColumnHelper.java | 31 ++++++++++++++++--- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/helpers/TestColumnHelper.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/helpers/TestColumnHelper.java index 1ca8fb8be..34876e8ad 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/helpers/TestColumnHelper.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/helpers/TestColumnHelper.java @@ -17,7 +17,13 @@ package org.apache.poi.xssf.usermodel.helpers; -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.assertNull; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; import org.apache.poi.xssf.model.StylesTable; import org.apache.poi.xssf.usermodel.XSSFCellStyle; @@ -32,8 +38,9 @@ import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTXf; * Tests for {@link ColumnHelper} * */ -public final class TestColumnHelper extends TestCase { +public final class TestColumnHelper { + @Test public void testCleanColumns() { CTWorksheet worksheet = CTWorksheet.Factory.newInstance(); @@ -67,6 +74,7 @@ public final class TestColumnHelper extends TestCase { assertFalse(helper.getColumn(1, false).getHidden()); } + @Test public void testSortColumns() { CTCols cols1 = CTCols.Factory.newInstance(); CTCol col1 = cols1.addNewCol(); @@ -112,6 +120,7 @@ public final class TestColumnHelper extends TestCase { assertEquals(27, cols1.getColArray(8).getMax()); } + @Test public void testCloneCol() { CTWorksheet worksheet = CTWorksheet.Factory.newInstance(); ColumnHelper helper = new ColumnHelper(worksheet); @@ -129,6 +138,7 @@ public final class TestColumnHelper extends TestCase { assertEquals(13.4, newCol.getWidth(), 0.0); } + @Test public void testAddCleanColIntoCols() { CTWorksheet worksheet = CTWorksheet.Factory.newInstance(); ColumnHelper helper = new ColumnHelper(worksheet); @@ -180,12 +190,14 @@ public final class TestColumnHelper extends TestCase { assertEquals(16750, cols1.getColArray(11).getMax()); } + @Test public void testAddCleanColIntoColsExactOverlap() throws Exception { CTCols cols = createHiddenAndBestFitColsWithHelper(1, 1, 1, 1); assertEquals(1, cols.sizeOfColArray()); assertMinMaxHiddenBestFit(cols, 0, 1, 1, true, true); } + @Test public void testAddCleanColIntoColsOverlapsOverhangingBothSides() throws Exception { CTCols cols = createHiddenAndBestFitColsWithHelper(2, 2, 1, 3); assertEquals(3, cols.sizeOfColArray()); @@ -194,6 +206,7 @@ public final class TestColumnHelper extends TestCase { assertMinMaxHiddenBestFit(cols, 2, 3, 3, false, true); } + @Test public void testAddCleanColIntoColsOverlapsCompletelyNested() throws Exception { CTCols cols = createHiddenAndBestFitColsWithHelper(1, 3, 2, 2); assertEquals(3, cols.sizeOfColArray()); @@ -202,6 +215,7 @@ public final class TestColumnHelper extends TestCase { assertMinMaxHiddenBestFit(cols, 2, 3, 3, true, false); } + @Test public void testAddCleanColIntoColsNewOverlapsOverhangingLeftNotRightExactRight() throws Exception { CTCols cols = createHiddenAndBestFitColsWithHelper(2, 3, 1, 3); assertEquals(2, cols.sizeOfColArray()); @@ -209,6 +223,7 @@ public final class TestColumnHelper extends TestCase { assertMinMaxHiddenBestFit(cols, 1, 2, 3, true, true); } + @Test public void testAddCleanColIntoColsNewOverlapsOverhangingRightNotLeftExactLeft() throws Exception { CTCols cols = createHiddenAndBestFitColsWithHelper(1, 2, 1, 3); assertEquals(2, cols.sizeOfColArray()); @@ -216,6 +231,7 @@ public final class TestColumnHelper extends TestCase { assertMinMaxHiddenBestFit(cols, 1, 3, 3, false, true); } + @Test public void testAddCleanColIntoColsNewOverlapsOverhangingLeftNotRight() throws Exception { CTCols cols = createHiddenAndBestFitColsWithHelper(2, 3, 1, 2); assertEquals(3, cols.sizeOfColArray()); @@ -224,6 +240,7 @@ public final class TestColumnHelper extends TestCase { assertMinMaxHiddenBestFit(cols, 2, 3, 3, true, false); } + @Test public void testAddCleanColIntoColsNewOverlapsOverhangingRightNotLeft() throws Exception { CTCols cols = createHiddenAndBestFitColsWithHelper(1, 2, 2, 3); assertEquals(3, cols.sizeOfColArray()); @@ -236,7 +253,7 @@ public final class TestColumnHelper extends TestCase { * Creates and adds a hidden column and then a best fit column with the given min/max pairs. * Suitable for testing handling of overlap. */ - private CTCols createHiddenAndBestFitColsWithHelper(int hiddenMin, int hiddenMax, int bestFitMin, int bestFitMax) { + private static CTCols createHiddenAndBestFitColsWithHelper(int hiddenMin, int hiddenMax, int bestFitMin, int bestFitMax) { CTWorksheet worksheet = CTWorksheet.Factory.newInstance(); ColumnHelper helper = new ColumnHelper(worksheet); CTCols cols = worksheet.getColsArray(0); @@ -251,7 +268,7 @@ public final class TestColumnHelper extends TestCase { return cols; } - private void assertMinMaxHiddenBestFit(CTCols cols, int index, int min, int max, boolean hidden, boolean bestFit) { + private static void assertMinMaxHiddenBestFit(CTCols cols, int index, int min, int max, boolean hidden, boolean bestFit) { CTCol col = cols.getColArray(index); assertEquals(min, col.getMin()); assertEquals(max, col.getMax()); @@ -259,13 +276,14 @@ public final class TestColumnHelper extends TestCase { assertEquals(bestFit, col.getBestFit()); } - private CTCol createCol(int min, int max) { + private static CTCol createCol(int min, int max) { CTCol col = CTCol.Factory.newInstance(); col.setMin(min); col.setMax(max); return col; } + @Test public void testGetColumn() { CTWorksheet worksheet = CTWorksheet.Factory.newInstance(); @@ -295,6 +313,7 @@ public final class TestColumnHelper extends TestCase { assertNotNull(helper.getColumn(5, false)); } + @Test public void testSetColumnAttributes() { CTCol col = CTCol.Factory.newInstance(); col.setWidth(12); @@ -309,6 +328,7 @@ public final class TestColumnHelper extends TestCase { assertTrue(newCol.getHidden()); } + @Test public void testGetOrCreateColumn() { XSSFWorkbook workbook = new XSSFWorkbook(); XSSFSheet sheet = workbook.createSheet("Sheet 1"); @@ -330,6 +350,7 @@ public final class TestColumnHelper extends TestCase { assertNull(columnHelper.getColumn(30, false)); } + @Test public void testGetSetColDefaultStyle() { XSSFWorkbook workbook = new XSSFWorkbook(); XSSFSheet sheet = workbook.createSheet();