use of com.thecoderscorner.menu.domain.EnumMenuItem in project tcMenu by davetcc.
the class MenuIdChooserImplTest method testIdEepromGenerationOnEmptyTree.
@Test
public void testIdEepromGenerationOnEmptyTree() {
MenuTree menuTree = new MenuTree();
chooser = new MenuIdChooserImpl(menuTree);
assertEquals(1, chooser.nextHighestId());
assertEquals(2, chooser.nextHighestEeprom());
EnumMenuItem item = EnumMenuItemBuilder.anEnumMenuItemBuilder().withId(1).withEepromAddr(-1).withName("Test").withEnumList(Collections.emptyList()).menuItem();
menuTree.addMenuItem(MenuTree.ROOT, item);
assertEquals(2, chooser.nextHighestEeprom());
}
use of com.thecoderscorner.menu.domain.EnumMenuItem in project tcMenu by davetcc.
the class UIEnumMenuItemTest method checkThatConsumerCalledWith.
private void checkThatConsumerCalledWith(String... expected) {
ArgumentCaptor<MenuItem> captor = ArgumentCaptor.forClass(MenuItem.class);
verify(mockedConsumer, atLeastOnce()).accept(any(), captor.capture());
EnumMenuItem item = (EnumMenuItem) captor.getValue();
assertThat(item.getEnumEntries()).containsExactly(expected);
}
use of com.thecoderscorner.menu.domain.EnumMenuItem in project tcMenu by davetcc.
the class UIEnumMenuItem method getChangedMenuItem.
@Override
protected Optional<EnumMenuItem> getChangedMenuItem() {
List<FieldError> errors = new ArrayList<>();
ObservableList<String> items = listView.getItems();
if (items.isEmpty()) {
errors.add(new FieldError("There must be at least one choice", "Choices"));
} else if (items.stream().anyMatch(str -> str.isEmpty() || str.matches(".*[\"\\\\].*$"))) {
errors.add(new FieldError("Choices must not contain speech marks or backslash", "Choices"));
}
EnumMenuItemBuilder builder = EnumMenuItemBuilder.anEnumMenuItemBuilder().withExisting(getMenuItem()).withEnumList(items);
getChangedDefaults(builder, errors);
return getItemOrReportError(builder.menuItem(), errors);
}
Aggregations