Modified: poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestCellStyle.java URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestCellStyle.java?rev=1800375&r1=1800374&r2=1800375&view=diff ============================================================================== --- poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestCellStyle.java (original) +++ poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestCellStyle.java Fri Jun 30 11:48:23 2017 @@ -28,7 +28,9 @@ import org.apache.poi.ss.usermodel.Borde import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.CellStyle; import org.apache.poi.ss.usermodel.CellType; +import org.apache.poi.ss.usermodel.FillPatternType; import org.apache.poi.ss.usermodel.Font; +import org.apache.poi.ss.usermodel.HorizontalAlignment; import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Workbook; @@ -187,11 +189,11 @@ public final class TestCellStyle extends cs.setBorderRight(BorderStyle.THIN); cs.setBorderTop(BorderStyle.THIN); cs.setFillForegroundColor(( short ) 0xA); - cs.setFillPattern(( short ) 1); + cs.setFillPattern(FillPatternType.DIAMONDS); fnt.setColor(( short ) 0xf); fnt.setItalic(true); cs2.setFillForegroundColor(( short ) 0x0); - cs2.setFillPattern(( short ) 1); + cs2.setFillPattern(FillPatternType.DIAMONDS); cs2.setFont(fnt); for (int rownum = 0; rownum < 100; rownum++) { r = s.createRow(rownum); @@ -226,23 +228,23 @@ public final class TestCellStyle extends assertEquals(5, wb.getNumberOfFonts()); HSSFCellStyle orig = wb.createCellStyle(); - orig.setAlignment(HSSFCellStyle.ALIGN_RIGHT); + orig.setAlignment(HorizontalAlignment.JUSTIFY); orig.setFont(fnt); orig.setDataFormat((short)18); - assertTrue(HSSFCellStyle.ALIGN_RIGHT == orig.getAlignment()); - assertTrue(fnt == orig.getFont(wb)); - assertTrue(18 == orig.getDataFormat()); + assertEquals(HorizontalAlignment.JUSTIFY, orig.getAlignmentEnum()); + assertEquals(fnt, orig.getFont(wb)); + assertEquals(18, orig.getDataFormat()); HSSFCellStyle clone = wb.createCellStyle(); - assertFalse(HSSFCellStyle.ALIGN_RIGHT == clone.getAlignment()); + assertFalse(HorizontalAlignment.RIGHT == clone.getAlignmentEnum()); assertFalse(fnt == clone.getFont(wb)); assertFalse(18 == clone.getDataFormat()); clone.cloneStyleFrom(orig); - assertTrue(HSSFCellStyle.ALIGN_RIGHT == clone.getAlignment()); - assertTrue(fnt == clone.getFont(wb)); - assertTrue(18 == clone.getDataFormat()); + assertEquals(HorizontalAlignment.JUSTIFY, clone.getAlignmentEnum()); + assertEquals(fnt, clone.getFont(wb)); + assertEquals(18, clone.getDataFormat()); assertEquals(5, wb.getNumberOfFonts()); } @@ -262,13 +264,13 @@ public final class TestCellStyle extends fmt.getFormat("MadeUpTwo"); HSSFCellStyle orig = wbOrig.createCellStyle(); - orig.setAlignment(HSSFCellStyle.ALIGN_RIGHT); + orig.setAlignment(HorizontalAlignment.RIGHT); orig.setFont(fnt); orig.setDataFormat(fmt.getFormat("Test##")); - assertTrue(HSSFCellStyle.ALIGN_RIGHT == orig.getAlignment()); - assertTrue(fnt == orig.getFont(wbOrig)); - assertTrue(fmt.getFormat("Test##") == orig.getDataFormat()); + assertEquals(HorizontalAlignment.RIGHT, orig.getAlignmentEnum()); + assertEquals(fnt, orig.getFont(wbOrig)); + assertEquals(fmt.getFormat("Test##"), orig.getDataFormat()); // Now a style on another workbook HSSFWorkbook wbClone = new HSSFWorkbook(); @@ -278,13 +280,13 @@ public final class TestCellStyle extends HSSFCellStyle clone = wbClone.createCellStyle(); assertEquals(4, wbClone.getNumberOfFonts()); - assertFalse(HSSFCellStyle.ALIGN_RIGHT == clone.getAlignment()); + assertFalse(HorizontalAlignment.RIGHT == clone.getAlignmentEnum()); assertFalse("TestingFont" == clone.getFont(wbClone).getFontName()); clone.cloneStyleFrom(orig); - assertTrue(HSSFCellStyle.ALIGN_RIGHT == clone.getAlignment()); - assertTrue("TestingFont" == clone.getFont(wbClone).getFontName()); - assertTrue(fmtClone.getFormat("Test##") == clone.getDataFormat()); + assertEquals(HorizontalAlignment.RIGHT, clone.getAlignmentEnum()); + assertEquals("TestingFont", clone.getFont(wbClone).getFontName()); + assertEquals(fmtClone.getFormat("Test##"), clone.getDataFormat()); assertFalse(fmtClone.getFormat("Test##") == fmt.getFormat("Test##")); assertEquals(5, wbClone.getNumberOfFonts()); }
Modified: poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFOptimiser.java URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFOptimiser.java?rev=1800375&r1=1800374&r2=1800375&view=diff ============================================================================== --- poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFOptimiser.java (original) +++ poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFOptimiser.java Fri Jun 30 11:48:23 2017 @@ -17,6 +17,7 @@ package org.apache.poi.hssf.usermodel; import org.apache.poi.ss.usermodel.BorderStyle; +import org.apache.poi.ss.usermodel.HorizontalAlignment; import junit.framework.TestCase; @@ -158,119 +159,119 @@ public final class TestHSSFOptimiser ext } public void testOptimiseStyles() { - HSSFWorkbook wb = new HSSFWorkbook(); - - // Two fonts - assertEquals(4, wb.getNumberOfFonts()); - - HSSFFont f1 = wb.createFont(); - f1.setFontHeight((short) 11); - f1.setFontName("Testing"); - - HSSFFont f2 = wb.createFont(); - f2.setFontHeight((short) 22); - f2.setFontName("Also Testing"); - - assertEquals(6, wb.getNumberOfFonts()); - - // Several styles - assertEquals(21, wb.getNumCellStyles()); - - HSSFCellStyle cs1 = wb.createCellStyle(); - cs1.setFont(f1); - - HSSFCellStyle cs2 = wb.createCellStyle(); - cs2.setFont(f2); - - HSSFCellStyle cs3 = wb.createCellStyle(); - cs3.setFont(f1); - - HSSFCellStyle cs4 = wb.createCellStyle(); - cs4.setFont(f1); - cs4.setAlignment((short) 22); + HSSFWorkbook wb = new HSSFWorkbook(); - HSSFCellStyle cs5 = wb.createCellStyle(); - cs5.setFont(f2); - cs5.setAlignment((short) 111); + // Two fonts + assertEquals(4, wb.getNumberOfFonts()); - HSSFCellStyle cs6 = wb.createCellStyle(); - cs6.setFont(f2); - - assertEquals(27, wb.getNumCellStyles()); - - // Use them - HSSFSheet s = wb.createSheet(); - HSSFRow r = s.createRow(0); + HSSFFont f1 = wb.createFont(); + f1.setFontHeight((short) 11); + f1.setFontName("Testing"); + + HSSFFont f2 = wb.createFont(); + f2.setFontHeight((short) 22); + f2.setFontName("Also Testing"); + + assertEquals(6, wb.getNumberOfFonts()); + + // Several styles + assertEquals(21, wb.getNumCellStyles()); + + HSSFCellStyle cs1 = wb.createCellStyle(); + cs1.setFont(f1); + + HSSFCellStyle cs2 = wb.createCellStyle(); + cs2.setFont(f2); + + HSSFCellStyle cs3 = wb.createCellStyle(); + cs3.setFont(f1); + + HSSFCellStyle cs4 = wb.createCellStyle(); + cs4.setFont(f1); + cs4.setAlignment(HorizontalAlignment.CENTER); + + HSSFCellStyle cs5 = wb.createCellStyle(); + cs5.setFont(f2); + cs5.setAlignment(HorizontalAlignment.FILL); + + HSSFCellStyle cs6 = wb.createCellStyle(); + cs6.setFont(f2); + + assertEquals(27, wb.getNumCellStyles()); + + // Use them + HSSFSheet s = wb.createSheet(); + HSSFRow r = s.createRow(0); + + r.createCell(0).setCellStyle(cs1); + r.createCell(1).setCellStyle(cs2); + r.createCell(2).setCellStyle(cs3); + r.createCell(3).setCellStyle(cs4); + r.createCell(4).setCellStyle(cs5); + r.createCell(5).setCellStyle(cs6); + r.createCell(6).setCellStyle(cs1); + r.createCell(7).setCellStyle(cs2); + + assertEquals(21, r.getCell(0).getCellValueRecord().getXFIndex()); + assertEquals(26, r.getCell(5).getCellValueRecord().getXFIndex()); + assertEquals(21, r.getCell(6).getCellValueRecord().getXFIndex()); + + // Optimise + HSSFOptimiser.optimiseCellStyles(wb); + + // Check + assertEquals(6, wb.getNumberOfFonts()); + assertEquals(25, wb.getNumCellStyles()); + + // cs1 -> 21 + assertEquals(21, r.getCell(0).getCellValueRecord().getXFIndex()); + // cs2 -> 22 + assertEquals(22, r.getCell(1).getCellValueRecord().getXFIndex()); + assertEquals(22, r.getCell(1).getCellStyle().getFont(wb).getFontHeight()); + // cs3 = cs1 -> 21 + assertEquals(21, r.getCell(2).getCellValueRecord().getXFIndex()); + // cs4 --> 24 -> 23 + assertEquals(23, r.getCell(3).getCellValueRecord().getXFIndex()); + // cs5 --> 25 -> 24 + assertEquals(24, r.getCell(4).getCellValueRecord().getXFIndex()); + // cs6 = cs2 -> 22 + assertEquals(22, r.getCell(5).getCellValueRecord().getXFIndex()); + // cs1 -> 21 + assertEquals(21, r.getCell(6).getCellValueRecord().getXFIndex()); + // cs2 -> 22 + assertEquals(22, r.getCell(7).getCellValueRecord().getXFIndex()); + + + // Add a new duplicate, and two that aren't used + HSSFCellStyle csD = wb.createCellStyle(); + csD.setFont(f1); + r.createCell(8).setCellStyle(csD); + + HSSFFont f3 = wb.createFont(); + f3.setFontHeight((short) 23); + f3.setFontName("Testing 3"); + HSSFFont f4 = wb.createFont(); + f4.setFontHeight((short) 24); + f4.setFontName("Testing 4"); + + HSSFCellStyle csU1 = wb.createCellStyle(); + csU1.setFont(f3); + HSSFCellStyle csU2 = wb.createCellStyle(); + csU2.setFont(f4); + + // Check before the optimise + assertEquals(8, wb.getNumberOfFonts()); + assertEquals(28, wb.getNumCellStyles()); + + // Optimise, should remove the two un-used ones and the one duplicate + HSSFOptimiser.optimiseCellStyles(wb); + + // Check + assertEquals(8, wb.getNumberOfFonts()); + assertEquals(25, wb.getNumCellStyles()); - r.createCell(0).setCellStyle(cs1); - r.createCell(1).setCellStyle(cs2); - r.createCell(2).setCellStyle(cs3); - r.createCell(3).setCellStyle(cs4); - r.createCell(4).setCellStyle(cs5); - r.createCell(5).setCellStyle(cs6); - r.createCell(6).setCellStyle(cs1); - r.createCell(7).setCellStyle(cs2); - - assertEquals(21, r.getCell(0).getCellValueRecord().getXFIndex()); - assertEquals(26, r.getCell(5).getCellValueRecord().getXFIndex()); - assertEquals(21, r.getCell(6).getCellValueRecord().getXFIndex()); - - // Optimise - HSSFOptimiser.optimiseCellStyles(wb); - - // Check - assertEquals(6, wb.getNumberOfFonts()); - assertEquals(25, wb.getNumCellStyles()); - - // cs1 -> 21 - assertEquals(21, r.getCell(0).getCellValueRecord().getXFIndex()); - // cs2 -> 22 - assertEquals(22, r.getCell(1).getCellValueRecord().getXFIndex()); - assertEquals(22, r.getCell(1).getCellStyle().getFont(wb).getFontHeight()); - // cs3 = cs1 -> 21 - assertEquals(21, r.getCell(2).getCellValueRecord().getXFIndex()); - // cs4 --> 24 -> 23 - assertEquals(23, r.getCell(3).getCellValueRecord().getXFIndex()); - // cs5 --> 25 -> 24 - assertEquals(24, r.getCell(4).getCellValueRecord().getXFIndex()); - // cs6 = cs2 -> 22 - assertEquals(22, r.getCell(5).getCellValueRecord().getXFIndex()); - // cs1 -> 21 - assertEquals(21, r.getCell(6).getCellValueRecord().getXFIndex()); - // cs2 -> 22 - assertEquals(22, r.getCell(7).getCellValueRecord().getXFIndex()); - - - // Add a new duplicate, and two that aren't used - HSSFCellStyle csD = wb.createCellStyle(); - csD.setFont(f1); - r.createCell(8).setCellStyle(csD); - - HSSFFont f3 = wb.createFont(); - f3.setFontHeight((short) 23); - f3.setFontName("Testing 3"); - HSSFFont f4 = wb.createFont(); - f4.setFontHeight((short) 24); - f4.setFontName("Testing 4"); - - HSSFCellStyle csU1 = wb.createCellStyle(); - csU1.setFont(f3); - HSSFCellStyle csU2 = wb.createCellStyle(); - csU2.setFont(f4); - - // Check before the optimise - assertEquals(8, wb.getNumberOfFonts()); - assertEquals(28, wb.getNumCellStyles()); - - // Optimise, should remove the two un-used ones and the one duplicate - HSSFOptimiser.optimiseCellStyles(wb); - - // Check - assertEquals(8, wb.getNumberOfFonts()); - assertEquals(25, wb.getNumCellStyles()); - - // csD -> cs1 -> 21 - assertEquals(21, r.getCell(8).getCellValueRecord().getXFIndex()); + // csD -> cs1 -> 21 + assertEquals(21, r.getCell(8).getCellValueRecord().getXFIndex()); } public void testOptimiseStylesCheckActualStyles() { Modified: poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestRowStyle.java URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestRowStyle.java?rev=1800375&r1=1800374&r2=1800375&view=diff ============================================================================== --- poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestRowStyle.java (original) +++ poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestRowStyle.java Fri Jun 30 11:48:23 2017 @@ -19,6 +19,7 @@ package org.apache.poi.hssf.usermodel; import org.apache.poi.hssf.HSSFTestDataSamples; import org.apache.poi.ss.usermodel.BorderStyle; +import org.apache.poi.ss.usermodel.FillPatternType; import org.apache.poi.util.IOUtils; import junit.framework.TestCase; @@ -118,11 +119,11 @@ public final class TestRowStyle extends cs.setBorderRight(BorderStyle.THIN); cs.setBorderTop(BorderStyle.THIN); cs.setFillForegroundColor(( short ) 0xA); - cs.setFillPattern(( short ) 1); + cs.setFillPattern(FillPatternType.BRICKS); fnt.setColor(( short ) 0xf); fnt.setItalic(true); cs2.setFillForegroundColor(( short ) 0x0); - cs2.setFillPattern(( short ) 1); + cs2.setFillPattern(FillPatternType.BRICKS); cs2.setFont(fnt); for (int rownum = 0; rownum < 100; rownum++) { @@ -159,7 +160,7 @@ public final class TestRowStyle extends assertEquals("Right Border Style for row:", BorderStyle.THIN, cs.getBorderRightEnum()); assertEquals("Top Border Style for row:", BorderStyle.THIN, cs.getBorderTopEnum()); assertEquals("FillForegroundColor for row:", 0xA, cs.getFillForegroundColor()); - assertEquals("FillPattern for row:", 0x1, cs.getFillPattern()); + assertEquals("FillPattern for row:", FillPatternType.BRICKS, cs.getFillPatternEnum()); rownum++; if (rownum >= 100) break; // I feel too lazy to check if this isreqd :-/ @@ -168,7 +169,7 @@ public final class TestRowStyle extends assertNotNull("Row is not null", r); cs2 = r.getRowStyle(); assertEquals("FillForegroundColor for row: ", cs2.getFillForegroundColor(), (short) 0x0); - assertEquals("FillPattern for row: ", cs2.getFillPattern(), (short) 0x1); + assertEquals("FillPattern for row: ", cs2.getFillPatternEnum(), FillPatternType.BRICKS); } IOUtils.closeQuietly(wb2); } Modified: poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestBugzillaIssues.java URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestBugzillaIssues.java?rev=1800375&r1=1800374&r2=1800375&view=diff ============================================================================== --- poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestBugzillaIssues.java (original) +++ poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestBugzillaIssues.java Fri Jun 30 11:48:23 2017 @@ -1041,14 +1041,13 @@ public abstract class BaseTestBugzillaIs wb.close(); } - @SuppressWarnings("deprecation") @Test public void bug56981() throws IOException { Workbook wb = _testDataProvider.createWorkbook(); CellStyle vertTop = wb.createCellStyle(); - vertTop.setVerticalAlignment(CellStyle.VERTICAL_TOP); + vertTop.setVerticalAlignment(VerticalAlignment.TOP); CellStyle vertBottom = wb.createCellStyle(); - vertBottom.setVerticalAlignment(CellStyle.VERTICAL_BOTTOM); + vertBottom.setVerticalAlignment(VerticalAlignment.BOTTOM); Sheet sheet = wb.createSheet("Sheet 1"); Row row = sheet.createRow(0); Cell top = row.createCell(0); @@ -1298,7 +1297,6 @@ public abstract class BaseTestBugzillaIs wb2.close(); } - @SuppressWarnings("deprecation") @Test public void bug58260() throws IOException { //Create workbook and worksheet @@ -1320,7 +1318,7 @@ public abstract class BaseTestBugzillaIs } catch (IllegalStateException e) { fail("Failed for row " + i); } - style.setAlignment(CellStyle.ALIGN_RIGHT); + style.setAlignment(HorizontalAlignment.RIGHT); if((wb instanceof HSSFWorkbook)) { // there are some predefined styles assertEquals(i+21, style.getIndex()); Modified: poi/trunk/src/testcases/org/apache/poi/ss/util/BaseTestCellUtil.java URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/util/BaseTestCellUtil.java?rev=1800375&r1=1800374&r2=1800375&view=diff ============================================================================== --- poi/trunk/src/testcases/org/apache/poi/ss/util/BaseTestCellUtil.java (original) +++ poi/trunk/src/testcases/org/apache/poi/ss/util/BaseTestCellUtil.java Fri Jun 30 11:48:23 2017 @@ -232,17 +232,17 @@ public class BaseTestCellUtil { // should be assertSame, but a new HSSFCellStyle is returned for each getCellStyle() call. // HSSFCellStyle wraps an underlying style record, and the underlying // style record is the same between multiple getCellStyle() calls. - assertEquals(CellStyle.ALIGN_GENERAL, A1.getCellStyle().getAlignment()); - assertEquals(CellStyle.ALIGN_GENERAL, B1.getCellStyle().getAlignment()); + assertEquals(HorizontalAlignment.GENERAL, A1.getCellStyle().getAlignmentEnum()); + assertEquals(HorizontalAlignment.GENERAL, B1.getCellStyle().getAlignmentEnum()); // get/set alignment modifies the cell's style - CellUtil.setAlignment(A1, null, CellStyle.ALIGN_RIGHT); - assertEquals(CellStyle.ALIGN_RIGHT, A1.getCellStyle().getAlignment()); + CellUtil.setAlignment(A1, HorizontalAlignment.RIGHT); + assertEquals(HorizontalAlignment.RIGHT, A1.getCellStyle().getAlignmentEnum()); // get/set alignment doesn't affect the style of cells with // the same style prior to modifying the style assertNotEquals(A1.getCellStyle(), B1.getCellStyle()); - assertEquals(CellStyle.ALIGN_GENERAL, B1.getCellStyle().getAlignment()); + assertEquals(HorizontalAlignment.GENERAL, B1.getCellStyle().getAlignmentEnum()); wb.close(); } @@ -377,15 +377,13 @@ public class BaseTestCellUtil { Workbook wb1 = _testDataProvider.createWorkbook(); Cell A1 = wb1.createSheet().createRow(0).createCell(0); Map<String, Object> properties = new HashMap<String, Object>(); - // FIXME: Use FillPatternType.BRICKS enum - properties.put(CellUtil.FILL_PATTERN, CellStyle.BRICKS); + properties.put(CellUtil.FILL_PATTERN, FillPatternType.BRICKS); properties.put(CellUtil.FILL_FOREGROUND_COLOR, IndexedColors.BLUE.index); properties.put(CellUtil.FILL_BACKGROUND_COLOR, IndexedColors.RED.index); CellUtil.setCellStyleProperties(A1, properties); CellStyle style = A1.getCellStyle(); - // FIXME: Use FillPatternType.BRICKS enum - assertEquals("fill pattern", CellStyle.BRICKS, style.getFillPattern()); + assertEquals("fill pattern", FillPatternType.BRICKS, style.getFillPatternEnum()); assertEquals("fill foreground color", IndexedColors.BLUE, IndexedColors.fromInt(style.getFillForegroundColor())); assertEquals("fill background color", IndexedColors.RED, IndexedColors.fromInt(style.getFillBackgroundColor())); wb1.close(); @@ -399,14 +397,12 @@ public class BaseTestCellUtil { Workbook wb1 = _testDataProvider.createWorkbook(); Cell A1 = wb1.createSheet().createRow(0).createCell(0); Map<String, Object> properties = new HashMap<String, Object>(); - // FIXME: Use FillPatternType.BRICKS enum properties.put(CellUtil.FILL_PATTERN, FillPatternType.BRICKS); properties.put(CellUtil.FILL_FOREGROUND_COLOR, IndexedColors.BLUE.index); properties.put(CellUtil.FILL_BACKGROUND_COLOR, IndexedColors.RED.index); CellUtil.setCellStyleProperties(A1, properties); CellStyle style = A1.getCellStyle(); - // FIXME: Use FillPatternType.BRICKS enum assertEquals("fill pattern", FillPatternType.BRICKS, style.getFillPatternEnum()); assertEquals("fill foreground color", IndexedColors.BLUE, IndexedColors.fromInt(style.getFillForegroundColor())); assertEquals("fill background color", IndexedColors.RED, IndexedColors.fromInt(style.getFillBackgroundColor())); --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@poi.apache.org For additional commands, e-mail: commits-h...@poi.apache.org