diff options
author | Josh Micich <josh@apache.org> | 2009-02-03 01:19:13 +0000 |
---|---|---|
committer | Josh Micich <josh@apache.org> | 2009-02-03 01:19:13 +0000 |
commit | 6fd3790d79f1e72875a7d9d9169d6dba05b0d528 (patch) | |
tree | d1e3a87fec659afd35e0c2354c3ae5e638656cb2 /src/testcases/org/apache | |
parent | 2b78c4ccd54113b60e5fa3f15c1889e80bdf2f21 (diff) | |
download | poi-6fd3790d79f1e72875a7d9d9169d6dba05b0d528.tar.gz poi-6fd3790d79f1e72875a7d9d9169d6dba05b0d528.zip |
Fixed deprecated references to HSSFSheet.getRow(short) etc. Removed all deprecated warnings from hssf.usermodel.examples.*
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@740179 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/testcases/org/apache')
-rw-r--r-- | src/testcases/org/apache/poi/hssf/usermodel/TestCellStyle.java | 279 | ||||
-rw-r--r-- | src/testcases/org/apache/poi/hssf/usermodel/TestRowStyle.java | 53 |
2 files changed, 130 insertions, 202 deletions
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestCellStyle.java b/src/testcases/org/apache/poi/hssf/usermodel/TestCellStyle.java index a4cf005a0c..17ad850d7f 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestCellStyle.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestCellStyle.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,20 +14,16 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - -/* - * TestCellStyle.java - * - * Created on December 11, 2001, 5:51 PM - */ package org.apache.poi.hssf.usermodel; -import java.io.*; - -import java.util.*; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.util.Calendar; +import java.util.Date; -import junit.framework.*; +import junit.framework.TestCase; import org.apache.poi.hssf.HSSFTestDataSamples; import org.apache.poi.util.TempFile; @@ -39,20 +34,12 @@ import org.apache.poi.util.TempFile; * @author Andrew C. Oliver */ -public class TestCellStyle - extends TestCase -{ +public final class TestCellStyle extends TestCase { private static HSSFWorkbook openSample(String sampleFileName) { return HSSFTestDataSamples.openSampleWorkbook(sampleFileName); } - /** Creates a new instance of TestCellStyle */ - - public TestCellStyle(String name) - { - super(name); - } /** * TEST NAME: Test Write Sheet Font <P> @@ -63,10 +50,7 @@ public class TestCellStyle * HSSFSheet last row or first row is incorrect. <P> * */ - - public void testWriteSheetFont() - throws IOException - { + public void testWriteSheetFont() throws IOException{ File file = TempFile.createTempFile("testWriteSheetFont", ".xls"); FileOutputStream out = new FileOutputStream(file); @@ -80,13 +64,10 @@ public class TestCellStyle fnt.setColor(HSSFFont.COLOR_RED); fnt.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); cs.setFont(fnt); - for (short rownum = ( short ) 0; rownum < 100; rownum++) - { + for (int rownum = 0; rownum < 100; rownum++) { r = s.createRow(rownum); - // r.setRowNum(( short ) rownum); - for (short cellnum = ( short ) 0; cellnum < 50; cellnum += 2) - { + for (int cellnum = 0; cellnum < 50; cellnum += 2) { c = r.createCell(cellnum); c.setCellValue(rownum * 10000 + cellnum + ((( double ) rownum / 1000) @@ -109,9 +90,7 @@ public class TestCellStyle /** * Tests that is creating a file with a date or an calendar works correctly. */ - public void testDataStyle() - throws Exception - { + public void testDataStyle() throws IOException { File file = TempFile.createTempFile("testWriteSheetStyleDate", ".xls"); FileOutputStream out = new FileOutputStream(file); @@ -141,7 +120,6 @@ public class TestCellStyle assertEquals("LAST ROW ", 0, s.getLastRowNum()); assertEquals("FIRST ROW ", 0, s.getFirstRowNum()); - } public void testHashEquals() { @@ -183,10 +161,7 @@ public class TestCellStyle * HSSFSheet last row or first row is incorrect. <P> * */ - - public void testWriteSheetStyle() - throws IOException - { + public void testWriteSheetStyle() throws IOException { File file = TempFile.createTempFile("testWriteSheetStyle", ".xls"); FileOutputStream out = new FileOutputStream(file); @@ -209,13 +184,10 @@ public class TestCellStyle cs2.setFillForegroundColor(( short ) 0x0); cs2.setFillPattern(( short ) 1); cs2.setFont(fnt); - for (short rownum = ( short ) 0; rownum < 100; rownum++) - { + for (int rownum = 0; rownum < 100; rownum++) { r = s.createRow(rownum); - // r.setRowNum(( short ) rownum); - for (short cellnum = ( short ) 0; cellnum < 50; cellnum += 2) - { + for (int cellnum = 0; cellnum < 50; cellnum += 2) { c = r.createCell(cellnum); c.setCellValue(rownum * 10000 + cellnum + ((( double ) rownum / 1000) @@ -232,136 +204,127 @@ public class TestCellStyle sanityChecker.checkHSSFWorkbook(wb); assertEquals("LAST ROW == 99", 99, s.getLastRowNum()); assertEquals("FIRST ROW == 0", 0, s.getFirstRowNum()); - - // assert((s.getLastRowNum() == 99)); } /** * Cloning one HSSFCellStyle onto Another, same * HSSFWorkbook */ - public void testCloneStyleSameWB() throws Exception { - HSSFWorkbook wb = new HSSFWorkbook(); - HSSFFont fnt = wb.createFont(); - fnt.setFontName("TestingFont"); - assertEquals(5, wb.getNumberOfFonts()); - - HSSFCellStyle orig = wb.createCellStyle(); - orig.setAlignment(HSSFCellStyle.ALIGN_RIGHT); - orig.setFont(fnt); - orig.setDataFormat((short)18); - - assertTrue(HSSFCellStyle.ALIGN_RIGHT == orig.getAlignment()); - assertTrue(fnt == orig.getFont(wb)); - assertTrue(18 == orig.getDataFormat()); - - HSSFCellStyle clone = wb.createCellStyle(); - assertFalse(HSSFCellStyle.ALIGN_RIGHT == clone.getAlignment()); - 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(5, wb.getNumberOfFonts()); + public void testCloneStyleSameWB() { + HSSFWorkbook wb = new HSSFWorkbook(); + HSSFFont fnt = wb.createFont(); + fnt.setFontName("TestingFont"); + assertEquals(5, wb.getNumberOfFonts()); + + HSSFCellStyle orig = wb.createCellStyle(); + orig.setAlignment(HSSFCellStyle.ALIGN_RIGHT); + orig.setFont(fnt); + orig.setDataFormat((short)18); + + assertTrue(HSSFCellStyle.ALIGN_RIGHT == orig.getAlignment()); + assertTrue(fnt == orig.getFont(wb)); + assertTrue(18 == orig.getDataFormat()); + + HSSFCellStyle clone = wb.createCellStyle(); + assertFalse(HSSFCellStyle.ALIGN_RIGHT == clone.getAlignment()); + 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(5, wb.getNumberOfFonts()); } /** * Cloning one HSSFCellStyle onto Another, across * two different HSSFWorkbooks */ - public void testCloneStyleDiffWB() throws Exception { - HSSFWorkbook wbOrig = new HSSFWorkbook(); - - HSSFFont fnt = wbOrig.createFont(); - fnt.setFontName("TestingFont"); - assertEquals(5, wbOrig.getNumberOfFonts()); - - HSSFDataFormat fmt = wbOrig.createDataFormat(); - fmt.getFormat("MadeUpOne"); - fmt.getFormat("MadeUpTwo"); - - HSSFCellStyle orig = wbOrig.createCellStyle(); - orig.setAlignment(HSSFCellStyle.ALIGN_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()); - - // Now a style on another workbook - HSSFWorkbook wbClone = new HSSFWorkbook(); - assertEquals(4, wbClone.getNumberOfFonts()); - HSSFDataFormat fmtClone = wbClone.createDataFormat(); - - HSSFCellStyle clone = wbClone.createCellStyle(); - assertEquals(4, wbClone.getNumberOfFonts()); - - assertFalse(HSSFCellStyle.ALIGN_RIGHT == clone.getAlignment()); - 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()); - assertFalse(fmtClone.getFormat("Test##") == fmt.getFormat("Test##")); - assertEquals(5, wbClone.getNumberOfFonts()); + public void testCloneStyleDiffWB() { + HSSFWorkbook wbOrig = new HSSFWorkbook(); + + HSSFFont fnt = wbOrig.createFont(); + fnt.setFontName("TestingFont"); + assertEquals(5, wbOrig.getNumberOfFonts()); + + HSSFDataFormat fmt = wbOrig.createDataFormat(); + fmt.getFormat("MadeUpOne"); + fmt.getFormat("MadeUpTwo"); + + HSSFCellStyle orig = wbOrig.createCellStyle(); + orig.setAlignment(HSSFCellStyle.ALIGN_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()); + + // Now a style on another workbook + HSSFWorkbook wbClone = new HSSFWorkbook(); + assertEquals(4, wbClone.getNumberOfFonts()); + HSSFDataFormat fmtClone = wbClone.createDataFormat(); + + HSSFCellStyle clone = wbClone.createCellStyle(); + assertEquals(4, wbClone.getNumberOfFonts()); + + assertFalse(HSSFCellStyle.ALIGN_RIGHT == clone.getAlignment()); + 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()); + assertFalse(fmtClone.getFormat("Test##") == fmt.getFormat("Test##")); + assertEquals(5, wbClone.getNumberOfFonts()); } - public void testStyleNames() throws Exception { + public void testStyleNames() { HSSFWorkbook wb = openSample("WithExtendedStyles.xls"); - HSSFSheet s = wb.getSheetAt(0); - HSSFCell c1 = s.getRow(0).getCell(0); - HSSFCell c2 = s.getRow(1).getCell(0); - HSSFCell c3 = s.getRow(2).getCell(0); - - HSSFCellStyle cs1 = c1.getCellStyle(); - HSSFCellStyle cs2 = c2.getCellStyle(); - HSSFCellStyle cs3 = c3.getCellStyle(); - - assertNotNull(cs1); - assertNotNull(cs2); - assertNotNull(cs3); - - // Check we got the styles we'd expect - assertEquals(10, cs1.getFont(wb).getFontHeightInPoints()); - assertEquals(9, cs2.getFont(wb).getFontHeightInPoints()); - assertEquals(12, cs3.getFont(wb).getFontHeightInPoints()); - - assertEquals(15, cs1.getIndex()); - assertEquals(23, cs2.getIndex()); - assertEquals(24, cs3.getIndex()); - - assertNull(cs1.getParentStyle()); - assertNotNull(cs2.getParentStyle()); - assertNotNull(cs3.getParentStyle()); - - assertEquals(21, cs2.getParentStyle().getIndex()); - assertEquals(22, cs3.getParentStyle().getIndex()); - - // Now check we can get style records for - // the parent ones - assertNull(wb.getWorkbook().getStyleRecord(15)); - assertNull(wb.getWorkbook().getStyleRecord(23)); - assertNull(wb.getWorkbook().getStyleRecord(24)); - - assertNotNull(wb.getWorkbook().getStyleRecord(21)); - assertNotNull(wb.getWorkbook().getStyleRecord(22)); - - // Now check the style names - assertEquals(null, cs1.getUserStyleName()); - assertEquals(null, cs2.getUserStyleName()); - assertEquals(null, cs3.getUserStyleName()); - assertEquals("style1", cs2.getParentStyle().getUserStyleName()); - assertEquals("style2", cs3.getParentStyle().getUserStyleName()); - } - - public static void main(String [] ignored_args) - { - System.out - .println("Testing org.apache.poi.hssf.usermodel.HSSFCellStyle"); - junit.textui.TestRunner.run(TestCellStyle.class); + HSSFSheet s = wb.getSheetAt(0); + HSSFCell c1 = s.getRow(0).getCell(0); + HSSFCell c2 = s.getRow(1).getCell(0); + HSSFCell c3 = s.getRow(2).getCell(0); + + HSSFCellStyle cs1 = c1.getCellStyle(); + HSSFCellStyle cs2 = c2.getCellStyle(); + HSSFCellStyle cs3 = c3.getCellStyle(); + + assertNotNull(cs1); + assertNotNull(cs2); + assertNotNull(cs3); + + // Check we got the styles we'd expect + assertEquals(10, cs1.getFont(wb).getFontHeightInPoints()); + assertEquals(9, cs2.getFont(wb).getFontHeightInPoints()); + assertEquals(12, cs3.getFont(wb).getFontHeightInPoints()); + + assertEquals(15, cs1.getIndex()); + assertEquals(23, cs2.getIndex()); + assertEquals(24, cs3.getIndex()); + + assertNull(cs1.getParentStyle()); + assertNotNull(cs2.getParentStyle()); + assertNotNull(cs3.getParentStyle()); + + assertEquals(21, cs2.getParentStyle().getIndex()); + assertEquals(22, cs3.getParentStyle().getIndex()); + + // Now check we can get style records for + // the parent ones + assertNull(wb.getWorkbook().getStyleRecord(15)); + assertNull(wb.getWorkbook().getStyleRecord(23)); + assertNull(wb.getWorkbook().getStyleRecord(24)); + + assertNotNull(wb.getWorkbook().getStyleRecord(21)); + assertNotNull(wb.getWorkbook().getStyleRecord(22)); + + // Now check the style names + assertEquals(null, cs1.getUserStyleName()); + assertEquals(null, cs2.getUserStyleName()); + assertEquals(null, cs3.getUserStyleName()); + assertEquals("style1", cs2.getParentStyle().getUserStyleName()); + assertEquals("style2", cs3.getParentStyle().getUserStyleName()); } } diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestRowStyle.java b/src/testcases/org/apache/poi/hssf/usermodel/TestRowStyle.java index 8cca078496..36821e6a24 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestRowStyle.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestRowStyle.java @@ -14,37 +14,18 @@ limitations under the License. ==================================================================== */ - -/* - * TestRowStyle.java - * - * Created on May 20, 2005 - */ package org.apache.poi.hssf.usermodel; -import java.io.IOException; - import junit.framework.TestCase; import org.apache.poi.hssf.HSSFTestDataSamples; -import org.apache.poi.util.TempFile; /** * Class to test row styling functionality * * @author Amol S. Deshmukh < amolweb at ya hoo dot com > */ - -public class TestRowStyle - extends TestCase -{ - - /** Creates a new instance of TestCellStyle */ - - public TestRowStyle(String name) - { - super(name); - } +public final class TestRowStyle extends TestCase { /** * TEST NAME: Test Write Sheet Font <P> @@ -55,21 +36,17 @@ public class TestRowStyle * HSSFSheet last row or first row is incorrect. <P> * */ - - public void testWriteSheetFont() - throws IOException - { + public void testWriteSheetFont() { HSSFWorkbook wb = new HSSFWorkbook(); HSSFSheet s = wb.createSheet(); HSSFRow r = null; - HSSFCell c = null; HSSFFont fnt = wb.createFont(); HSSFCellStyle cs = wb.createCellStyle(); fnt.setColor(HSSFFont.COLOR_RED); fnt.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); cs.setFont(fnt); - for (short rownum = ( short ) 0; rownum < 100; rownum++) + for (int rownum = 0; rownum < 100; rownum++) { r = s.createRow(rownum); r.setRowStyle(cs); @@ -86,13 +63,11 @@ public class TestRowStyle /** * Tests that is creating a file with a date or an calendar works correctly. */ - public void testDataStyle() - throws Exception - { + public void testDataStyle() { HSSFWorkbook wb = new HSSFWorkbook(); HSSFSheet s = wb.createSheet(); HSSFCellStyle cs = wb.createCellStyle(); - HSSFRow row = s.createRow((short)0); + HSSFRow row = s.createRow(0); // with Date: cs.setDataFormat(HSSFDataFormat.getBuiltinFormat("m/d/yy")); @@ -101,7 +76,7 @@ public class TestRowStyle // with Calendar: - row = s.createRow((short)1); + row = s.createRow(1); cs.setDataFormat(HSSFDataFormat.getBuiltinFormat("m/d/yy")); row.setRowStyle(cs); row.createCell(0); @@ -126,10 +101,7 @@ public class TestRowStyle * HSSFSheet last row or first row is incorrect. <P> * */ - - public void testWriteSheetStyle() - throws IOException - { + public void testWriteSheetStyle() { HSSFWorkbook wb = new HSSFWorkbook(); HSSFSheet s = wb.createSheet(); HSSFRow r = null; @@ -148,7 +120,7 @@ public class TestRowStyle cs2.setFillForegroundColor(( short ) 0x0); cs2.setFillPattern(( short ) 1); cs2.setFont(fnt); - for (short rownum = ( short ) 0; rownum < 100; rownum++) + for (int rownum = 0; rownum < 100; rownum++) { r = s.createRow(rownum); r.setRowStyle(cs); @@ -171,7 +143,7 @@ public class TestRowStyle s = wb.getSheetAt(0); assertNotNull("Sheet is not null", s); - for (short rownum = ( short ) 0; rownum < 100; rownum++) + for (int rownum = 0; rownum < 100; rownum++) { r = s.getRow(rownum); assertNotNull("Row is not null", r); @@ -194,11 +166,4 @@ public class TestRowStyle assertEquals("FillPattern for row: ", cs2.getFillPattern(), (short) 0x1); } } - - public static void main(String [] ignored_args) - { - System.out - .println("Testing org.apache.poi.hssf.usermodel.HSSFCellStyle"); - junit.textui.TestRunner.run(TestCellStyle.class); - } } |