EditionPresenter implements EditionView.Presenter { @Override public void onResetChanges(FBFormItem fakeItem, Map<String, Object> newItems) { Map<String, Object> dataSnapshot = new HashMap<String, Object>(); dataSnapshot.put("newItems", newItems); dataSnapshot.put("fakeItemSelected", fakeItem); bus.fireEvent(new UndoableEvent(dataSnapshot, new UndoableHandler() { @Override public void onEvent(UndoableEvent event) { } @Override @SuppressWarnings("unchecked") public void undoAction(UndoableEvent event) { FBFormItem itemSelected = (FBFormItem) event.getData("fakeItemSelected"); itemSelected.saveValues((Map<String, Object>) event.getData("newItems")); editView.populate(itemSelected); } @Override public void doAction(UndoableEvent event) { FBFormItem itemSelected = (FBFormItem) event.getData("fakeItemSelected"); editView.populate(itemSelected); } })); } EditionPresenter(EditionView view); @Override void onSaveChanges(Map<String, Object> oldProps, Map<String, Object> newProps, FBFormItem itemSelected); @Override void onResetChanges(FBFormItem fakeItem, Map<String, Object> newItems);  }
@Test public void testOnResetChanges() throws Exception { final FBFormItem formItem = EasyMock.createMock(FBFormItem.class); final Map<String, Object> newProps = new HashMap<String, Object>(); UndoableHandler handler = EasyMock.createMock(UndoableHandler.class); handler.onEvent(EasyMock.isA(UndoableEvent.class)); EasyMock.expectLastCall().andAnswer(new IAnswer<Object>() { public Object answer() throws Throwable { Object[] params = EasyMock.getCurrentArguments(); UndoableEvent event = (UndoableEvent) params[0]; assertNotNull("newItems shouldn't be null", event.getData("newItems")); assertNotNull("fakeItemSelected shouldn't be null", event.getData("fakeItemSelected")); assertSame("newProps and newItems should be the same", newProps, event.getData("newItems")); assertSame("formItem and fakeItemSelected should be the same", formItem, event.getData("itemSelected")); return null; } }).once(); bus.addHandler(UndoableEvent.TYPE, handler); view.populate(EasyMock.same(formItem)); EasyMock.expectLastCall().once(); EasyMock.replay(view, formItem); EditionPresenter presenter = new EditionPresenter(view); presenter.onResetChanges(formItem, newProps); EasyMock.verify(view, formItem); }