@Test public void testSetItems_ResetsSelectionIndex() { handler.handleSet(new JsonObject().add("selectionIndex", 7)); dropDown.setItems(new String[] {"a"}); assertEquals(-1, dropDown.getSelectionIndex()); }
@Test public void testHide_SetsVisible() { dropDown.setVisible(true); dropDown.setVisible(false); assertFalse(dropDown.getVisible()); }
@Test public void testGetItems_returnsItems() { String[] items = new String[] {"a", "b", "c"}; dropDown.setItems(items); assertTrue(Arrays.equals(items, dropDown.getItems())); }
@Test public void testRemoveListener_DefaultSelectionRenderListenFalse() { Listener listener = mock(Listener.class); dropDown.addListener(SWT.DefaultSelection, listener); dropDown.removeListener(SWT.DefaultSelection, listener); verify(remoteObject).listen(eq("DefaultSelection"), eq(false)); }
@Test public void testProcessSetVisible_ValueIsFalse() { dropDown.setVisible(true); handler.handleSet(new JsonObject().add("visible", false)); assertFalse(dropDown.getVisible()); }
@Test public void testSetSelectionIndex_RendersSelection() { dropDown.setItems(FOUR_ITEMS); dropDown.setSelectionIndex(2); verify(remoteObject).set("selectionIndex", 2); }
@Test public void testSetSelectionIndex_SetsSelection() { dropDown.setItems(FOUR_ITEMS); dropDown.setSelectionIndex(2); assertEquals(2, dropDown.getSelectionIndex()); }
@Test public void testHide_RendersVisibleFalse() { dropDown.setVisible(true); dropDown.setVisible(false); verify(remoteObject).set("visible", false); }
@Test public void testSetItems_storesSaveCopy() { String[] items = new String[] {"a", "b", "c"}; dropDown.setItems(items); items[1] = "x"; assertEquals("b", dropDown.getItems()[1]); }
@Test public void testSetSelectionIndex_IgnoredForTooBigValue() { dropDown.setItems(FOUR_ITEMS); dropDown.setSelectionIndex(2); dropDown.setSelectionIndex(4); assertEquals(2, dropDown.getSelectionIndex()); }
@Test public void testRemoveListener_SelectionRenderListenFalse() { Listener listener = mock(Listener.class); dropDown.addListener(SWT.Selection, listener); // Mockito.reset( remoteObject ); dropDown.removeListener(SWT.Selection, listener); verify(remoteObject).listen(eq("Selection"), eq(false)); }
@Test public void testDispose_FiresDispose() { Fixture.fakePhase(PhaseId.PROCESS_ACTION); Listener listener = mock(Listener.class); dropDown.addListener(SWT.Dispose, listener); dropDown.dispose(); verify(listener).handleEvent(any(Event.class)); }
protected void disableInputFields(boolean disable) { txtName.setDisabled(disable); txtDesc.setDisabled(disable); txtNotes.setDisabled(disable); cbbMembers.setDisabled(disable); cbbCategory.setDisabled(disable); cbbSubCategory.setDisabled(disable); btnAddSubCat.setDisabled(disable); btnRemoveSubCat.setDisabled(disable || subCatUnremovable()); }
@Test public void testSetVisibleItemCount_DoesNotRenderVisibleItemCountIfUnchanged() { dropDown.setVisibleItemCount(7); dropDown.setVisibleItemCount(7); verify(remoteObject, times(1)).set("visibleItemCount", 7); }
@Test public void testSetItems_RenderItems() { dropDown.setItems(new String[] {"a", "b", "c"}); JsonArray expected = JsonUtil.createJsonArray(new String[] {"a", "b", "c"}); verify(remoteObject).set(eq("items"), eq(expected)); }
@Test public void testVisible_SetToTrueTwiceRenderVisibleOnce() { dropDown.setVisible(true); dropDown.setVisible(true); verify(remoteObject, times(1)).set("visible", true); }
@Test public void testStyles_addsHSroll() { dropDown = new DropDown(text, SWT.H_SCROLL); assertEquals(SWT.V_SCROLL, dropDown.getStyle() & SWT.V_SCROLL); assertEquals(SWT.H_SCROLL, dropDown.getStyle() & SWT.H_SCROLL); }
@Test public void testAddListener_Selection_doesNotSendListenTwice() { dropDown.addListener(SWT.Selection, mock(Listener.class)); dropDown.addListener(SWT.Selection, mock(Listener.class)); verify(remoteObject, times(1)).listen(eq("Selection"), eq(true)); }
@Test public void testSetData_RendersColumns() { Fixture.fakePhase(PhaseId.PROCESS_ACTION); dropDown.setData("columns", new int[] {10, 20}); verify(remoteObject).set(eq("columns"), eq(new JsonArray().add(10).add(20))); }
@Test public void testSetData_RendersMarkupEnabled() { Fixture.fakePhase(PhaseId.PROCESS_ACTION); dropDown.setData(RWT.MARKUP_ENABLED, Boolean.TRUE); verify(remoteObject).set(eq("markupEnabled"), eq(true)); }
@Test public void testSetData_RendersIncorrectTypeAsNull() { Fixture.fakePhase(PhaseId.PROCESS_ACTION); dropDown.setData("columns", Boolean.TRUE); verify(remoteObject).set(eq("columns"), eq(JsonValue.NULL)); }
@Test public void testAddListener_SelectionRenderListenTrue() { Listener listener = mock(Listener.class); dropDown.addListener(SWT.Selection, listener); verify(remoteObject).listen(eq("Selection"), eq(true)); }
@Test public void testSetData_RendersDataInWhiteList() { Fixture.fakePhase(PhaseId.PROCESS_ACTION); WidgetUtil.registerDataKeys("foo", "bar"); dropDown.setData("foo", "bar"); verify(remoteObject).set(eq("data"), eq(new JsonObject().add("foo", "bar"))); }
@Test public void testSetData_DoesNotRenderDataNotInWhiteList() { Fixture.fakePhase(PhaseId.PROCESS_ACTION); WidgetUtil.registerDataKeys("foo", "bar"); dropDown.setData("fool", "bar"); verify(remoteObject, never()).set(eq("data"), any(JsonObject.class)); }
@Test public void testRemoveListener_rendersClientListeners() { ClientListener listener = new ClientListener(""); String listenerId = ClientListenerUtil.getRemoteId(listener); dropDown.removeListener(SWT.Show, listener); JsonObject expectedParameters = new JsonObject().add("eventType", "Show").add("listenerId", listenerId); verify(remoteObject).call(eq("removeListener"), eq(expectedParameters)); }
/* sets or hides fields depending on which tab is shown */ public void setVisibleComponents(nonHumanMgt.SelType sType) { boolean catTab = (sType == nonHumanMgt.SelType.category); // these only appear on the resources tab cbbCategory.setVisible(!catTab); lblSubCategory.setVisible(!catTab); cbbSubCategory.setVisible(!catTab); // these only appear on the categories tab lblMembers.setVisible(catTab); cbbMembers.setVisible(catTab); lbxSubCatItems.setVisible(catTab); btnAddSubCat.setVisible(catTab); btnRemoveSubCat.setVisible(catTab); // nullify lists if (catTab) { cbbCategory.setItems(null); cbbSubCategory.setItems(null); } else lbxSubCatItems.setItems(null); }
/* saves a newly added resource to the org database */ public boolean addResource(String name) { if (!_orgDataSet.isKnownNonHumanResourceName(name)) { String catID = (String) cbbCategory.getSelected(); NonHumanCategory category = _orgDataSet.getNonHumanCategory(catID); String subCat = (String) cbbSubCategory.getSelected(); NonHumanResource resource = _sb.getSelectedNonHumanResource(); if (resource == null) resource = new NonHumanResource(); resource.setName(name); resource.setCategory(category); resource.setSubCategory(subCat); resource.setDescription((String) txtDesc.getText()); resource.setNotes((String) txtNotes.getText()); String newID = _orgDataSet.addNonHumanResource(resource); if (_rm.successful(newID)) { updateSelectedResource(resource, false); _sb.setNhResourcesChoice(newID); return true; } else _msgPanel.error(_msgPanel.format(newID)); } else addDuplicationError("Resource"); return false; }
/* fills ui with the selected resource's values */ private void populateGUI(NonHumanResource resource, String id) { // selected resource is null after a selection change if (resource == null) { resource = _orgDataSet.getNonHumanResource(id); updateSelectedResource(resource); } if (resource != null) { populateSimpleFields(resource); NonHumanCategory category = resource.getCategory(); String subCatName = resource.getSubCategoryName(); if (category == null) { category = getFirstListedCategory(); // default } if (subCatName == null) subCatName = "None"; if (category != null) { cbbCategory.setSelected(category.getID()); _sb.setNhResourcesSubcategoryItems(getSubCategoryList(category)); cbbSubCategory.setSelected(subCatName); } else _sb.setNhResourcesSubcategoryItems(null); // no categories defined } _sb.setNhResourcesSubcategoryList(null); // empty the category tab list box }
@Test public void testFireDefaultSelectionEvent() { Fixture.fakePhase(PhaseId.PROCESS_ACTION); final List<Event> log = new ArrayList<Event>(); dropDown.addListener( SWT.DefaultSelection, new Listener() { @Override public void handleEvent(Event event) { log.add(event); } }); handler.handleNotify("DefaultSelection", new JsonObject().add("index", 2).add("text", "foo")); assertEquals(1, log.size()); assertEquals(2, log.get(0).index); assertEquals("foo", log.get(0).text); }
protected void clearCombos() { cbbCategory.setSelected(null); cbbSubCategory.setSelected(null); cbbCategory.setItems(null); cbbSubCategory.setItems(null); }