diff options
author | PJ Fanning <fanningpj@apache.org> | 2017-06-28 10:34:37 +0000 |
---|---|---|
committer | PJ Fanning <fanningpj@apache.org> | 2017-06-28 10:34:37 +0000 |
commit | b68b916d0890a0088db173ea08477d48f80dfc33 (patch) | |
tree | 19e992813e160c50e2e8f884bc3d8ce8217e81bc /src/testcases/org/apache/poi | |
parent | 995a28cd868a83fbcbba8d20d459b1eecc45aae4 (diff) | |
download | poi-b68b916d0890a0088db173ea08477d48f80dfc33.tar.gz poi-b68b916d0890a0088db173ea08477d48f80dfc33.zip |
Remove some deprecated *SSF APIs
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1800147 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/testcases/org/apache/poi')
9 files changed, 76 insertions, 43 deletions
diff --git a/src/testcases/org/apache/poi/hssf/model/TestDrawingShapes.java b/src/testcases/org/apache/poi/hssf/model/TestDrawingShapes.java index 2c00cbfe0e..27089fe8d5 100644 --- a/src/testcases/org/apache/poi/hssf/model/TestDrawingShapes.java +++ b/src/testcases/org/apache/poi/hssf/model/TestDrawingShapes.java @@ -154,7 +154,7 @@ public class TestDrawingShapes { anchor.setAnchorType(AnchorType.MOVE_DONT_RESIZE); assertEquals(AnchorType.MOVE_DONT_RESIZE, anchor.getAnchorType()); //noinspection deprecation - anchor.setAnchorType(AnchorType.MOVE_DONT_RESIZE.value); + anchor.setAnchorType(AnchorType.MOVE_DONT_RESIZE); assertEquals(AnchorType.MOVE_DONT_RESIZE, anchor.getAnchorType()); HSSFSimpleShape rectangle = drawing.createSimpleShape(anchor); diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java b/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java index 06354fb0c5..d4abaf59a5 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java @@ -17,6 +17,7 @@ package org.apache.poi.hssf.usermodel; +import static org.apache.poi.POITestCase.assertContains; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; @@ -24,7 +25,6 @@ import static org.junit.Assert.assertNull; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; -import static org.apache.poi.POITestCase.assertContains; import java.awt.image.BufferedImage; import java.io.ByteArrayInputStream; @@ -98,7 +98,6 @@ import org.junit.Test; * <b>YK: If a bug can be tested in terms of common ss interfaces, * define the test in the base class {@link BaseTestBugzillaIssues}</b> */ -@SuppressWarnings("deprecation") public final class TestBugs extends BaseTestBugzillaIssues { // to not affect other tests running in the same JVM @After @@ -996,7 +995,7 @@ public final class TestBugs extends BaseTestBugzillaIssues { assertEquals(4, wb.getNumberOfFonts()); HSSFFont f1 = wb.getFontAt((short)0); - assertEquals(400, f1.getBoldweight()); + assertFalse(f1.getBold()); // Check that asking for the same font // multiple times gives you the same thing. @@ -1020,7 +1019,7 @@ public final class TestBugs extends BaseTestBugzillaIssues { // yet to add assertNull( wb.findFont( - (short)11, (short)123, (short)22, + false, (short)123, (short)22, "Thingy", false, true, (short)2, (byte)2 ) ); @@ -1031,7 +1030,7 @@ public final class TestBugs extends BaseTestBugzillaIssues { assertEquals(5, nf.getIndex()); assertEquals(nf, wb.getFontAt((short)5)); - nf.setBoldweight((short)11); + nf.setBold(false); nf.setColor((short)123); nf.setFontHeight((short)22); nf.setFontName("Thingy"); @@ -1046,12 +1045,12 @@ public final class TestBugs extends BaseTestBugzillaIssues { // Find it now assertNotNull( wb.findFont( - (short)11, (short)123, (short)22, + false, (short)123, (short)22, "Thingy", false, true, (short)2, (byte)2 ) ); HSSFFont font = wb.findFont( - (short) 11, (short) 123, (short) 22, + false, (short) 123, (short) 22, "Thingy", false, true, (short) 2, (byte) 2 ); assertNotNull(font); @@ -1061,7 +1060,7 @@ public final class TestBugs extends BaseTestBugzillaIssues { ); assertEquals(nf, wb.findFont( - (short)11, (short)123, (short)22, + false, (short)123, (short)22, "Thingy", false, true, (short)2, (byte)2 ) ); diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestCellStyle.java b/src/testcases/org/apache/poi/hssf/usermodel/TestCellStyle.java index 62d20273df..223cac57e9 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestCellStyle.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestCellStyle.java @@ -70,7 +70,7 @@ public final class TestCellStyle extends TestCase { HSSFCellStyle cs = wb.createCellStyle(); fnt.setColor(HSSFFont.COLOR_RED); - fnt.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); + fnt.setBold(true); cs.setFont(fnt); for (int rownum = 0; rownum < 100; rownum++) { r = s.createRow(rownum); diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheet.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheet.java index 57938d8cf7..1286c3dc11 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheet.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheet.java @@ -25,7 +25,6 @@ import static org.junit.Assert.assertNull; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; -import static org.apache.poi.POITestCase.assertBetween; import java.io.IOException; import java.util.List; @@ -59,7 +58,13 @@ import org.apache.poi.hssf.record.aggregates.WorksheetProtectionBlock; import org.apache.poi.hssf.usermodel.RecordInspector.RecordCollector; import org.apache.poi.ss.formula.ptg.Area3DPtg; import org.apache.poi.ss.formula.ptg.Ptg; -import org.apache.poi.ss.usermodel.*; +import org.apache.poi.ss.usermodel.AutoFilter; +import org.apache.poi.ss.usermodel.BaseTestSheet; +import org.apache.poi.ss.usermodel.DataValidation; +import org.apache.poi.ss.usermodel.DataValidationConstraint; +import org.apache.poi.ss.usermodel.DataValidationHelper; +import org.apache.poi.ss.usermodel.Sheet; +import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.ss.util.CellRangeAddress; import org.apache.poi.ss.util.CellRangeAddressList; import org.junit.Test; @@ -505,7 +510,6 @@ public final class TestHSSFSheet extends BaseTestSheet { workbook.close(); } - @SuppressWarnings("deprecation") @Test public void zoom() throws IOException { HSSFWorkbook wb = new HSSFWorkbook(); @@ -945,7 +949,7 @@ public final class TestHSSFSheet extends BaseTestSheet { assertEquals(11*20, bs.getFont(wbSimple).getFontHeight()); assertEquals(8, bs.getFont(wbSimple).getColor()); assertFalse(bs.getFont(wbSimple).getItalic()); - assertEquals(HSSFFont.BOLDWEIGHT_NORMAL, bs.getFont(wbSimple).getBoldweight()); + assertFalse(bs.getFont(wbSimple).getBold()); HSSFCellStyle cs = wbComplex.getSheetAt(0).getColumnStyle(1); diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestRowStyle.java b/src/testcases/org/apache/poi/hssf/usermodel/TestRowStyle.java index 35519d36cf..1efc3e18af 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestRowStyle.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestRowStyle.java @@ -17,10 +17,11 @@ package org.apache.poi.hssf.usermodel; -import junit.framework.TestCase; - import org.apache.poi.hssf.HSSFTestDataSamples; import org.apache.poi.ss.usermodel.BorderStyle; +import org.apache.poi.util.IOUtils; + +import junit.framework.TestCase; /** * Class to test row styling functionality @@ -36,7 +37,6 @@ public final class TestRowStyle extends TestCase { * Last row, first row is tested against the correct values (99,0).<P> * FAILURE: HSSF does not create a sheet or excepts. Filesize does not match the known good. * HSSFSheet last row or first row is incorrect. <P> - * */ public void testWriteSheetFont() { HSSFWorkbook wb = new HSSFWorkbook(); @@ -46,7 +46,7 @@ public final class TestRowStyle extends TestCase { HSSFCellStyle cs = wb.createCellStyle(); fnt.setColor(HSSFFont.COLOR_RED); - fnt.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); + fnt.setBold(true); cs.setFont(fnt); for (int rownum = 0; rownum < 100; rownum++) { @@ -54,12 +54,14 @@ public final class TestRowStyle extends TestCase { r.setRowStyle(cs); r.createCell(0); } - wb = HSSFTestDataSamples.writeOutAndReadBack(wb); + HSSFWorkbook wb2 = HSSFTestDataSamples.writeOutAndReadBack(wb); + IOUtils.closeQuietly(wb); SanityChecker sanityChecker = new SanityChecker(); - sanityChecker.checkHSSFWorkbook(wb); + sanityChecker.checkHSSFWorkbook(wb2); assertEquals("LAST ROW == 99", 99, s.getLastRowNum()); assertEquals("FIRST ROW == 0", 0, s.getFirstRowNum()); + IOUtils.closeQuietly(wb2); } /** @@ -83,14 +85,15 @@ public final class TestRowStyle extends TestCase { row.setRowStyle(cs); row.createCell(0); - wb = HSSFTestDataSamples.writeOutAndReadBack(wb); + HSSFWorkbook wb2 = HSSFTestDataSamples.writeOutAndReadBack(wb); + IOUtils.closeQuietly(wb); SanityChecker sanityChecker = new SanityChecker(); - sanityChecker.checkHSSFWorkbook(wb); + sanityChecker.checkHSSFWorkbook(wb2); assertEquals("LAST ROW ", 1, s.getLastRowNum()); assertEquals("FIRST ROW ", 0, s.getFirstRowNum()); - + IOUtils.closeQuietly(wb2); } /** @@ -101,7 +104,6 @@ public final class TestRowStyle extends TestCase { * Last row, first row is tested against the correct values (99,0).<P> * FAILURE: HSSF does not create a sheet or excepts. Filesize does not match the known good. * HSSFSheet last row or first row is incorrect. <P> - * */ public void testWriteSheetStyle() { HSSFWorkbook wb = new HSSFWorkbook(); @@ -135,14 +137,15 @@ public final class TestRowStyle extends TestCase { r.setRowStyle(cs2); r.createCell(0); } - wb = HSSFTestDataSamples.writeOutAndReadBack(wb); + HSSFWorkbook wb2 = HSSFTestDataSamples.writeOutAndReadBack(wb); + IOUtils.closeQuietly(wb); SanityChecker sanityChecker = new SanityChecker(); - sanityChecker.checkHSSFWorkbook(wb); + sanityChecker.checkHSSFWorkbook(wb2); assertEquals("LAST ROW == 99", 99, s.getLastRowNum()); assertEquals("FIRST ROW == 0", 0, s.getFirstRowNum()); - s = wb.getSheetAt(0); + s = wb2.getSheetAt(0); assertNotNull("Sheet is not null", s); for (int rownum = 0; rownum < 100; rownum++) @@ -167,5 +170,6 @@ public final class TestRowStyle extends TestCase { assertEquals("FillForegroundColor for row: ", cs2.getFillForegroundColor(), (short) 0x0); assertEquals("FillPattern for row: ", cs2.getFillPattern(), (short) 0x1); } + IOUtils.closeQuietly(wb2); } } diff --git a/src/testcases/org/apache/poi/ss/usermodel/BaseTestFont.java b/src/testcases/org/apache/poi/ss/usermodel/BaseTestFont.java index cc4a903760..7c8b06443c 100644 --- a/src/testcases/org/apache/poi/ss/usermodel/BaseTestFont.java +++ b/src/testcases/org/apache/poi/ss/usermodel/BaseTestFont.java @@ -38,19 +38,19 @@ public abstract class BaseTestFont { protected final void baseTestDefaultFont(String defaultName, short defaultSize, short defaultColor) throws IOException { //get default font and check against default value Workbook workbook = _testDataProvider.createWorkbook(); - Font fontFind=workbook.findFont(Font.BOLDWEIGHT_NORMAL, defaultColor, defaultSize, defaultName, false, false, Font.SS_NONE, Font.U_NONE); + Font fontFind=workbook.findFont(false, defaultColor, defaultSize, defaultName, false, false, Font.SS_NONE, Font.U_NONE); assertNotNull(fontFind); //get default font, then change 2 values and check against different values (height changes) Font font=workbook.createFont(); - font.setBoldweight(Font.BOLDWEIGHT_BOLD); - assertEquals(Font.BOLDWEIGHT_BOLD, font.getBoldweight()); + font.setBold(true); + assertTrue(font.getBold()); font.setUnderline(Font.U_DOUBLE); assertEquals(Font.U_DOUBLE, font.getUnderline()); font.setFontHeightInPoints((short)15); assertEquals(15*20, font.getFontHeight()); assertEquals(15, font.getFontHeightInPoints()); - fontFind=workbook.findFont(Font.BOLDWEIGHT_BOLD, defaultColor, (short)(15*20), defaultName, false, false, Font.SS_NONE, Font.U_DOUBLE); + fontFind=workbook.findFont(true, defaultColor, (short)(15*20), defaultName, false, false, Font.SS_NONE, Font.U_DOUBLE); assertNotNull(fontFind); workbook.close(); } @@ -61,7 +61,7 @@ public abstract class BaseTestFont { int num0 = wb.getNumberOfFonts(); Font f1=wb.createFont(); - f1.setBoldweight(Font.BOLDWEIGHT_BOLD); + f1.setBold(true); short idx1 = f1.getIndex(); wb.createCellStyle().setFont(f1); @@ -76,7 +76,7 @@ public abstract class BaseTestFont { wb.createCellStyle().setFont(f3); assertEquals(num0 + 3,wb.getNumberOfFonts()); - assertEquals(Font.BOLDWEIGHT_BOLD,wb.getFontAt(idx1).getBoldweight()); + assertTrue(wb.getFontAt(idx1).getBold()); assertEquals(Font.U_DOUBLE,wb.getFontAt(idx2).getUnderline()); assertEquals(23,wb.getFontAt(idx3).getFontHeightInPoints()); wb.close(); @@ -97,7 +97,7 @@ public abstract class BaseTestFont { int num0 = wb1.getNumberOfFonts(); Font font=wb1.createFont(); - font.setBoldweight(Font.BOLDWEIGHT_BOLD); + font.setBold(true); font.setStrikeout(true); font.setColor(IndexedColors.YELLOW.getIndex()); font.setFontName("Courier"); @@ -161,7 +161,7 @@ public abstract class BaseTestFont { //default font Font f1 = wb.getFontAt((short)0); - assertEquals(Font.BOLDWEIGHT_NORMAL, f1.getBoldweight()); + assertFalse(f1.getBold()); // Check that asking for the same font // multiple times gives you the same thing. @@ -172,7 +172,7 @@ public abstract class BaseTestFont { // yet to add assertNull( wb.findFont( - Font.BOLDWEIGHT_BOLD, (short)123, (short)(22*20), + true, (short)123, (short)(22*20), "Thingy", false, true, (short)2, (byte)2 ) ); @@ -183,7 +183,7 @@ public abstract class BaseTestFont { assertSame(nf, wb.getFontAt(nfIdx)); - nf.setBoldweight(Font.BOLDWEIGHT_BOLD); + nf.setBold(true); nf.setColor((short)123); nf.setFontHeightInPoints((short)22); nf.setFontName("Thingy"); @@ -201,13 +201,13 @@ public abstract class BaseTestFont { // Find it now assertNotNull( wb.findFont( - Font.BOLDWEIGHT_BOLD, (short)123, (short)(22*20), + true, (short)123, (short)(22*20), "Thingy", false, true, (short)2, (byte)2 ) ); assertSame(nf, wb.findFont( - Font.BOLDWEIGHT_BOLD, (short)123, (short)(22*20), + true, (short)123, (short)(22*20), "Thingy", false, true, (short)2, (byte)2 ) ); diff --git a/src/testcases/org/apache/poi/ss/usermodel/TestDataFormatter.java b/src/testcases/org/apache/poi/ss/usermodel/TestDataFormatter.java index b7990b43fd..f65bd6c5d7 100644 --- a/src/testcases/org/apache/poi/ss/usermodel/TestDataFormatter.java +++ b/src/testcases/org/apache/poi/ss/usermodel/TestDataFormatter.java @@ -28,8 +28,10 @@ import static org.junit.Assert.fail; import java.io.IOException; import java.text.DateFormat; +import java.util.Arrays; import java.util.Calendar; import java.util.Date; +import java.util.List; import java.util.Locale; import org.apache.poi.hssf.HSSFTestDataSamples; @@ -853,11 +855,34 @@ public class TestDataFormatter { } /** + * bug 60422 : simple number formats seem ok +≈ */ + @Test + public void testSimpleNumericFormatsInGermanyLocale() { + List<Locale> locales = Arrays.asList(new Locale[] {Locale.GERMANY, Locale.US, Locale.ROOT} ); + for (Locale locale : locales) { + //show that LocaleUtil has no effect on these tests + LocaleUtil.setUserLocale(locale); + try { + char euro = '\u20AC'; + DataFormatter df = new DataFormatter(Locale.GERMANY); + assertEquals("4,33", df.formatRawCellContents(4.33, -1, "#,##0.00")); + assertEquals("1.234,33", df.formatRawCellContents(1234.333, -1, "#,##0.00")); + assertEquals("-1.234,33", df.formatRawCellContents(-1234.333, -1, "#,##0.00")); + assertEquals("1.234,33 " + euro, df.formatRawCellContents(1234.33, -1, "#,##0.00 " + euro)); + assertEquals("1.234,33 " + euro, df.formatRawCellContents(1234.33, -1, "#,##0.00 \"" + euro + "\"")); + } finally { + LocaleUtil.resetUserLocale(); + } + } + } + + /** * bug 60422 : DataFormatter has issues with a specific NumberFormat in Germany default locale - * Currently, this test only passes if you set LocaleUtil.setUserLocale(Locale.ROOT) or Locale.US. - */ +≈ */ @Test public void testBug60422() { + //when this is set to Locale.Germany, the result is LocaleUtil.setUserLocale(Locale.ROOT); try { char euro = '\u20AC'; @@ -865,6 +890,7 @@ public class TestDataFormatter { String formatString = String.format(Locale.ROOT, "_-* #,##0.00\\ \"%s\"_-;\\-* #,##0.00\\ \"%s\"_-;_-* \"-\"??\\ \"%s\"_-;_-@_-", euro, euro, euro); + //this should be 4,33 assertEquals("4.33 " + euro, df.formatRawCellContents(4.33, 178, formatString)); } finally { LocaleUtil.resetUserLocale(); diff --git a/src/testcases/org/apache/poi/ss/util/NumberComparingSpreadsheetGenerator.java b/src/testcases/org/apache/poi/ss/util/NumberComparingSpreadsheetGenerator.java index 01bca57255..8069a16b43 100644 --- a/src/testcases/org/apache/poi/ss/util/NumberComparingSpreadsheetGenerator.java +++ b/src/testcases/org/apache/poi/ss/util/NumberComparingSpreadsheetGenerator.java @@ -78,7 +78,7 @@ public class NumberComparingSpreadsheetGenerator { HSSFRow row = sheet.createRow(0); HSSFCellStyle style = wb.createCellStyle(); HSSFFont font = wb.createFont(); - font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); + font.setBold(true); style.setFont(font); writeHeaderCell(row, 0, "Raw Long Bits A", style); writeHeaderCell(row, 1, "Raw Long Bits B", style); diff --git a/src/testcases/org/apache/poi/ss/util/NumberRenderingSpreadsheetGenerator.java b/src/testcases/org/apache/poi/ss/util/NumberRenderingSpreadsheetGenerator.java index 0961134e62..f810f3093e 100644 --- a/src/testcases/org/apache/poi/ss/util/NumberRenderingSpreadsheetGenerator.java +++ b/src/testcases/org/apache/poi/ss/util/NumberRenderingSpreadsheetGenerator.java @@ -97,7 +97,7 @@ public class NumberRenderingSpreadsheetGenerator { HSSFRow row = sheet.createRow(0); HSSFCellStyle style = wb.createCellStyle(); HSSFFont font = wb.createFont(); - font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); + font.setBold(true); style.setFont(font); writeHeaderCell(row, 0, "Value", style); writeHeaderCell(row, 1, "Raw Long Bits", style); |