@Test public void testMenuItemSelected() throws Exception { final Dispatcher dispatcher = Dispatcher.getInstance(); final Store store = mock(Store.class); dispatcher.registerStore(store); dispatcher.menuItemSelected(MenuItem.HOME); dispatcher.menuItemSelected(MenuItem.COMPANY); final ArgumentCaptor<Action> actionCaptor = ArgumentCaptor.forClass(Action.class); verify(store, times(4)).onAction(actionCaptor.capture()); verifyNoMoreInteractions(store); final List<Action> actions = actionCaptor.getAllValues(); final List<MenuAction> menuActions = actions.stream() .filter(a -> a.getType().equals(ActionType.MENU_ITEM_SELECTED)) .map(a -> (MenuAction) a) .collect(Collectors.toList()); final List<ContentAction> contentActions = actions.stream() .filter(a -> a.getType().equals(ActionType.CONTENT_CHANGED)) .map(a -> (ContentAction) a) .collect(Collectors.toList()); assertEquals(2, menuActions.size()); assertEquals(1, menuActions.stream().map(MenuAction::getMenuItem).filter(MenuItem.HOME::equals).count()); assertEquals(1, menuActions.stream().map(MenuAction::getMenuItem).filter(MenuItem.COMPANY::equals).count()); assertEquals(2, contentActions.size()); assertEquals(1, contentActions.stream().map(ContentAction::getContent).filter(Content.PRODUCTS::equals).count()); assertEquals(1, contentActions.stream().map(ContentAction::getContent).filter(Content.COMPANY::equals).count()); }
public void menuItemSelected(MenuItem menuItem) { dispatchAction(new MenuAction(menuItem)); switch (menuItem) { case HOME: case PRODUCTS: default: dispatchAction(new ContentAction(Content.PRODUCTS)); break; case COMPANY: dispatchAction(new ContentAction(Content.COMPANY)); break; } }
Dispatcher { public void menuItemSelected(MenuItem menuItem) { dispatchAction(new MenuAction(menuItem)); switch (menuItem) { case HOME: case PRODUCTS: default: dispatchAction(new ContentAction(Content.PRODUCTS)); break; case COMPANY: dispatchAction(new ContentAction(Content.COMPANY)); break; } } }
Dispatcher { public void menuItemSelected(MenuItem menuItem) { dispatchAction(new MenuAction(menuItem)); switch (menuItem) { case HOME: case PRODUCTS: default: dispatchAction(new ContentAction(Content.PRODUCTS)); break; case COMPANY: dispatchAction(new ContentAction(Content.COMPANY)); break; } } private  Dispatcher(); }
Dispatcher { public void menuItemSelected(MenuItem menuItem) { dispatchAction(new MenuAction(menuItem)); switch (menuItem) { case HOME: case PRODUCTS: default: dispatchAction(new ContentAction(Content.PRODUCTS)); break; case COMPANY: dispatchAction(new ContentAction(Content.COMPANY)); break; } } private  Dispatcher(); static Dispatcher getInstance(); void registerStore(Store store); void menuItemSelected(MenuItem menuItem); }
Dispatcher { public void menuItemSelected(MenuItem menuItem) { dispatchAction(new MenuAction(menuItem)); switch (menuItem) { case HOME: case PRODUCTS: default: dispatchAction(new ContentAction(Content.PRODUCTS)); break; case COMPANY: dispatchAction(new ContentAction(Content.COMPANY)); break; } } private  Dispatcher(); static Dispatcher getInstance(); void registerStore(Store store); void menuItemSelected(MenuItem menuItem);  }