diff options
Diffstat (limited to 'src/testcases/org')
3 files changed, 96 insertions, 54 deletions
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestEscherGraphics.java b/src/testcases/org/apache/poi/hssf/usermodel/TestEscherGraphics.java index afeee14eda..e6d5693846 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestEscherGraphics.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestEscherGraphics.java @@ -17,11 +17,20 @@ package org.apache.poi.hssf.usermodel; -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; -import java.awt.*; +import java.awt.Color; +import java.awt.Font; +import java.awt.FontMetrics; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; +import java.io.IOException; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; /** * Tests the capabilities of the EscherGraphics class. @@ -29,55 +38,62 @@ import java.io.ByteArrayOutputStream; * All tests have two escher groups available to them, * one anchored at 0,0,1022,255 and another anchored * at 20,30,500,200 - * - * @author Glen Stampoultzis (glens at apache.org) */ -public final class TestEscherGraphics extends TestCase { +public final class TestEscherGraphics { private HSSFWorkbook workbook; private HSSFPatriarch patriarch; private HSSFShapeGroup escherGroupA; - private HSSFShapeGroup escherGroupB; private EscherGraphics graphics; - protected void setUp() throws Exception - { + @Before + public void setUp() throws IOException { workbook = new HSSFWorkbook(); HSSFSheet sheet = workbook.createSheet("test"); patriarch = sheet.createDrawingPatriarch(); escherGroupA = patriarch.createGroup(new HSSFClientAnchor(0,0,1022,255,(short)0,0,(short) 0,0)); - escherGroupB = patriarch.createGroup(new HSSFClientAnchor(20,30,500,200,(short)0,0,(short) 0,0)); -// escherGroup = new HSSFShapeGroup(null, new HSSFChildAnchor()); - graphics = new EscherGraphics(this.escherGroupA, workbook, Color.black, 1.0f); - super.setUp(); + patriarch.createGroup(new HSSFClientAnchor(20,30,500,200,(short)0,0,(short) 0,0)); + graphics = new EscherGraphics(escherGroupA, workbook, Color.black, 1.0f); + } + + @After + public void closeResources() throws IOException { + workbook.close(); } + @Test public void testGetFont() { Font f = graphics.getFont(); - if (f.toString().indexOf("dialog") == -1 && f.toString().indexOf("Dialog") == -1) + if (f.toString().indexOf("dialog") == -1 && f.toString().indexOf("Dialog") == -1) { assertEquals("java.awt.Font[family=Arial,name=Arial,style=plain,size=10]", f.toString()); + } } + @Test public void testGetFontMetrics() { Font f = graphics.getFont(); - if (f.toString().indexOf("dialog") != -1 || f.toString().indexOf("Dialog") != -1) + if (f.toString().indexOf("dialog") != -1 || f.toString().indexOf("Dialog") != -1) { return; + } FontMetrics fontMetrics = graphics.getFontMetrics(graphics.getFont()); assertEquals(7, fontMetrics.charWidth('X')); assertEquals("java.awt.Font[family=Arial,name=Arial,style=plain,size=10]", fontMetrics.getFont().toString()); } + @Test public void testSetFont() { Font f = new Font("Helvetica", 0, 12); graphics.setFont(f); assertEquals(f, graphics.getFont()); } + @Test public void testSetColor() { graphics.setColor(Color.red); assertEquals(Color.red, graphics.getColor()); } + @Test public void testFillRect() { graphics.fillRect( 10, 10, 20, 20 ); HSSFSimpleShape s = (HSSFSimpleShape) escherGroupA.getChildren().get(0); @@ -88,12 +104,14 @@ public final class TestEscherGraphics extends TestCase { assertEquals(30, s.getAnchor().getDx2()); } + @Test public void testDrawString() { graphics.drawString("This is a test", 10, 10); HSSFTextbox t = (HSSFTextbox) escherGroupA.getChildren().get(0); assertEquals("This is a test", t.getString().getString()); } + @Test public void testGetDataBackAgain() throws Exception { HSSFSheet s; HSSFShapeGroup s1; @@ -284,6 +302,6 @@ public final class TestEscherGraphics extends TestCase { assertEquals(200, s2.getAnchor().getDy2()); // Not working just yet - //assertEquals("I am text box 1", tbox1.getString().getString()); + assertEquals("I am text box 1", tbox1.getString().getString()); } } diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestEscherGraphics2d.java b/src/testcases/org/apache/poi/hssf/usermodel/TestEscherGraphics2d.java index dc3d5f42ce..b0b4293a74 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestEscherGraphics2d.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestEscherGraphics2d.java @@ -17,30 +17,44 @@ package org.apache.poi.hssf.usermodel; -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; -import java.awt.*; +import java.awt.Color; +import java.awt.Font; +import java.awt.FontMetrics; import java.awt.geom.Line2D; +import java.io.IOException; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; /** * Tests the Graphics2d drawing capability. - * - * @author Glen Stampoultzis (glens at apache.org) */ -public final class TestEscherGraphics2d extends TestCase { +public final class TestEscherGraphics2d { + private HSSFWorkbook workbook; private HSSFShapeGroup escherGroup; private EscherGraphics2d graphics; - @Override - protected void setUp() { - HSSFWorkbook workbook = new HSSFWorkbook(); + @Before + public void setUp() { + workbook = new HSSFWorkbook(); HSSFSheet sheet = workbook.createSheet("test"); escherGroup = sheet.createDrawingPatriarch().createGroup(new HSSFClientAnchor(0,0,1023,255,(short)0,0,(short) 0,0)); escherGroup = new HSSFShapeGroup(null, new HSSFChildAnchor()); - EscherGraphics g = new EscherGraphics(this.escherGroup, workbook, Color.black, 1.0f); + EscherGraphics g = new EscherGraphics(escherGroup, workbook, Color.black, 1.0f); graphics = new EscherGraphics2d(g); } + + @After + public void closeResources() throws IOException { + workbook.close(); + } + @Test public void testDrawString() { graphics.drawString("This is a test", 10, 10); HSSFTextbox t = (HSSFTextbox) escherGroup.getChildren().get(0); @@ -71,7 +85,8 @@ public final class TestEscherGraphics2d extends TestCase { } } - public void testFillRect() { + @Test + public void testFillRect() { graphics.fillRect( 10, 10, 20, 20 ); HSSFSimpleShape s = (HSSFSimpleShape) escherGroup.getChildren().get(0); assertEquals(HSSFSimpleShape.OBJECT_TYPE_RECTANGLE, s.getShapeType()); @@ -81,29 +96,37 @@ public final class TestEscherGraphics2d extends TestCase { assertEquals(30, s.getAnchor().getDx2()); } - public void testGetFontMetrics() { + @Test + public void testGetFontMetrics() { FontMetrics fontMetrics = graphics.getFontMetrics(graphics.getFont()); - if (isDialogPresent()) // if dialog is returned we can't run the test properly. + if (isDialogPresent()) { + // if dialog is returned we can't run the test properly. return; + } assertEquals(7, fontMetrics.charWidth('X')); assertEquals("java.awt.Font[family=Arial,name=Arial,style=plain,size=10]", fontMetrics.getFont().toString()); } - public void testSetFont() { + @Test + public void testSetFont() { Font f = new Font("Helvetica", 0, 12); graphics.setFont(f); assertEquals(f, graphics.getFont()); } - public void testSetColor() { + @Test + public void testSetColor() { graphics.setColor(Color.red); assertEquals(Color.red, graphics.getColor()); } - public void testGetFont() { + @Test + public void testGetFont() { Font f = graphics.getFont(); - if (isDialogPresent()) // if dialog is returned we can't run the test properly. + if (isDialogPresent()) { + // if dialog is returned we can't run the test properly. return; + } assertEquals("java.awt.Font[family=Arial,name=Arial,style=plain,size=10]", f.toString()); } @@ -113,7 +136,8 @@ public final class TestEscherGraphics2d extends TestCase { return fontDebugStr.indexOf("dialog") != -1 || fontDebugStr.indexOf("Dialog") != -1; } - public void testDraw() { + @Test + public void testDraw() { graphics.draw(new Line2D.Double(10,10,20,20)); HSSFSimpleShape s = (HSSFSimpleShape) escherGroup.getChildren().get(0); assertTrue(s.getShapeType() == HSSFSimpleShape.OBJECT_TYPE_LINE); diff --git a/src/testcases/org/apache/poi/ss/usermodel/BaseTestBugzillaIssues.java b/src/testcases/org/apache/poi/ss/usermodel/BaseTestBugzillaIssues.java index eff708ee00..945bdf86a8 100644 --- a/src/testcases/org/apache/poi/ss/usermodel/BaseTestBugzillaIssues.java +++ b/src/testcases/org/apache/poi/ss/usermodel/BaseTestBugzillaIssues.java @@ -68,7 +68,7 @@ public abstract class BaseTestBugzillaIssues { * Also tests bug 15353 (problems with hyperlinks to Google) */ @Test - public final void bug23094() throws Exception { + public final void bug23094() throws IOException { Workbook wb1 = _testDataProvider.createWorkbook(); Sheet s = wb1.createSheet(); Row r = s.createRow(0); @@ -92,7 +92,7 @@ public abstract class BaseTestBugzillaIssues { * open resulting file in Excel to check results! * @param num the number of strings to generate */ - public final void bug15375(int num) throws Exception { + public final void bug15375(int num) throws IOException { Workbook wb1 = _testDataProvider.createWorkbook(); Sheet sheet = wb1.createSheet(); CreationHelper factory = wb1.getCreationHelper(); @@ -137,7 +137,7 @@ public abstract class BaseTestBugzillaIssues { * Merged regions were being removed from the parent in cloned sheets */ @Test - public void bug22720() throws Exception { + public void bug22720() throws IOException { Workbook wb = _testDataProvider.createWorkbook(); wb.createSheet("TEST"); Sheet template = wb.getSheetAt(0); @@ -165,7 +165,7 @@ public abstract class BaseTestBugzillaIssues { } @Test - public final void bug28031() throws Exception { + public final void bug28031() throws IOException { Workbook wb1 = _testDataProvider.createWorkbook(); Sheet sheet = wb1.createSheet(); wb1.setSheetName(0, "Sheet1"); @@ -191,7 +191,7 @@ public abstract class BaseTestBugzillaIssues { * {=SUM(IF(FREQUENCY(IF(LEN(V4:V220)>0,MATCH(V4:V220,V4:V220,0),""),IF(LEN(V4:V220)>0,MATCH(V4:V220,V4:V220,0),""))>0,1))} */ @Test - public final void bug21334() throws Exception { + public final void bug21334() throws IOException { Workbook wb1 = _testDataProvider.createWorkbook(); Sheet sh = wb1.createSheet(); Cell cell = sh.createRow(0).createCell(0); @@ -208,7 +208,7 @@ public abstract class BaseTestBugzillaIssues { /** another test for the number of unique strings issue *test opening the resulting file in Excel*/ @Test - public final void bug22568() throws Exception { + public final void bug22568() throws IOException { int r=2000;int c=3; Workbook wb1 = _testDataProvider.createWorkbook(); @@ -260,7 +260,7 @@ public abstract class BaseTestBugzillaIssues { * Bug 42448: Can't parse SUMPRODUCT(A!C7:A!C67, B8:B68) / B69 */ @Test - public final void bug42448() throws Exception { + public final void bug42448() throws IOException { Workbook wb = _testDataProvider.createWorkbook(); Cell cell = wb.createSheet().createRow(0).createCell(0); cell.setCellFormula("SUMPRODUCT(A!C7:A!C67, B8:B68) / B69"); @@ -269,7 +269,7 @@ public abstract class BaseTestBugzillaIssues { } @Test - public void bug18800() throws Exception { + public void bug18800() throws IOException { Workbook wb1 = _testDataProvider.createWorkbook(); wb1.createSheet("TEST"); Sheet sheet = wb1.cloneSheet(0); @@ -300,7 +300,7 @@ public abstract class BaseTestBugzillaIssues { } @Test - public void bug43093() throws Exception { + public void bug43093() throws IOException { Workbook xlw = _testDataProvider.createWorkbook(); addNewSheetWithCellsA1toD4(xlw, 1); @@ -322,7 +322,7 @@ public abstract class BaseTestBugzillaIssues { } @Test - public void bug46729_testMaxFunctionArguments() throws Exception { + public void bug46729_testMaxFunctionArguments() throws IOException { String[] func = {"COUNT", "AVERAGE", "MAX", "MIN", "OR", "SUBTOTAL", "SKEW"}; SpreadsheetVersion ssVersion = _testDataProvider.getSpreadsheetVersion(); @@ -362,7 +362,7 @@ public abstract class BaseTestBugzillaIssues { } @Test - public final void bug50681_testAutoSize() throws Exception { + public final void bug50681_testAutoSize() throws IOException { Workbook wb = _testDataProvider.createWorkbook(); BaseTestSheetAutosizeColumn.fixFonts(wb); Sheet sheet = wb.createSheet("Sheet1"); @@ -456,7 +456,7 @@ public abstract class BaseTestBugzillaIssues { * CreateFreezePane column/row order check */ @Test - public void bug49381() throws Exception { + public void bug49381() throws IOException { Workbook wb = _testDataProvider.createWorkbook(); int colSplit = 1; int rowSplit = 2; @@ -510,7 +510,7 @@ public abstract class BaseTestBugzillaIssues { * open resulting file in excel, and check that there is a link to Google */ @Test - public void bug15353() throws Exception { + public void bug15353() throws IOException { String hyperlinkF = "HYPERLINK(\"http://google.com\",\"Google\")"; Workbook wb1 = _testDataProvider.createWorkbook(); @@ -536,7 +536,7 @@ public abstract class BaseTestBugzillaIssues { * HLookup and VLookup with optional arguments */ @Test - public void bug51024() throws Exception { + public void bug51024() throws IOException { Workbook wb = _testDataProvider.createWorkbook(); Sheet s = wb.createSheet(); Row r1 = s.createRow(0); @@ -573,7 +573,7 @@ public abstract class BaseTestBugzillaIssues { } @Test - public void stackoverflow23114397() throws Exception { + public void stackoverflow23114397() throws IOException { Workbook wb = _testDataProvider.createWorkbook(); DataFormat format = wb.getCreationHelper().createDataFormat(); @@ -642,7 +642,7 @@ public abstract class BaseTestBugzillaIssues { * =ISNUMBER(SEARCH("AM",A1)) evaluation */ @Test - public void stackoverflow26437323() throws Exception { + public void stackoverflow26437323() throws IOException { Workbook wb = _testDataProvider.createWorkbook(); Sheet s = wb.createSheet(); Row r1 = s.createRow(0); @@ -799,7 +799,7 @@ public abstract class BaseTestBugzillaIssues { */ @Ignore("Fix this to evaluate for XSSF, Fix this to work at all for HSSF") @Test - public void bug46670() throws Exception { + public void bug46670() throws IOException { Workbook wb1 = _testDataProvider.createWorkbook(); Sheet s = wb1.createSheet(); Row r1 = s.createRow(0); @@ -925,7 +925,7 @@ public abstract class BaseTestBugzillaIssues { * that it now is again */ @Test - public void bug48718() throws Exception { + public void bug48718() throws IOException { Workbook wb = _testDataProvider.createWorkbook(); int startingFonts = wb instanceof HSSFWorkbook ? 4 : 1; @@ -947,7 +947,7 @@ public abstract class BaseTestBugzillaIssues { } @Test - public void bug57430() throws Exception { + public void bug57430() throws IOException { Workbook wb = _testDataProvider.createWorkbook(); wb.createSheet("Sheet1"); @@ -1050,7 +1050,7 @@ public abstract class BaseTestBugzillaIssues { * kind of value from a Formula cell */ @Test - public void bug47815() throws Exception { + public void bug47815() throws IOException { Workbook wb = _testDataProvider.createWorkbook(); Sheet s = wb.createSheet(); Row r = s.createRow(0); @@ -1109,7 +1109,7 @@ public abstract class BaseTestBugzillaIssues { } @Test - public void test58113() throws Exception { + public void test58113() throws IOException { Workbook wb = _testDataProvider.createWorkbook(); Sheet sheet = wb.createSheet( "Test" ); @@ -1155,7 +1155,7 @@ public abstract class BaseTestBugzillaIssues { * Mid in it, can give #VALUE in Excel */ @Test - public void bug55747() throws Exception { + public void bug55747() throws IOException { Workbook wb1 = _testDataProvider.createWorkbook(); FormulaEvaluator ev = wb1.getCreationHelper().createFormulaEvaluator(); Sheet s = wb1.createSheet(); |