@Before public void setup() { final HablarTester hablar = new HablarTester(); itemMenu = hablar.newMenu(); final RosterItemDisplay itemDisplay = hablar.newDisplay(RosterItemDisplay.class); display = hablar.newDisplay(RosterGroupDisplay.class); when(display.newRosterItemDisplay(anyString(), anyString())).thenReturn(itemDisplay); group = new RosterGroup("mygroup"); final RosterConfig rosterConfig = new RosterConfig(); new RosterGroupPresenter( group, itemMenu, display, rosterConfig, new ImmediateRunCommandScheduler()); group.add(RosterItemHelper.createItem("test1", "name1", "mygroup")); group.add(RosterItemHelper.createItem("test2", "name2", "mygroup")); group.add(RosterItemHelper.createItem("test3", "name3", "mygroup")); rosterConfig.oneClickChat = true; Mockito.reset(display); }
@Override protected void preloadForm() { display.clearSelectionList(); display.getGroupName().setValue(oldGroupName); final RosterGroup group = roster.getRosterGroup(oldGroupName); final Set<XmppURI> addedUris = new HashSet<XmppURI>(); if (group != null) { for (final RosterItem item : group.getItems()) { display.addSelectedRosterItem(item); addedUris.add(item.getJID()); } } for (final RosterItem item : roster.getItems()) { if (!addedUris.contains(item.getJID())) { display.addRosterItem(item); } } }
@Test public void shouldRemoveWhenItemRemoved() { group.remove(XmppURI.uri("test1")); verify(display, times(1)).remove((RosterItemDisplay) anyObject()); }
@Test public void shouldAddWhenItemAdded() { group.add(RosterItemHelper.createItem("test4", "name4", "mygroup")); verify(display, times(1)).add((RosterItemDisplay) anyObject()); }