@Test public void test() { double xSpeed = 10; double ySpeed = 10; double initialPosX = 100; double initialPosY = 100; double width = 100; double height = 100; // Creating a model SpriteModel model = new SpriteModel(initialPosX, initialPosY, xSpeed, ySpeed, width, height, "", ""); // creating a change visibility action ActionChangeVisibility actionChangeVisibility = new ActionChangeVisibility(false); // Invoking the action on the model actionChangeVisibility.doAction(model); // Check whether the visibility has changed if (!model.isVisible()) assertTrue(true); else assertTrue(false); }
@Test public void test() { double xSpeed = 10; double ySpeed = 10; double initialPosX = 100; double initialPosY = 100; double width = 100; double height = 100; // Creating a model SpriteModel model = new SpriteModel(initialPosX, initialPosY, xSpeed, ySpeed, width, height, "", ""); // Creating a Move action ActionMove actionMove = new ActionMove(); // Invoking the action on the model actionMove.doAction(model); // Checking whether the models position is moved according to xpeed and yspeed if ((model.getPosX() - initialPosX == xSpeed) && (model.getPosY() - initialPosY == ySpeed)) assertTrue(true); else assertTrue(false); }
/** Test method for {@link eventlistener.NewFrameEventListener#checkEvent(java.util.HashMap)}. */ @Test public void testCheckEvent() { SpriteModel selectedSpriteModel = new SpriteModel(100, 100, 20, 20, 100, 100, "", ""); SpriteModel selectedSpriteModelTest = new SpriteModel(190, 190, 20, 20, 100, 100, "", ""); SpriteList.getInstance().addSprite(selectedSpriteModel); SpriteList.getInstance().addSprite(selectedSpriteModelTest); NewFrameEventListener newFrameListener = new NewFrameEventListener(); newFrameListener.setRegisteredGroupId(selectedSpriteModel.getGroupId()); newFrameListener.setRegisteredObjectId(selectedSpriteModel.getId()); GameAction action = new ActionMove(); newFrameListener.setAction(action); double previousX = selectedSpriteModel.getPosX(); double previousY = selectedSpriteModel.getPosY(); newFrameListener.checkEvent(null); if (selectedSpriteModel.getPosX() - previousX == 20 && selectedSpriteModel.getPosY() - previousY == 20) assertTrue(true); else assertTrue(false); }