public ECSAction copy() { return copy(owner); }
@Override public Component copy(Entity copyTo) { ActionComponent copy = new ActionComponent(); for (Entry<String, ECSAction> entry : actions.entrySet()) { copy.addAction(entry.getValue().copy(copyTo)); } return copy; }
@Test public void testPerformAllowedAction() { game.startGame(); ActionComponent actions = retriever.get(entity); assertEquals(Collections.<String>emptySet(), actions.getActions()); @SuppressWarnings("unchecked") Consumer<ECSAction> perform = (Consumer<ECSAction>) mock(Consumer.class); String name = "Use"; actions.addAction(new ECSAction(entity, name, action -> true, perform)); actions.getAction(name).copy().perform(entity); verify(perform).accept(Mockito.any(ECSAction.class)); }
@Test public void deniedActionWithSystem() { String name = "Use"; game.addSystem(new SpecificActionSystem(name) { @Override protected void isAllowed(ActionAllowedCheckEvent event) { event.setAllowed(false); } @Override protected void onPerform(ActionPerformEvent event) { } }); game.startGame(); ActionComponent actions = retriever.get(entity); assertEquals(Collections.<String>emptySet(), actions.getActions()); @SuppressWarnings("unchecked") Consumer<ECSAction> perform = (Consumer<ECSAction>) mock(Consumer.class); actions.addAction(new ECSAction(entity, name, action -> true, perform)); actions.getAction(name).copy().perform(entity); verifyNoMoreInteractions(perform); assertFalse(actions.getAction(name).isAllowed(entity)); }