MapElementSize width = new MapElementSizePixel(20.0);
MapElementSize height = new MapElementSizePixel(20.0);
Point position = new Point(5, 5);
RectangleElement targetRectangle = new RectangleElement(position,
Color.RED, width, height);
MapElementFactory.buildMapElement(targetRectangle, battle);
RectangleElement rectangle = CampaignClient.getInstance().getBean(
targetRectangle.getId(), 300L);
assertEquals("The position should be equals", position,
rectangle.getPosition());
assertEquals("The color should be equals", Color.RED,
rectangle.getColor());
assertEquals("The angle should be equals", Double.valueOf(0),
rectangle.getAngle());
assertEquals("The width should be equals", width.getPixels(battle
.getScale()), rectangle.getWidth().getPixels(battle.getScale()));
assertEquals("The height should be equals", height.getPixels(battle
.getScale()), rectangle.getHeight()
.getPixels(battle.getScale()));
MapElementSize newWidth = new MapElementSizeSquare(2.0);
MapElementSize newHeight = new MapElementSizeSquare(3.0);
rectangle.setWidth(newWidth);
rectangle.setHeight(newHeight);
sleep();
assertEquals("The width should be equals", newWidth.getPixels(battle
.getScale()), rectangle.getWidth().getPixels(battle.getScale()));
assertEquals("The height should be equals", newHeight.getPixels(battle
.getScale()), rectangle.getHeight()
.getPixels(battle.getScale()));
BufferedImage realImg = new BufferedImage(200, 200,
BufferedImage.TYPE_INT_ARGB);
Graphics2D g2 = realImg.createGraphics();
rectangle.draw(g2, 1.0, true);
g2.dispose();
targetRectangle.setWidth(newWidth);
targetRectangle.setHeight(newHeight);
BufferedImage targetImg = new BufferedImage(200, 200,
BufferedImage.TYPE_INT_ARGB);
g2 = targetImg.createGraphics();
rectangle.draw(g2, 1.0, true);
g2.dispose();
try {
assertTrue("images should be same",
compareImage(targetImg, realImg));