public void testBattleWithMapElement() {
Long waitingTime = 1000L;
MapBean emptyBattle = new MapBean("");
assertEquals("verify emptyBattle", emptyBattle, emptyBattle);
UniqueID battleId = null;
try {
battleId = createBattle("test battle 10", getDefaultImage());
} catch (IOException e) {
fail("fail to create battle");
}
assertNotNull("the battle id must'nt be null", battleId);
MapBean battle = CampaignClient.getInstance().getBean(battleId,
waitingTime);
assertNotNull("the battle should not be null", battle);
PropertyChangeListener listener = new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent evt) {
innerClassCall();
}
};
battle.addPropertyChangeListener(listener);
Point position = new Point(5, 5);
Color color = Color.GREEN;
MapElementSize width = new MapElementSizeMeter(6.0);
MapElementSize height = new MapElementSizePixel(42.0);
RectangleElement rectangle = new RectangleElement(position, color,
width, height);
Collection<UniqueID> elementsOnMap = battle.getElements();
assertTrue("The map shouldn't have any element",
elementsOnMap.isEmpty());
MapElementFactory.buildMapElement(rectangle, battle);
// wait for the element to be in the element list
while (elementsOnMap.isEmpty()) {
sleep(10);
elementsOnMap = battle.getElements();
}
assertEquals("The map should have 1 element", 1, elementsOnMap.size());
assertEquals("The rectangle id should be the same", rectangle.getId(),
elementsOnMap.iterator().next());
assertEquals(
"The map should have at least 1 element at the position (6,6)",
1, battle.getElementsAt(new Point(6, 6)).size());
assertEquals(
"The map should'nt have any element at the position (4,4)", 0,
battle.getElementsAt(new Point(4, 4)).size());
battle.removeElement(elementsOnMap.iterator().next());
while (!elementsOnMap.isEmpty()) {
sleep(10);
elementsOnMap = battle.getElements();
}
assertTrue("The map should'nt have any element",
elementsOnMap.isEmpty());
battle.setScale(new Scale(25, 1.5));
battle.setFilter(new UniqueID());
sleep();
// Should have 4 call
// (add element, remove element, scale change, filter change)
verifyInnerClassCall(4);