convert TestColumnHelper from junit3 to junit4
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1777038 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
18fd1b522d
commit
f458a9ac41
@ -17,7 +17,13 @@
|
|||||||
|
|
||||||
package org.apache.poi.xssf.usermodel.helpers;
|
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.model.StylesTable;
|
||||||
import org.apache.poi.xssf.usermodel.XSSFCellStyle;
|
import org.apache.poi.xssf.usermodel.XSSFCellStyle;
|
||||||
@ -32,8 +38,9 @@ import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTXf;
|
|||||||
* Tests for {@link ColumnHelper}
|
* Tests for {@link ColumnHelper}
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public final class TestColumnHelper extends TestCase {
|
public final class TestColumnHelper {
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testCleanColumns() {
|
public void testCleanColumns() {
|
||||||
CTWorksheet worksheet = CTWorksheet.Factory.newInstance();
|
CTWorksheet worksheet = CTWorksheet.Factory.newInstance();
|
||||||
|
|
||||||
@ -67,6 +74,7 @@ public final class TestColumnHelper extends TestCase {
|
|||||||
assertFalse(helper.getColumn(1, false).getHidden());
|
assertFalse(helper.getColumn(1, false).getHidden());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testSortColumns() {
|
public void testSortColumns() {
|
||||||
CTCols cols1 = CTCols.Factory.newInstance();
|
CTCols cols1 = CTCols.Factory.newInstance();
|
||||||
CTCol col1 = cols1.addNewCol();
|
CTCol col1 = cols1.addNewCol();
|
||||||
@ -112,6 +120,7 @@ public final class TestColumnHelper extends TestCase {
|
|||||||
assertEquals(27, cols1.getColArray(8).getMax());
|
assertEquals(27, cols1.getColArray(8).getMax());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testCloneCol() {
|
public void testCloneCol() {
|
||||||
CTWorksheet worksheet = CTWorksheet.Factory.newInstance();
|
CTWorksheet worksheet = CTWorksheet.Factory.newInstance();
|
||||||
ColumnHelper helper = new ColumnHelper(worksheet);
|
ColumnHelper helper = new ColumnHelper(worksheet);
|
||||||
@ -129,6 +138,7 @@ public final class TestColumnHelper extends TestCase {
|
|||||||
assertEquals(13.4, newCol.getWidth(), 0.0);
|
assertEquals(13.4, newCol.getWidth(), 0.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testAddCleanColIntoCols() {
|
public void testAddCleanColIntoCols() {
|
||||||
CTWorksheet worksheet = CTWorksheet.Factory.newInstance();
|
CTWorksheet worksheet = CTWorksheet.Factory.newInstance();
|
||||||
ColumnHelper helper = new ColumnHelper(worksheet);
|
ColumnHelper helper = new ColumnHelper(worksheet);
|
||||||
@ -180,12 +190,14 @@ public final class TestColumnHelper extends TestCase {
|
|||||||
assertEquals(16750, cols1.getColArray(11).getMax());
|
assertEquals(16750, cols1.getColArray(11).getMax());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testAddCleanColIntoColsExactOverlap() throws Exception {
|
public void testAddCleanColIntoColsExactOverlap() throws Exception {
|
||||||
CTCols cols = createHiddenAndBestFitColsWithHelper(1, 1, 1, 1);
|
CTCols cols = createHiddenAndBestFitColsWithHelper(1, 1, 1, 1);
|
||||||
assertEquals(1, cols.sizeOfColArray());
|
assertEquals(1, cols.sizeOfColArray());
|
||||||
assertMinMaxHiddenBestFit(cols, 0, 1, 1, true, true);
|
assertMinMaxHiddenBestFit(cols, 0, 1, 1, true, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testAddCleanColIntoColsOverlapsOverhangingBothSides() throws Exception {
|
public void testAddCleanColIntoColsOverlapsOverhangingBothSides() throws Exception {
|
||||||
CTCols cols = createHiddenAndBestFitColsWithHelper(2, 2, 1, 3);
|
CTCols cols = createHiddenAndBestFitColsWithHelper(2, 2, 1, 3);
|
||||||
assertEquals(3, cols.sizeOfColArray());
|
assertEquals(3, cols.sizeOfColArray());
|
||||||
@ -194,6 +206,7 @@ public final class TestColumnHelper extends TestCase {
|
|||||||
assertMinMaxHiddenBestFit(cols, 2, 3, 3, false, true);
|
assertMinMaxHiddenBestFit(cols, 2, 3, 3, false, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testAddCleanColIntoColsOverlapsCompletelyNested() throws Exception {
|
public void testAddCleanColIntoColsOverlapsCompletelyNested() throws Exception {
|
||||||
CTCols cols = createHiddenAndBestFitColsWithHelper(1, 3, 2, 2);
|
CTCols cols = createHiddenAndBestFitColsWithHelper(1, 3, 2, 2);
|
||||||
assertEquals(3, cols.sizeOfColArray());
|
assertEquals(3, cols.sizeOfColArray());
|
||||||
@ -202,6 +215,7 @@ public final class TestColumnHelper extends TestCase {
|
|||||||
assertMinMaxHiddenBestFit(cols, 2, 3, 3, true, false);
|
assertMinMaxHiddenBestFit(cols, 2, 3, 3, true, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testAddCleanColIntoColsNewOverlapsOverhangingLeftNotRightExactRight() throws Exception {
|
public void testAddCleanColIntoColsNewOverlapsOverhangingLeftNotRightExactRight() throws Exception {
|
||||||
CTCols cols = createHiddenAndBestFitColsWithHelper(2, 3, 1, 3);
|
CTCols cols = createHiddenAndBestFitColsWithHelper(2, 3, 1, 3);
|
||||||
assertEquals(2, cols.sizeOfColArray());
|
assertEquals(2, cols.sizeOfColArray());
|
||||||
@ -209,6 +223,7 @@ public final class TestColumnHelper extends TestCase {
|
|||||||
assertMinMaxHiddenBestFit(cols, 1, 2, 3, true, true);
|
assertMinMaxHiddenBestFit(cols, 1, 2, 3, true, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testAddCleanColIntoColsNewOverlapsOverhangingRightNotLeftExactLeft() throws Exception {
|
public void testAddCleanColIntoColsNewOverlapsOverhangingRightNotLeftExactLeft() throws Exception {
|
||||||
CTCols cols = createHiddenAndBestFitColsWithHelper(1, 2, 1, 3);
|
CTCols cols = createHiddenAndBestFitColsWithHelper(1, 2, 1, 3);
|
||||||
assertEquals(2, cols.sizeOfColArray());
|
assertEquals(2, cols.sizeOfColArray());
|
||||||
@ -216,6 +231,7 @@ public final class TestColumnHelper extends TestCase {
|
|||||||
assertMinMaxHiddenBestFit(cols, 1, 3, 3, false, true);
|
assertMinMaxHiddenBestFit(cols, 1, 3, 3, false, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testAddCleanColIntoColsNewOverlapsOverhangingLeftNotRight() throws Exception {
|
public void testAddCleanColIntoColsNewOverlapsOverhangingLeftNotRight() throws Exception {
|
||||||
CTCols cols = createHiddenAndBestFitColsWithHelper(2, 3, 1, 2);
|
CTCols cols = createHiddenAndBestFitColsWithHelper(2, 3, 1, 2);
|
||||||
assertEquals(3, cols.sizeOfColArray());
|
assertEquals(3, cols.sizeOfColArray());
|
||||||
@ -224,6 +240,7 @@ public final class TestColumnHelper extends TestCase {
|
|||||||
assertMinMaxHiddenBestFit(cols, 2, 3, 3, true, false);
|
assertMinMaxHiddenBestFit(cols, 2, 3, 3, true, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testAddCleanColIntoColsNewOverlapsOverhangingRightNotLeft() throws Exception {
|
public void testAddCleanColIntoColsNewOverlapsOverhangingRightNotLeft() throws Exception {
|
||||||
CTCols cols = createHiddenAndBestFitColsWithHelper(1, 2, 2, 3);
|
CTCols cols = createHiddenAndBestFitColsWithHelper(1, 2, 2, 3);
|
||||||
assertEquals(3, cols.sizeOfColArray());
|
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.
|
* Creates and adds a hidden column and then a best fit column with the given min/max pairs.
|
||||||
* Suitable for testing handling of overlap.
|
* 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();
|
CTWorksheet worksheet = CTWorksheet.Factory.newInstance();
|
||||||
ColumnHelper helper = new ColumnHelper(worksheet);
|
ColumnHelper helper = new ColumnHelper(worksheet);
|
||||||
CTCols cols = worksheet.getColsArray(0);
|
CTCols cols = worksheet.getColsArray(0);
|
||||||
@ -251,7 +268,7 @@ public final class TestColumnHelper extends TestCase {
|
|||||||
return cols;
|
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);
|
CTCol col = cols.getColArray(index);
|
||||||
assertEquals(min, col.getMin());
|
assertEquals(min, col.getMin());
|
||||||
assertEquals(max, col.getMax());
|
assertEquals(max, col.getMax());
|
||||||
@ -259,13 +276,14 @@ public final class TestColumnHelper extends TestCase {
|
|||||||
assertEquals(bestFit, col.getBestFit());
|
assertEquals(bestFit, col.getBestFit());
|
||||||
}
|
}
|
||||||
|
|
||||||
private CTCol createCol(int min, int max) {
|
private static CTCol createCol(int min, int max) {
|
||||||
CTCol col = CTCol.Factory.newInstance();
|
CTCol col = CTCol.Factory.newInstance();
|
||||||
col.setMin(min);
|
col.setMin(min);
|
||||||
col.setMax(max);
|
col.setMax(max);
|
||||||
return col;
|
return col;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testGetColumn() {
|
public void testGetColumn() {
|
||||||
CTWorksheet worksheet = CTWorksheet.Factory.newInstance();
|
CTWorksheet worksheet = CTWorksheet.Factory.newInstance();
|
||||||
|
|
||||||
@ -295,6 +313,7 @@ public final class TestColumnHelper extends TestCase {
|
|||||||
assertNotNull(helper.getColumn(5, false));
|
assertNotNull(helper.getColumn(5, false));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testSetColumnAttributes() {
|
public void testSetColumnAttributes() {
|
||||||
CTCol col = CTCol.Factory.newInstance();
|
CTCol col = CTCol.Factory.newInstance();
|
||||||
col.setWidth(12);
|
col.setWidth(12);
|
||||||
@ -309,6 +328,7 @@ public final class TestColumnHelper extends TestCase {
|
|||||||
assertTrue(newCol.getHidden());
|
assertTrue(newCol.getHidden());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testGetOrCreateColumn() {
|
public void testGetOrCreateColumn() {
|
||||||
XSSFWorkbook workbook = new XSSFWorkbook();
|
XSSFWorkbook workbook = new XSSFWorkbook();
|
||||||
XSSFSheet sheet = workbook.createSheet("Sheet 1");
|
XSSFSheet sheet = workbook.createSheet("Sheet 1");
|
||||||
@ -330,6 +350,7 @@ public final class TestColumnHelper extends TestCase {
|
|||||||
assertNull(columnHelper.getColumn(30, false));
|
assertNull(columnHelper.getColumn(30, false));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testGetSetColDefaultStyle() {
|
public void testGetSetColDefaultStyle() {
|
||||||
XSSFWorkbook workbook = new XSSFWorkbook();
|
XSSFWorkbook workbook = new XSSFWorkbook();
|
||||||
XSSFSheet sheet = workbook.createSheet();
|
XSSFSheet sheet = workbook.createSheet();
|
||||||
|
Loading…
Reference in New Issue
Block a user