Removed System.out.println and compiler warnings from test code

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@736193 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Josh Micich 2009-01-21 02:16:01 +00:00
parent 07fd83a278
commit 3463da015d

View File

@ -27,43 +27,38 @@ import java.awt.geom.Line2D;
* *
* @author Glen Stampoultzis (glens at apache.org) * @author Glen Stampoultzis (glens at apache.org)
*/ */
public class TestEscherGraphics2d extends TestCase public final class TestEscherGraphics2d extends TestCase {
{ private HSSFShapeGroup escherGroup;
private HSSFShapeGroup escherGroup; private EscherGraphics2d graphics;
private EscherGraphics2d graphics;
protected void setUp() throws Exception protected void setUp() {
{
super.setUp();
HSSFWorkbook workbook = new HSSFWorkbook(); HSSFWorkbook workbook = new HSSFWorkbook();
HSSFSheet sheet = workbook.createSheet("test"); HSSFSheet sheet = workbook.createSheet("test");
escherGroup = sheet.createDrawingPatriarch().createGroup(new HSSFClientAnchor(0,0,1023,255,(short)0,0,(short) 0,0)); escherGroup = sheet.createDrawingPatriarch().createGroup(new HSSFClientAnchor(0,0,1023,255,(short)0,0,(short) 0,0));
escherGroup = new HSSFShapeGroup(null, new HSSFChildAnchor()); escherGroup = new HSSFShapeGroup(null, new HSSFChildAnchor());
EscherGraphics g = new EscherGraphics(this.escherGroup, workbook, Color.black, 1.0f); EscherGraphics g = new EscherGraphics(this.escherGroup, workbook, Color.black, 1.0f);
graphics = new EscherGraphics2d(g); graphics = new EscherGraphics2d(g);
}
} public void testDrawString() {
graphics.drawString("This is a test", 10, 10);
public void testDrawString() throws Exception HSSFTextbox t = (HSSFTextbox) escherGroup.getChildren().get(0);
{ assertEquals("This is a test", t.getString().getString().toString());
graphics.drawString("This is a test", 10, 10);
HSSFTextbox t = (HSSFTextbox) escherGroup.getChildren().get(0);
assertEquals("This is a test", t.getString().getString().toString());
// Check that with a valid font, it's still ok // Check that with a valid font, it's still ok
Font font = new Font("Forte", Font.PLAIN, 12); Font font = new Font("Forte", Font.PLAIN, 12);
graphics.setFont(font); graphics.setFont(font);
graphics.drawString("This is another test", 10, 10); graphics.drawString("This is another test", 10, 10);
// And test with ones that need the style appending // And test with ones that need the style appending
font = new Font("dialog", Font.PLAIN, 12); font = new Font("dialog", Font.PLAIN, 12);
graphics.setFont(font); graphics.setFont(font);
graphics.drawString("This is another test", 10, 10); graphics.drawString("This is another test", 10, 10);
font = new Font("dialog", Font.BOLD, 12); font = new Font("dialog", Font.BOLD, 12);
graphics.setFont(font); graphics.setFont(font);
graphics.drawString("This is another test", 10, 10); graphics.drawString("This is another test", 10, 10);
// But with an invalid font, we get an exception // But with an invalid font, we get an exception
font = new Font("IamAmadeUPfont", Font.PLAIN, 22); font = new Font("IamAmadeUPfont", Font.PLAIN, 22);
@ -72,60 +67,59 @@ public class TestEscherGraphics2d extends TestCase
graphics.drawString("This is another test", 10, 10); graphics.drawString("This is another test", 10, 10);
fail(); fail();
} catch(IllegalArgumentException e) { } catch(IllegalArgumentException e) {
// expected
} }
} }
public void testFillRect() throws Exception public void testFillRect() {
{ graphics.fillRect( 10, 10, 20, 20 );
graphics.fillRect( 10, 10, 20, 20 ); HSSFSimpleShape s = (HSSFSimpleShape) escherGroup.getChildren().get(0);
HSSFSimpleShape s = (HSSFSimpleShape) escherGroup.getChildren().get(0); assertEquals(HSSFSimpleShape.OBJECT_TYPE_RECTANGLE, s.getShapeType());
assertEquals(HSSFSimpleShape.OBJECT_TYPE_RECTANGLE, s.getShapeType()); assertEquals(10, s.getAnchor().getDx1());
assertEquals(10, s.getAnchor().getDx1()); assertEquals(10, s.getAnchor().getDy1());
assertEquals(10, s.getAnchor().getDy1()); assertEquals(30, s.getAnchor().getDy2());
assertEquals(30, s.getAnchor().getDy2()); assertEquals(30, s.getAnchor().getDx2());
assertEquals(30, s.getAnchor().getDx2()); }
}
public void testGetFontMetrics() throws Exception public void testGetFontMetrics() {
{ FontMetrics fontMetrics = graphics.getFontMetrics(graphics.getFont());
FontMetrics fontMetrics = graphics.getFontMetrics(graphics.getFont()); if (isDialogPresent()) // if dialog is returned we can't run the test properly.
if (graphics.getFont().toString().indexOf("dialog") != -1 || graphics.getFont().toString().indexOf("Dialog") != -1) // if dialog is returned we can't run the test properly. return;
return; assertEquals(7, fontMetrics.charWidth('X'));
assertEquals(7, fontMetrics.charWidth('X')); assertEquals("java.awt.Font[family=Arial,name=Arial,style=plain,size=10]", fontMetrics.getFont().toString());
assertEquals("java.awt.Font[family=Arial,name=Arial,style=plain,size=10]", fontMetrics.getFont().toString()); }
}
public void testSetFont() throws Exception public void testSetFont() {
{ Font f = new Font("Helvetica", 0, 12);
Font f = new Font("Helvetica", 0, 12); graphics.setFont(f);
graphics.setFont(f); assertEquals(f, graphics.getFont());
assertEquals(f, graphics.getFont()); }
}
public void testSetColor() throws Exception public void testSetColor() {
{ graphics.setColor(Color.red);
graphics.setColor(Color.red); assertEquals(Color.red, graphics.getColor());
assertEquals(Color.red, graphics.getColor()); }
}
public void testGetFont() throws Exception public void testGetFont() {
{ Font f = graphics.getFont();
Font f = graphics.getFont(); if (isDialogPresent()) // if dialog is returned we can't run the test properly.
if (graphics.getFont().toString().indexOf("dialog") != -1 || graphics.getFont().toString().indexOf("Dialog") != -1) // if dialog is returned we can't run the test properly. return;
return;
assertEquals("java.awt.Font[family=Arial,name=Arial,style=plain,size=10]", f.toString()); assertEquals("java.awt.Font[family=Arial,name=Arial,style=plain,size=10]", f.toString());
} }
public void testDraw() throws Exception private boolean isDialogPresent() {
{ String fontDebugStr = graphics.getFont().toString();
graphics.draw(new Line2D.Double(10,10,20,20)); return fontDebugStr.indexOf("dialog") != -1 || fontDebugStr.indexOf("Dialog") != -1;
HSSFSimpleShape s = (HSSFSimpleShape) escherGroup.getChildren().get(0); }
assertTrue(s.getShapeType() == HSSFSimpleShape.OBJECT_TYPE_LINE);
assertEquals(10, s.getAnchor().getDx1()); public void testDraw() {
assertEquals(10, s.getAnchor().getDy1()); graphics.draw(new Line2D.Double(10,10,20,20));
assertEquals(20, s.getAnchor().getDx2()); HSSFSimpleShape s = (HSSFSimpleShape) escherGroup.getChildren().get(0);
assertEquals(20, s.getAnchor().getDy2()); assertTrue(s.getShapeType() == HSSFSimpleShape.OBJECT_TYPE_LINE);
System.out.println("s = " + s); assertEquals(10, s.getAnchor().getDx1());
} assertEquals(10, s.getAnchor().getDy1());
assertEquals(20, s.getAnchor().getDx2());
assertEquals(20, s.getAnchor().getDy2());
}
} }