aboutsummaryrefslogtreecommitdiffstats
path: root/src/testcases/org/apache/poi/hssf/usermodel
diff options
context:
space:
mode:
authorAndreas Beeker <kiwiwings@apache.org>2015-10-12 20:43:42 +0000
committerAndreas Beeker <kiwiwings@apache.org>2015-10-12 20:43:42 +0000
commit86c72f59dabff2653a5d5ef2caf441e899665eb4 (patch)
tree8806fc40a457c810df0a3046de7f7a147c1ab8bc /src/testcases/org/apache/poi/hssf/usermodel
parent5735e23853c6e79529f96771ee20c97b2341a9e2 (diff)
downloadpoi-86c72f59dabff2653a5d5ef2caf441e899665eb4.tar.gz
poi-86c72f59dabff2653a5d5ef2caf441e899665eb4.zip
- removed deprecated and confusing methods in XSSFColor
- sonar fixes git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1708236 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/testcases/org/apache/poi/hssf/usermodel')
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/TestEscherGraphics.java48
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/TestEscherGraphics2d.java58
2 files changed, 74 insertions, 32 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);