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;
* Tests for {@link ColumnHelper}
*
*/
-public final class TestColumnHelper extends TestCase {
+public final class TestColumnHelper {
+ @Test
public void testCleanColumns() {
CTWorksheet worksheet = CTWorksheet.Factory.newInstance();
assertFalse(helper.getColumn(1, false).getHidden());
}
+ @Test
public void testSortColumns() {
CTCols cols1 = CTCols.Factory.newInstance();
CTCol col1 = cols1.addNewCol();
assertEquals(27, cols1.getColArray(8).getMax());
}
+ @Test
public void testCloneCol() {
CTWorksheet worksheet = CTWorksheet.Factory.newInstance();
ColumnHelper helper = new ColumnHelper(worksheet);
assertEquals(13.4, newCol.getWidth(), 0.0);
}
+ @Test
public void testAddCleanColIntoCols() {
CTWorksheet worksheet = CTWorksheet.Factory.newInstance();
ColumnHelper helper = new ColumnHelper(worksheet);
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());
assertMinMaxHiddenBestFit(cols, 2, 3, 3, false, true);
}
+ @Test
public void testAddCleanColIntoColsOverlapsCompletelyNested() throws Exception {
CTCols cols = createHiddenAndBestFitColsWithHelper(1, 3, 2, 2);
assertEquals(3, cols.sizeOfColArray());
assertMinMaxHiddenBestFit(cols, 2, 3, 3, true, false);
}
+ @Test
public void testAddCleanColIntoColsNewOverlapsOverhangingLeftNotRightExactRight() throws Exception {
CTCols cols = createHiddenAndBestFitColsWithHelper(2, 3, 1, 3);
assertEquals(2, cols.sizeOfColArray());
assertMinMaxHiddenBestFit(cols, 1, 2, 3, true, true);
}
+ @Test
public void testAddCleanColIntoColsNewOverlapsOverhangingRightNotLeftExactLeft() throws Exception {
CTCols cols = createHiddenAndBestFitColsWithHelper(1, 2, 1, 3);
assertEquals(2, cols.sizeOfColArray());
assertMinMaxHiddenBestFit(cols, 1, 3, 3, false, true);
}
+ @Test
public void testAddCleanColIntoColsNewOverlapsOverhangingLeftNotRight() throws Exception {
CTCols cols = createHiddenAndBestFitColsWithHelper(2, 3, 1, 2);
assertEquals(3, cols.sizeOfColArray());
assertMinMaxHiddenBestFit(cols, 2, 3, 3, true, false);
}
+ @Test
public void testAddCleanColIntoColsNewOverlapsOverhangingRightNotLeft() throws Exception {
CTCols cols = createHiddenAndBestFitColsWithHelper(1, 2, 2, 3);
assertEquals(3, cols.sizeOfColArray());
* 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);
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());
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();
assertNotNull(helper.getColumn(5, false));
}
+ @Test
public void testSetColumnAttributes() {
CTCol col = CTCol.Factory.newInstance();
col.setWidth(12);
assertTrue(newCol.getHidden());
}
+ @Test
public void testGetOrCreateColumn() {
XSSFWorkbook workbook = new XSSFWorkbook();
XSSFSheet sheet = workbook.createSheet("Sheet 1");
assertNull(columnHelper.getColumn(30, false));
}
+ @Test
public void testGetSetColDefaultStyle() {
XSSFWorkbook workbook = new XSSFWorkbook();
XSSFSheet sheet = workbook.createSheet();