Package limelight.ui

Source Code of limelight.ui.PenTest

//- Copyright © 2008-2011 8th Light, Inc. All Rights Reserved.
//- Limelight and all included source files are distributed under terms of the MIT License.

package limelight.ui;

import junit.framework.TestCase;
import java.awt.*;
import java.awt.geom.Line2D;

import limelight.ui.MockGraphics;
import limelight.ui.Pen;

public class PenTest extends TestCase
{
  private MockGraphics graphics;
  private Pen pen;

  public void setUp() throws Exception
  {
    graphics = new MockGraphics();
    pen = new Pen(graphics);
  }

  public void tearDown() throws Exception
  {
  }

  public void testWithColor() throws Exception
  {
    Pen result = pen.withColor(Color.red);

    assertSame(pen, result);
    assertEquals(Color.red, pen.getColor());
  }

  public void testWithStroke() throws Exception
  {
    Pen result = pen.withStroke(1);

    assertSame(pen, result);
    assertEquals(1, pen.getStroke().getLineWidth(), 0.1);
  }

  public void testWithAntialiasing() throws Exception
  {
    Pen result = pen.withAntialiasing(false);

    assertSame(pen, result);
    assertEquals(RenderingHints.VALUE_ANTIALIAS_OFF, graphics.getRenderingHint(RenderingHints.KEY_ANTIALIASING));

    result = pen.withAntialiasing(true);

    assertSame(pen, result);
    assertEquals(RenderingHints.VALUE_ANTIALIAS_ON, graphics.getRenderingHint(RenderingHints.KEY_ANTIALIASING));
  }

  public void testDrawLine() throws Exception
  {
    pen.drawLine(1, 2, 3, 4);

    assertEquals(Line2D.Double.class, graphics.drawnShape(0).shape.getClass());
    Line2D.Double line = (Line2D.Double)graphics.drawnShape(0).shape;
    assertEquals(1, line.getX1(), 0.1);
    assertEquals(2, line.getY1(), 0.1);
    assertEquals(3, line.getX2(), 0.1);
    assertEquals(4, line.getY2(), 0.1);
  }

}
TOP

Related Classes of limelight.ui.PenTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.