@Test public void text() { // Arrange CheckBox cb = new CheckBox("foo"); // Pre-Assert assertEquals("foo", cb.getText()); // Act cb.setText("text"); // Assert assertEquals("text", cb.getText()); }
public void addCheckbox(String list, Boolean value) { final CheckBox checkbox = new CheckBox(list); StyledFlowPanel fix = new StyledFlowPanel("fix"); checkbox.addStyleName("checkbox"); // manage checks and unchecks checkbox.addValueChangeHandler( new ValueChangeHandler<Boolean>() { @Override public void onValueChange(ValueChangeEvent<Boolean> event) { // is the item is checked? if (event.getValue() == true && !listed.contains(checkbox.getText()) && checkbox.getText() != null && checkbox.getText().length() != 0) { // set the values listed.add(checkbox.getText()); rosterItem.setGroups(listed); // disable during processing checkbox.setEnabled(false); // show task final DefaultTaskInfo task = new DefaultTaskInfo("Adding person to the list", false); TaskMonitor.getInstance().addTask(task); // save new state rosterItem.save( new RequestCallback<RosterItem>() { @Override public void onFailure() { // return to original state and notify user checkbox.setEnabled(true); checkbox.setValue(true); task.complete("Could not add person to list.", Status.failure); } @Override public void onSuccess(RosterItem result) { // enable the checkbox again checkbox.setEnabled(true); task.complete("", Status.succes); } }); } else if (event.getValue() == false && listed.contains(checkbox.getText())) { // set the values listed.remove(checkbox.getText()); rosterItem.setGroups(listed); // disable during processing checkbox.setEnabled(false); // show task final DefaultTaskInfo task = new DefaultTaskInfo("Removing person from the list", false); TaskMonitor.getInstance().addTask(task); // save new state rosterItem.save( new RequestCallback<RosterItem>() { @Override public void onFailure() { // return to original state and notify user checkbox.setEnabled(true); checkbox.setValue(true); task.complete("Could not remove person from the list.", Status.failure); } @Override public void onSuccess(RosterItem result) { // enable the checkbox again checkbox.setEnabled(true); task.complete("", Status.succes); } }); } } }); // if this person is already on the list make sure the checkbox is // checked if (listed != null && list.length() > 0 && listed.contains(list)) { checkbox.setValue(true); } else if (value == true) { // if a new checkbox is added automatically check it and fire a // change event checkbox.setValue(true); checkbox.fireEvent(new ValueChangeEvent<Boolean>(true) {}); } if (checkbox.getText() != null && checkbox.getText().length() != 0) { wrapper.add(checkbox); wrapper.add(fix); } }