public void testCircle() {
Long waitingTime = 1000L;
MapBean battle = CampaignClient.getInstance().getBean(battleId,
waitingTime);
MapElementSize circleRadius = new MapElementSizePixel(20.0);
Point position = new Point(5, 5);
CircleElement circleClient = new CircleElement(position, Color.RED,
circleRadius);
MapElementFactory.buildMapElement(circleClient, battle);
circleClient = CampaignClient.getInstance().getBean(
circleClient.getId(), 300L);
assertEquals("The position should be equals", position,
circleClient.getPosition());
assertEquals("The color should be equals", Color.RED,
circleClient.getColor());
assertEquals("The angle should be equals", Double.valueOf(0),
circleClient.getAngle());
assertEquals("The radius should be equals",
circleRadius.getPixels(battle.getScale()), circleClient
.getRadius().getPixels(battle.getScale()));
assertEquals("The width and the height should be equals",
circleClient.getWidthPixels(), circleClient.getHeightPixels());
BufferedImage imgGenerated = new BufferedImage(1000, 1000,
BufferedImage.TYPE_INT_ARGB);
Graphics2D g2 = (Graphics2D) imgGenerated.getGraphics();
circleClient.draw(g2, 1.0, true);
g2.dispose();
BufferedImage imgExpected = new BufferedImage(1000, 1000,
BufferedImage.TYPE_INT_ARGB);
g2 = (Graphics2D) imgExpected.getGraphics();
circleClient.draw(g2, 1.0, true);
g2.dispose();
try {
assertTrue("images should be same",
compareImage(imgExpected, imgGenerated));
} catch (IOException e) {
fail("fail to compare images");
}
Double angle = 25.0;
Boolean isHidden = !circleClient.isHiddenForPlayer();
Point newPosition = new Point(12, 12);
circleClient.setHiddenForPlayer(isHidden);
circleClient.setPosition(newPosition);
circleClient.setAngle(angle);
waitForChange(circleClient, "getPosition", newPosition);
waitForChange(circleClient, "getAngle", angle);
waitForChange(circleClient, "isHiddenForPlayer", isHidden);
waitForChange(circleClient, "getPosition", newPosition);
waitForChange(circleClient, "getPosition", newPosition);
assertEquals("The position should be equals", newPosition,
circleClient.getPosition());
assertEquals("The color should be equals", angle,
circleClient.getAngle());
assertEquals("The angle should be equals", isHidden,
circleClient.isHiddenForPlayer());
assertTrue("the circle not contain point (5,5)",
!circleClient.contain(new Point(5, 5)));
assertTrue("the circle contain point (32,32)",
circleClient.contain(new Point(32, 32)));
MapElementSize newCircleRadius = new MapElementSizeMeter(1.5);
circleClient.setRadius(newCircleRadius);
sleep();
assertEquals("radius should be equals",
newCircleRadius.getPixels(battle.getScale()), circleClient
.getRadius().getPixels(battle.getScale()));
Color color = Color.BLUE;
circleClient.setColor(color);
sleep();