method2testcases
stringlengths 118
3.08k
|
---|
### Question:
BindingContext implements UiUpdateObserver { public void modelChanged() { updateUI(); } BindingContext(); BindingContext(String contextName); BindingContext(String contextName, PropertyBehaviorProvider behaviorProvider,
Handler afterUpdateHandler); BindingContext(String contextName, PropertyBehaviorProvider behaviorProvider,
PropertyDispatcherFactory dispatcherFactory, Handler afterUpdateHandler); String getName(); @Deprecated BindingContext add(Binding binding); BindingContext add(Binding binding, ComponentWrapper componentWrapper); Collection<Binding> getBindings(); void removeBindingsForComponent(Object uiComponent); void removeBindingsForPmo(Object pmo); @Deprecated void updateUI(); void modelChanged(); @Override void uiUpdated(); @Deprecated final void updateMessages(MessageList messages); MessageList displayMessages(MessageList messages); PropertyBehaviorProvider getBehaviorProvider(); @Override String toString(); Binding bind(Object pmo,
BindingDescriptor bindingDescriptor,
ComponentWrapper componentWrapper); Binding bind(Object pmo,
BoundProperty boundProperty,
List<LinkkiAspectDefinition> aspectDefs,
ComponentWrapper componentWrapper); ContainerBinding bindContainer(Object pmo,
BoundProperty boundProperty,
List<LinkkiAspectDefinition> aspectDefs,
ComponentWrapper componentWrapper); @Deprecated final PropertyDispatcher createDispatcherChain(Object pmo,
BindingDescriptor bindingDescriptor); }### Answer:
@Test public void testModelChangedBindingsAndValidate_noBindingInContext() { Handler afterUpdateUi = mock(Handler.class); BindingContext context = new BindingContext("", PropertyBehaviorProvider.NO_BEHAVIOR_PROVIDER, afterUpdateUi); context.modelChanged(); verify(afterUpdateUi).apply(); } |
### Question:
BindingContext implements UiUpdateObserver { public Binding bind(Object pmo, BindingDescriptor bindingDescriptor, ComponentWrapper componentWrapper) { requireNonNull(bindingDescriptor, "bindingDescriptor must not be null"); return bind(pmo, bindingDescriptor.getBoundProperty(), bindingDescriptor.getAspectDefinitions(), componentWrapper); } BindingContext(); BindingContext(String contextName); BindingContext(String contextName, PropertyBehaviorProvider behaviorProvider,
Handler afterUpdateHandler); BindingContext(String contextName, PropertyBehaviorProvider behaviorProvider,
PropertyDispatcherFactory dispatcherFactory, Handler afterUpdateHandler); String getName(); @Deprecated BindingContext add(Binding binding); BindingContext add(Binding binding, ComponentWrapper componentWrapper); Collection<Binding> getBindings(); void removeBindingsForComponent(Object uiComponent); void removeBindingsForPmo(Object pmo); @Deprecated void updateUI(); void modelChanged(); @Override void uiUpdated(); @Deprecated final void updateMessages(MessageList messages); MessageList displayMessages(MessageList messages); PropertyBehaviorProvider getBehaviorProvider(); @Override String toString(); Binding bind(Object pmo,
BindingDescriptor bindingDescriptor,
ComponentWrapper componentWrapper); Binding bind(Object pmo,
BoundProperty boundProperty,
List<LinkkiAspectDefinition> aspectDefs,
ComponentWrapper componentWrapper); ContainerBinding bindContainer(Object pmo,
BoundProperty boundProperty,
List<LinkkiAspectDefinition> aspectDefs,
ComponentWrapper componentWrapper); @Deprecated final PropertyDispatcher createDispatcherChain(Object pmo,
BindingDescriptor bindingDescriptor); }### Answer:
@Test public void testBind_ButtonPmoBindningToCheckUpdateFromPmo() { BindingContext context = new BindingContext(); TestButtonPmo buttonPmo = new TestButtonPmo(); TestUiComponent button = new TestUiComponent(); buttonPmo.setEnabled(false); ComponentWrapper buttonWrapper = new TestComponentWrapper(button); context.bind(buttonPmo, BoundProperty.of(""), Arrays.asList(new EnabledAspectDefinition(EnabledType.DYNAMIC)), buttonWrapper); assertThat(button.isEnabled(), is(false)); } |
### Question:
WrapperType { public boolean isAssignableFrom(@CheckForNull WrapperType type) { return this.equals(type) || (type != null && isAssignableFrom(type.getParent())); } private WrapperType(String name, WrapperType parent); static WrapperType of(String name); static WrapperType of(String name, WrapperType parent); @CheckForNull WrapperType getParent(); boolean isRoot(); boolean isAssignableFrom(@CheckForNull WrapperType type); @Override int hashCode(); @Override boolean equals(Object obj); @Override String toString(); static final WrapperType ROOT; static final WrapperType COMPONENT; static final WrapperType LAYOUT; static final WrapperType FIELD; }### Answer:
@Test public void testIsAssignableFrom() { assertTrue(WrapperType.ROOT.isAssignableFrom(WrapperType.ROOT)); assertTrue(WrapperType.ROOT.isAssignableFrom(WrapperType.COMPONENT)); assertTrue(WrapperType.ROOT.isAssignableFrom(WrapperType.FIELD)); assertTrue(WrapperType.ROOT.isAssignableFrom(WrapperType.LAYOUT)); assertTrue(WrapperType.ROOT.isAssignableFrom(WrapperType.of("custom"))); assertTrue(WrapperType.ROOT.isAssignableFrom(WrapperType.of("customComponent", WrapperType.COMPONENT))); assertTrue(WrapperType.COMPONENT.isAssignableFrom(WrapperType.COMPONENT)); assertTrue(WrapperType.COMPONENT.isAssignableFrom(WrapperType.LAYOUT)); assertTrue(WrapperType.COMPONENT.isAssignableFrom(WrapperType.FIELD)); assertFalse(WrapperType.FIELD.isAssignableFrom(WrapperType.COMPONENT)); assertFalse(WrapperType.FIELD.isAssignableFrom(WrapperType.ROOT)); assertFalse(WrapperType.of("custom").isAssignableFrom(WrapperType.COMPONENT)); assertFalse(WrapperType.of("custom", WrapperType.COMPONENT).isAssignableFrom(WrapperType.COMPONENT)); } |
### Question:
WrapperType { public boolean isRoot() { return this == ROOT; } private WrapperType(String name, WrapperType parent); static WrapperType of(String name); static WrapperType of(String name, WrapperType parent); @CheckForNull WrapperType getParent(); boolean isRoot(); boolean isAssignableFrom(@CheckForNull WrapperType type); @Override int hashCode(); @Override boolean equals(Object obj); @Override String toString(); static final WrapperType ROOT; static final WrapperType COMPONENT; static final WrapperType LAYOUT; static final WrapperType FIELD; }### Answer:
@Test public void testIsRoot() { assertTrue(WrapperType.ROOT.isRoot()); assertFalse(WrapperType.COMPONENT.isRoot()); assertFalse(WrapperType.FIELD.isRoot()); assertFalse(WrapperType.of("foo", null).isRoot()); assertFalse(WrapperType.of("", null).isRoot()); } |
### Question:
ElementBinding implements Binding { @Override public void updateFromPmo() { try { aspectUpdaters.updateUI(); componentWrapper.postUpdate(); } catch (RuntimeException e) { throw new LinkkiBindingException( "Error while updating UI (" + e.getMessage() + ") in " + toString(), e); } } ElementBinding(ComponentWrapper componentWrapper, PropertyDispatcher propertyDispatcher,
Handler modelChanged, List<LinkkiAspectDefinition> aspectDefinitions); PropertyDispatcher getPropertyDispatcher(); @Override void updateFromPmo(); @Override Object getBoundComponent(); @Override @SuppressFBWarnings(value = "NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE", justification = "because that's what requireNonNull is for") Object getPmo(); @Override MessageList displayMessages(MessageList messages); @Override String toString(); }### Answer:
@Test public void testUpdateFromPmo_updateAspect() { Handler componentUpdater = mock(Handler.class); LinkkiAspectDefinition aspectDefinition = mock(LinkkiAspectDefinition.class); when(aspectDefinition.supports(any())).thenReturn(true); when(aspectDefinition.createUiUpdater(any(), any())).thenReturn(componentUpdater); ElementBinding fieldBinding = new ElementBinding(new TestComponentWrapper(field), propertyDispatcherValue, Handler.NOP_HANDLER, Arrays.asList(aspectDefinition)); fieldBinding.updateFromPmo(); verify(componentUpdater).apply(); } |
### Question:
ElementBinding implements Binding { @Override public MessageList displayMessages(MessageList messages) { MessageList messagesForProperty = getRelevantMessages(messages); componentWrapper.setValidationMessages(messagesForProperty); return messagesForProperty; } ElementBinding(ComponentWrapper componentWrapper, PropertyDispatcher propertyDispatcher,
Handler modelChanged, List<LinkkiAspectDefinition> aspectDefinitions); PropertyDispatcher getPropertyDispatcher(); @Override void updateFromPmo(); @Override Object getBoundComponent(); @Override @SuppressFBWarnings(value = "NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE", justification = "because that's what requireNonNull is for") Object getPmo(); @Override MessageList displayMessages(MessageList messages); @Override String toString(); }### Answer:
@Test public void testDisplayMessages() { messageList.add(Message.newError("code", "text")); selectBinding.displayMessages(messageList); @NonNull MessageList validationMessages = selectField.getValidationMessages(); assertThat(validationMessages, hasErrorMessage("code")); Message firstMessage = validationMessages.getFirstMessage(Severity.ERROR).get(); assertEquals(firstMessage.getText(), "text"); }
@Test public void testDisplayMessages_noMessages() { selectBinding.displayMessages(messageList); assertThat(selectField.getValidationMessages(), is(emptyMessageList())); }
@Test public void testDisplayMessages_noMessageList() { Assertions.assertThrows(NullPointerException.class, () -> { selectBinding.displayMessages(null); }); } |
### Question:
MultiformatDateField extends DateField { public List<String> getAlternativeFormat() { return Arrays.asList(getState().getAlternativeFormats()); } MultiformatDateField(); MultiformatDateField(String caption, LocalDate value); MultiformatDateField(String caption); MultiformatDateField(
ValueChangeListener<LocalDate> valueChangeListener); MultiformatDateField(String caption,
ValueChangeListener<LocalDate> valueChangeListener); MultiformatDateField(String caption, LocalDate value,
ValueChangeListener<LocalDate> valueChangeListener); @Override void setDateFormat(String dateFormat); void setAlternativeFormats(List<String> formats); void addAlternativeFormat(String formatString); List<String> getAlternativeFormat(); }### Answer:
@Test public void testSetDateFormat_NoSpecialDateFormatSet() { MultiformatDateField multiformatDateField = new MultiformatDateField(); String dateFormat = multiformatDateField.getDateFormat(); List<String> alternativeFormat = multiformatDateField.getAlternativeFormat(); assertThat(dateFormat, is(nullValue())); assertThat(alternativeFormat, is(empty())); } |
### Question:
ApplicationLayout extends VerticalLayout implements ViewDisplay { protected <T extends View & Component> T getCurrentView() { @SuppressWarnings("unchecked") T view = (T)mainArea; return view; } ApplicationLayout(ApplicationHeader header, @CheckForNull ApplicationFooter footer); @Override void showView(View view); }### Answer:
@Test public void testGetCurrentView_empty() { setUpApplicationLayout(); Component currentView = applicationLayout.getCurrentView(); assertThat(currentView, is(instanceOf(EmptyView.class))); }
@Test public void testGetCurrentView() { setUpApplicationLayout(); View view = mock(View.class, withSettings().extraInterfaces(Component.class).defaultAnswer(Mockito.CALLS_REAL_METHODS)); applicationLayout.showView(view); Component currentView = applicationLayout.getCurrentView(); assertThat(currentView, is(view)); }
@Test public void testGetCurrentView() { setUpApplicationLayout(); View view = mock(View.class, withSettings().extraInterfaces(Component.class)); applicationLayout.showView(view); Component currentView = applicationLayout.getCurrentView(); assertThat(currentView, is(view)); } |
### Question:
LinkkiUi extends UI { @Override protected void init(VaadinRequest request) { requireNonNull(applicationConfig, "configure must be called before executing any initialization to set an ApplicationConfig"); ApplicationLayout applicationLayout = applicationConfig.createApplicationLayout(); setContent(applicationLayout); configureNavigator(applicationLayout); configureErrorHandler(); VaadinSession vaadinSession = VaadinSession.getCurrent(); if (vaadinSession != null) { vaadinSession.setAttribute(LinkkiConverterRegistry.class, applicationConfig.getConverterRegistry()); vaadinSession.setErrorHandler(getErrorHandler()); } Page.getCurrent().setTitle(getPageTitle()); } @SuppressFBWarnings(value = "NP_NONNULL_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR", justification = "applicationConfig/Layout will be non-null once configure was called") protected LinkkiUi(); @SuppressFBWarnings(value = "NP_NONNULL_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR", justification = "applicationConfig/Layout will be non-null once configure was called") LinkkiUi(ApplicationConfig applicationConfig); ApplicationConfig getApplicationConfig(); ApplicationLayout getApplicationLayout(); @SuppressFBWarnings(value = "RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE", justification = "when called from the constructor before configure") @Override void setContent(@CheckForNull Component content); static LinkkiUi getCurrent(); static ApplicationConfig getCurrentApplicationConfig(); @Deprecated static ApplicationNavigator getCurrentApplicationNavigator(); static Navigator getCurrentNavigator(); static ApplicationLayout getCurrentApplicationLayout(); }### Answer:
@Test public void testInit() { initUi(); assertThat(UI.getCurrent().getContent(), is(linkkiUi.getApplicationLayout())); } |
### Question:
LinkkiUi extends UI { public ApplicationLayout getApplicationLayout() { return (ApplicationLayout)getContent(); } @SuppressFBWarnings(value = "NP_NONNULL_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR", justification = "applicationConfig/Layout will be non-null once configure was called") protected LinkkiUi(); @SuppressFBWarnings(value = "NP_NONNULL_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR", justification = "applicationConfig/Layout will be non-null once configure was called") LinkkiUi(ApplicationConfig applicationConfig); ApplicationConfig getApplicationConfig(); ApplicationLayout getApplicationLayout(); @SuppressFBWarnings(value = "RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE", justification = "when called from the constructor before configure") @Override void setContent(@CheckForNull Component content); static LinkkiUi getCurrent(); static ApplicationConfig getCurrentApplicationConfig(); @Deprecated static ApplicationNavigator getCurrentApplicationNavigator(); static Navigator getCurrentNavigator(); static ApplicationLayout getCurrentApplicationLayout(); }### Answer:
@Test public void testLayoutInitializedWithCorrectLocale() { linkkiUi.setLocale(Locale.CANADA); initUi(); String menuItem = ((ApplicationMenu)((ApplicationHeader)linkkiUi.getApplicationLayout().getComponent(0)) .getComponent(0)).getItems().get(0).getText(); assertThat(menuItem, is(Locale.CANADA.getDisplayCountry())); } |
### Question:
DateFormats { public static String getPattern(Locale locale) { requireNonNull(locale, "locale must not be null"); String registeredPattern = LANGUAGE_PATTERNS.get(locale.getLanguage()); if (registeredPattern != null) { return registeredPattern; } else { return defaultLocalePattern(locale); } } private DateFormats(); static void register(String languageCode, String pattern); static String getPattern(Locale locale); static final String PATTERN_ISO; static final String PATTERN_DE; }### Answer:
@Test public void testGetPattern() { assertThat(DateFormats.getPattern(GERMAN), is(DateFormats.PATTERN_DE)); assertThat(DateFormats.getPattern(GERMANY), is(DateFormats.PATTERN_DE)); assertThat(DateFormats.getPattern(AUSTRIA), is(DateFormats.PATTERN_DE)); assertThat(DateFormats.getPattern(ENGLISH), is(not(nullValue()))); assertThat(DateFormats.getPattern(ENGLISH), is(not(DateFormats.PATTERN_DE))); assertThat(DateFormats.getPattern(ENGLISH), is(not(DateFormats.PATTERN_ISO))); assertThat(DateFormats.getPattern(ENGLISH), is("M/d/yy")); assertThat(DateFormats.getPattern(US), is(not(nullValue()))); assertThat(DateFormats.getPattern(US), is(not(DateFormats.PATTERN_DE))); assertThat(DateFormats.getPattern(US), is(not(DateFormats.PATTERN_ISO))); assertThat(DateFormats.getPattern(US), is("M/d/yy")); assertThat(DateFormats.getPattern(UK), is(oneOf("dd/MM/yy", "dd/MM/y"))); } |
### Question:
SidebarSheet { protected void unselect() { getButton().removeStyleName(LinkkiApplicationTheme.SIDEBAR_SELECTED); getContent().setVisible(false); } @Deprecated SidebarSheet(Resource icon, Component content, String tooltip); SidebarSheet(Resource icon, String name, Component content); SidebarSheet(Resource icon, String name, Component content, UiUpdateObserver uiUpdateObserver); SidebarSheet(Resource icon, String name, Supplier<Component> contentSupplier); SidebarSheet(Resource icon, String name, Supplier<Component> contentSupplier,
@CheckForNull UiUpdateObserver uiUpdateObserver); SidebarSheet(String id, Resource icon, String name, Component content, UiUpdateObserver uiUpdateObserver); SidebarSheet(String id, Resource icon, String name, Component content); SidebarSheet(String id, Resource icon, String name, Supplier<Component> contentSupplier); SidebarSheet(String id, Resource icon, String name, Supplier<Component> contentSupplier,
@CheckForNull UiUpdateObserver uiUpdateObserver); String getId(); Button getButton(); Component getContent(); String getName(); Optional<UiUpdateObserver> getUiUpdateObserver(); void setUiUpdateObserver(@CheckForNull UiUpdateObserver uiUpdateObserver); @Override String toString(); }### Answer:
@Test public void testUnselect_checkVisibilitySetToFalse() { HorizontalLayout content = new HorizontalLayout(); SidebarSheet sheet = createSideBarSheet(content); sheet.unselect(); assertThat(content.isVisible(), is(false)); } |
### Question:
SidebarSheet { protected void select() { uiUpdateObserver.ifPresent(UiUpdateObserver::uiUpdated); getContent().setVisible(true); getButton().addStyleName(LinkkiApplicationTheme.SIDEBAR_SELECTED); } @Deprecated SidebarSheet(Resource icon, Component content, String tooltip); SidebarSheet(Resource icon, String name, Component content); SidebarSheet(Resource icon, String name, Component content, UiUpdateObserver uiUpdateObserver); SidebarSheet(Resource icon, String name, Supplier<Component> contentSupplier); SidebarSheet(Resource icon, String name, Supplier<Component> contentSupplier,
@CheckForNull UiUpdateObserver uiUpdateObserver); SidebarSheet(String id, Resource icon, String name, Component content, UiUpdateObserver uiUpdateObserver); SidebarSheet(String id, Resource icon, String name, Component content); SidebarSheet(String id, Resource icon, String name, Supplier<Component> contentSupplier); SidebarSheet(String id, Resource icon, String name, Supplier<Component> contentSupplier,
@CheckForNull UiUpdateObserver uiUpdateObserver); String getId(); Button getButton(); Component getContent(); String getName(); Optional<UiUpdateObserver> getUiUpdateObserver(); void setUiUpdateObserver(@CheckForNull UiUpdateObserver uiUpdateObserver); @Override String toString(); }### Answer:
@Test public void testSelect_checkVisibilitySetToTrue() { HorizontalLayout content = new HorizontalLayout(); SidebarSheet sheet = createSideBarSheet(content); sheet.select(); assertThat(content.isVisible(), is(true)); }
@Test public void testSelect_CheckObserver() { HorizontalLayout content = new HorizontalLayout(); SidebarSheet sidebarSheet = new SidebarSheet(VaadinIcons.STAR_HALF_LEFT, "Test SidebarSheet", content, () -> triggered = true); sidebarSheet.select(); assertThat(triggered, is(true)); } |
### Question:
SidebarSheet { @Override public String toString() { return name; } @Deprecated SidebarSheet(Resource icon, Component content, String tooltip); SidebarSheet(Resource icon, String name, Component content); SidebarSheet(Resource icon, String name, Component content, UiUpdateObserver uiUpdateObserver); SidebarSheet(Resource icon, String name, Supplier<Component> contentSupplier); SidebarSheet(Resource icon, String name, Supplier<Component> contentSupplier,
@CheckForNull UiUpdateObserver uiUpdateObserver); SidebarSheet(String id, Resource icon, String name, Component content, UiUpdateObserver uiUpdateObserver); SidebarSheet(String id, Resource icon, String name, Component content); SidebarSheet(String id, Resource icon, String name, Supplier<Component> contentSupplier); SidebarSheet(String id, Resource icon, String name, Supplier<Component> contentSupplier,
@CheckForNull UiUpdateObserver uiUpdateObserver); String getId(); Button getButton(); Component getContent(); String getName(); Optional<UiUpdateObserver> getUiUpdateObserver(); void setUiUpdateObserver(@CheckForNull UiUpdateObserver uiUpdateObserver); @Override String toString(); }### Answer:
@Test public void testToString() { SidebarSheet sheet = new SidebarSheet(VaadinIcons.ADJUST, "Foo", new TextField()); assertThat(sheet.toString(), is("Foo")); } |
### Question:
SidebarSheet { public String getId() { return id; } @Deprecated SidebarSheet(Resource icon, Component content, String tooltip); SidebarSheet(Resource icon, String name, Component content); SidebarSheet(Resource icon, String name, Component content, UiUpdateObserver uiUpdateObserver); SidebarSheet(Resource icon, String name, Supplier<Component> contentSupplier); SidebarSheet(Resource icon, String name, Supplier<Component> contentSupplier,
@CheckForNull UiUpdateObserver uiUpdateObserver); SidebarSheet(String id, Resource icon, String name, Component content, UiUpdateObserver uiUpdateObserver); SidebarSheet(String id, Resource icon, String name, Component content); SidebarSheet(String id, Resource icon, String name, Supplier<Component> contentSupplier); SidebarSheet(String id, Resource icon, String name, Supplier<Component> contentSupplier,
@CheckForNull UiUpdateObserver uiUpdateObserver); String getId(); Button getButton(); Component getContent(); String getName(); Optional<UiUpdateObserver> getUiUpdateObserver(); void setUiUpdateObserver(@CheckForNull UiUpdateObserver uiUpdateObserver); @Override String toString(); }### Answer:
@Test public void testGetId_DerivedByName() { SidebarSheet sidebarSheet = new SidebarSheet(VaadinIcons.STAR_HALF_LEFT, "Test SidebarSheet", new HorizontalLayout()); assertThat(sidebarSheet.getId(), is("Test SidebarSheet")); }
@Test public void testGetId() { SidebarSheet sidebarSheet = new SidebarSheet("sheet1", VaadinIcons.STAR_HALF_LEFT, "Test SidebarSheet", new HorizontalLayout()); assertThat(sidebarSheet.getId(), is("sheet1")); } |
### Question:
SidebarLayout extends CssLayout { public void select(String id) { getSidebarSheet(id).ifPresent(this::select); } SidebarLayout(); void addSheets(Stream<SidebarSheet> sheets); void addSheets(Iterable<SidebarSheet> sheets); void addSheets(@NonNull SidebarSheet... sheets); void addSheet(SidebarSheet sheet); Registration addSelectionListener(SelectionListener listener); void select(String id); void select(SidebarSheet sheet); SidebarSheet getSelected(); List<SidebarSheet> getSidebarSheets(); Optional<SidebarSheet> getSidebarSheet(String id); }### Answer:
@Test public void testSelect_NotRegistered() { SidebarLayout sidebarLayout = new SidebarLayout(); SidebarSheet sheet1 = new SidebarSheet(ANY_ICON, ANY_STRING, createNewContent()); Assertions.assertThrows(IllegalArgumentException.class, () -> { sidebarLayout.select(sheet1); }); } |
### Question:
OkCancelDialog extends Window { @SuppressFBWarnings(value = "RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE", justification = "yeah, we know...") @Override public void setContent(@CheckForNull Component content) { if (mainArea == null) { super.setContent(content); } else { mainArea.removeAllComponents(); mainArea.addComponent(content); } } protected OkCancelDialog(String caption, Handler okHandler, Handler cancelHandler,
ButtonOption buttonOption, Component... contentComponents); @Deprecated OkCancelDialog(String caption); @Deprecated OkCancelDialog(String caption, Handler okHandler); @Deprecated OkCancelDialog(String caption, Handler okHandler, ButtonOption buttonOption); @Deprecated OkCancelDialog(String caption, Component content, Handler okHandler, ButtonOption buttonOption); @SuppressFBWarnings(value = "RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE", justification = "yeah, we know...") @Override void setContent(@CheckForNull Component content); void setSize(String width, String height); MessageList validate(); ValidationService getValidationService(); void setValidationService(ValidationService validationService); void setBeforeOkHandler(Handler beforeOkHandler); OkCancelDialog open(); void addContent(Component c); void addContent(Component c, float expandRatio); boolean isOkPressed(); ValidationDisplayState getValidationDisplayState(); boolean isCancelPressed(); String getOkCaption(); void setOkCaption(String okCaption); String getCancelCaption(); void setCancelCaption(String cancelCaption); static Builder builder(String caption); }### Answer:
@Test public void testSetContent() { OkCancelDialog dialog = OkCancelDialog.builder("").build(); assertThat(DialogTestUtil.getContents(dialog).size(), is(0)); dialog.setContent(new Label()); assertThat(DialogTestUtil.getContents(dialog), hasSize(1)); assertThat(dialog, is(showingEnabledOkButton())); } |
### Question:
OkCancelDialog extends Window { protected void ok() { okHandler.apply(); } protected OkCancelDialog(String caption, Handler okHandler, Handler cancelHandler,
ButtonOption buttonOption, Component... contentComponents); @Deprecated OkCancelDialog(String caption); @Deprecated OkCancelDialog(String caption, Handler okHandler); @Deprecated OkCancelDialog(String caption, Handler okHandler, ButtonOption buttonOption); @Deprecated OkCancelDialog(String caption, Component content, Handler okHandler, ButtonOption buttonOption); @SuppressFBWarnings(value = "RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE", justification = "yeah, we know...") @Override void setContent(@CheckForNull Component content); void setSize(String width, String height); MessageList validate(); ValidationService getValidationService(); void setValidationService(ValidationService validationService); void setBeforeOkHandler(Handler beforeOkHandler); OkCancelDialog open(); void addContent(Component c); void addContent(Component c, float expandRatio); boolean isOkPressed(); ValidationDisplayState getValidationDisplayState(); boolean isCancelPressed(); String getOkCaption(); void setOkCaption(String okCaption); String getCancelCaption(); void setCancelCaption(String cancelCaption); static Builder builder(String caption); }### Answer:
@Test public void testOk() { Handler okHandler = mock(Handler.class); Handler cancelHandler = mock(Handler.class); OkCancelDialog dialog = OkCancelDialog.builder("") .okHandler(okHandler) .cancelHandler(cancelHandler) .build(); dialog.open(); assertThat(UI.getCurrent().getWindows(), hasSize(1)); DialogTestUtil.clickOkButton(dialog); verify(okHandler).apply(); verify(cancelHandler, never()).apply(); assertThat(UI.getCurrent().getWindows(), hasSize(0)); } |
### Question:
DateFormats { public static void register(String languageCode, String pattern) { LANGUAGE_PATTERNS.put(languageCode, pattern); } private DateFormats(); static void register(String languageCode, String pattern); static String getPattern(Locale locale); static final String PATTERN_ISO; static final String PATTERN_DE; }### Answer:
@Test public void testRegister() { String customPattern = "yyMMdd"; DateFormats.register("foobar", customPattern); assertThat(DateFormats.getPattern(new Locale("foobar")), is(customPattern)); } |
### Question:
OkCancelDialog extends Window { public void setOkCaption(String okCaption) { okButton.setCaption(requireNonNull(okCaption, "okCaption must not be null")); } protected OkCancelDialog(String caption, Handler okHandler, Handler cancelHandler,
ButtonOption buttonOption, Component... contentComponents); @Deprecated OkCancelDialog(String caption); @Deprecated OkCancelDialog(String caption, Handler okHandler); @Deprecated OkCancelDialog(String caption, Handler okHandler, ButtonOption buttonOption); @Deprecated OkCancelDialog(String caption, Component content, Handler okHandler, ButtonOption buttonOption); @SuppressFBWarnings(value = "RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE", justification = "yeah, we know...") @Override void setContent(@CheckForNull Component content); void setSize(String width, String height); MessageList validate(); ValidationService getValidationService(); void setValidationService(ValidationService validationService); void setBeforeOkHandler(Handler beforeOkHandler); OkCancelDialog open(); void addContent(Component c); void addContent(Component c, float expandRatio); boolean isOkPressed(); ValidationDisplayState getValidationDisplayState(); boolean isCancelPressed(); String getOkCaption(); void setOkCaption(String okCaption); String getCancelCaption(); void setCancelCaption(String cancelCaption); static Builder builder(String caption); }### Answer:
@Test public void testSetOkCaption() { OkCancelDialog dialog = OkCancelDialog.builder("").build(); dialog.setOkCaption("confirm it"); assertThat(dialog.getOkCaption(), is("confirm it")); assertThat(DialogTestUtil.getButtons(dialog).get(0).getCaption(), is("confirm it")); } |
### Question:
OkCancelDialog extends Window { public void setCancelCaption(String cancelCaption) { if (cancelButton != null) { cancelButton.setCaption(requireNonNull(cancelCaption, "cancelCaption must not be null")); } else { throw new IllegalStateException("Dialog does not have a cancel button"); } } protected OkCancelDialog(String caption, Handler okHandler, Handler cancelHandler,
ButtonOption buttonOption, Component... contentComponents); @Deprecated OkCancelDialog(String caption); @Deprecated OkCancelDialog(String caption, Handler okHandler); @Deprecated OkCancelDialog(String caption, Handler okHandler, ButtonOption buttonOption); @Deprecated OkCancelDialog(String caption, Component content, Handler okHandler, ButtonOption buttonOption); @SuppressFBWarnings(value = "RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE", justification = "yeah, we know...") @Override void setContent(@CheckForNull Component content); void setSize(String width, String height); MessageList validate(); ValidationService getValidationService(); void setValidationService(ValidationService validationService); void setBeforeOkHandler(Handler beforeOkHandler); OkCancelDialog open(); void addContent(Component c); void addContent(Component c, float expandRatio); boolean isOkPressed(); ValidationDisplayState getValidationDisplayState(); boolean isCancelPressed(); String getOkCaption(); void setOkCaption(String okCaption); String getCancelCaption(); void setCancelCaption(String cancelCaption); static Builder builder(String caption); }### Answer:
@Test public void testSetCancelCaption() { OkCancelDialog dialog = OkCancelDialog.builder("").build(); dialog.setCancelCaption("cancel it"); assertThat(dialog.getCancelCaption(), is("cancel it")); assertThat(DialogTestUtil.getButtons(dialog).get(1).getCaption(), is("cancel it")); } |
### Question:
LazyInitializingMap { @CheckForNull public V getIfPresent(K key) { return internalMap.get(key); } LazyInitializingMap(Function<K, V> initializer); V get(K key); @CheckForNull V getIfPresent(K key); void clear(); @CheckForNull V remove(K key); }### Answer:
@Test public void testGetIfPresent() { LazyInitializingMap<String, Object> lazyInitializingMap = new LazyInitializingMap<>(initializer); Object value = lazyInitializingMap.getIfPresent("string"); assertNull(value); } |
### Question:
AbstractSection extends VerticalLayout { @Override public void setCaption(@CheckForNull String caption) { captionLabel.setValue(caption); captionLabel.setVisible(!StringUtils.isEmpty(caption)); updateHeader(); } AbstractSection(@CheckForNull String caption); AbstractSection(@CheckForNull String caption, boolean closeable); @Deprecated AbstractSection(@CheckForNull String caption, boolean closeable, Optional<Button> editButton); @Override void setCaption(@CheckForNull String caption); void addHeaderButton(Button button); void addHeaderComponent(Component component); boolean isOpen(); boolean isClosed(); void open(); void close(); }### Answer:
@Test public void testSetCaption() { TestSection section = new TestSection("CAP", false); HorizontalLayout header = section.getHeader(); Label captionLabel = (Label)header.getComponent(0); assertThat(header.isVisible(), is(true)); assertThat(captionLabel.isVisible(), is(true)); assertThat(captionLabel.getValue(), is("CAP")); section.setCaption("TION"); assertThat(header.isVisible(), is(true)); assertThat(captionLabel.isVisible(), is(true)); assertThat(captionLabel.getValue(), is("TION")); }
@Test public void testSetCaption_Null() { TestSection section = new TestSection("CAP", false); HorizontalLayout header = section.getHeader(); Label captionLabel = (Label)header.getComponent(0); assertThat(header.isVisible(), is(true)); assertThat(captionLabel.isVisible(), is(true)); assertThat(captionLabel.getValue(), is("CAP")); section.setCaption(null); assertThat(header.isVisible(), is(false)); assertThat(captionLabel.isVisible(), is(false)); }
@Test public void testSetCaption_Empty() { TestSection section = new TestSection("CAP", false); HorizontalLayout header = section.getHeader(); Label captionLabel = (Label)header.getComponent(0); assertThat(header.isVisible(), is(true)); assertThat(captionLabel.isVisible(), is(true)); assertThat(captionLabel.getValue(), is("CAP")); section.setCaption(""); assertThat(header.isVisible(), is(false)); assertThat(captionLabel.isVisible(), is(false)); } |
### Question:
LazyInitializingMap { public V get(K key) { @CheckForNull V value = internalMap.computeIfAbsent(key, initializer); if (value == null) { throw new NullPointerException("Initializer must not create a null value"); } return value; } LazyInitializingMap(Function<K, V> initializer); V get(K key); @CheckForNull V getIfPresent(K key); void clear(); @CheckForNull V remove(K key); }### Answer:
@Test public void testGet_null() { LazyInitializingMap<String, Object> lazyInitializingMap = new LazyInitializingMap<>(initializer); Assertions.assertThrows(NullPointerException.class, () -> { lazyInitializingMap.get(null); }); }
@Test public void testGet_initializerFunctionReturnsNull() { LazyInitializingMap<String, Object> lazyInitializingMap = new LazyInitializingMap<>( (String key) -> null); Assertions.assertThrows(NullPointerException.class, () -> { lazyInitializingMap.get("string"); }); }
@Test public void testGet() { LazyInitializingMap<String, Object> lazyInitializingMap = new LazyInitializingMap<>(initializer); assertNull(lazyInitializingMap.getIfPresent("string")); lazyInitializingMap.get("string"); assertNotNull(lazyInitializingMap.getIfPresent("string")); }
@Test public void testGet2() { LazyInitializingMap<String, Object> lazyInitializingMap = new LazyInitializingMap<>(initializer); Object value = lazyInitializingMap.get("string"); assertEquals("stringx", value); Object value2 = lazyInitializingMap.get("string"); assertSame(value, value2); } |
### Question:
TabSheetArea extends TabSheet implements Area { @Override public void reloadBindings() { Component selectedTab = getSelectedTab(); if (selectedTab != null && selectedTab instanceof Page) { ((Page)selectedTab).reloadBindings(); } } TabSheetArea(); TabSheetArea(boolean preserveHeader); @PostConstruct final void init(); @Deprecated TabSheet getTabSheet(); @Override void reloadBindings(); }### Answer:
@Test public void testAddTab_RefreshesFirstTabPage() { TabSheetArea tabSheetArea = new TestArea(); Page tabPage1 = mock(Page.class); Page tabPage2 = mock(Page.class); verify(tabPage1, times(0)).reloadBindings(); verify(tabPage2, times(0)).reloadBindings(); tabSheetArea.addTab(tabPage1, "1"); tabSheetArea.addTab(tabPage2, "2"); verify(tabPage1, times(1)).reloadBindings(); verify(tabPage2, times(0)).reloadBindings(); }
@Test public void testTabSelectionRefreshesPage() { TabSheetArea tabSheetArea = new TestArea(); Page tabPage1 = mock(Page.class); Page tabPage2 = mock(Page.class); tabSheetArea.addTab(tabPage1, "1"); tabSheetArea.addTab(tabPage2, "2"); verify(tabPage2, times(0)).reloadBindings(); tabSheetArea.setSelectedTab(1); verify(tabPage2, times(1)).reloadBindings(); } |
### Question:
TabSheetArea extends TabSheet implements Area { protected List<Page> getTabs() { return StreamUtil.stream(this) .filter(c -> c instanceof Page) .map(c -> (Page)c) .collect(Collectors.toList()); } TabSheetArea(); TabSheetArea(boolean preserveHeader); @PostConstruct final void init(); @Deprecated TabSheet getTabSheet(); @Override void reloadBindings(); }### Answer:
@Test public void testGetTabs() { Page tabPage1 = mock(Page.class); Page tabPage2 = mock(Page.class); TabSheetArea tabSheetArea = new TestArea(); assertThat(tabSheetArea.getTabs(), is(empty())); tabSheetArea.addTab(tabPage1, "1"); tabSheetArea.addTab(tabPage2, "2"); assertThat(tabSheetArea.getTabs(), contains(tabPage1, tabPage2)); } |
### Question:
LinkkiConverterRegistry implements Serializable { @SuppressWarnings("unchecked") public <P, M> Converter<P, M> findConverter(Type presentationType, Type modelType) { Class<?> rawPresentationType = getRawType(presentationType); Class<?> rawModelType = getRawType(modelType); if (isIdentityNecessary(rawPresentationType, rawModelType)) { return (Converter<P, M>)Converter.identity(); } else { return converters.computeIfAbsent(rawPresentationType, t -> Sequence.empty()) .stream() .map(Converter.class::cast) .filter(c -> TypeUtils.equals(getPresentationType(c), rawPresentationType) && TypeUtils.equals(rawModelType, getModelType(c))) .findFirst() .orElseThrow(() -> new IllegalArgumentException( "Cannot convert presentation type " + rawPresentationType + " to model type " + rawModelType)); } } @SafeVarargs LinkkiConverterRegistry(Converter<?, ?>... customConverters); LinkkiConverterRegistry(Collection<Converter<?, ?>> customConverters); LinkkiConverterRegistry(Sequence<Converter<?, ?>> customConverters); @SuppressWarnings("unchecked") Converter<P, M> findConverter(Type presentationType, Type modelType); LinkkiConverterRegistry with(Converter<?, ?> converter); static LinkkiConverterRegistry getCurrent(); static final LinkkiConverterRegistry DEFAULT; }### Answer:
@Test public void testFindConverter_Default() { LinkkiConverterRegistry linkkiConverterRegistry = new LinkkiConverterRegistry(); assertThat(linkkiConverterRegistry.findConverter(String.class, Date.class), is(instanceOf(StringToDateConverter.class))); }
@Test public void testFindConverter_NotFound() { Assertions.assertThrows(IllegalArgumentException.class, () -> { new LinkkiConverterRegistry().findConverter(String.class, java.time.LocalDate.class); }); }
@Test public void testFindConverter_overrideDefault() { LinkkiConverterRegistry linkkiConverterRegistry = new LinkkiConverterRegistry(new MyStringToDateConverter()); assertThat(linkkiConverterRegistry.findConverter(String.class, Date.class), is(instanceOf(MyStringToDateConverter.class))); } |
### Question:
FormattedDoubleToStringConverter extends FormattedNumberToStringConverter<Double> { @Override protected Double convertToModel(Number value) { return value.doubleValue(); } FormattedDoubleToStringConverter(String format); }### Answer:
@Test public void testConvertToModel() { FormattedDoubleToStringConverter converter = new FormattedDoubleToStringConverter("0.00"); ValueContext context = new ValueContext(Locale.GERMAN); assertThat(converter.convertToModel("1,23", context).getOrThrow(s -> new AssertionError(s)), is(1.23)); }
@Test public void testConvertToModel_Null() { FormattedDoubleToStringConverter converter = new FormattedDoubleToStringConverter("0.00"); ValueContext context = new ValueContext(Locale.GERMAN); assertThat(converter.convertToModel("", context).getOrThrow(s -> new AssertionError(s)), is(nullValue())); } |
### Question:
TwoDigitYearLocalDateConverter implements Converter<LocalDate, LocalDate> { @CheckForNull @Override public Result<LocalDate> convertToModel(@CheckForNull LocalDate value, ValueContext context) { if (value == null) { return Result.ok(null); } else { return Result.ok(TwoDigitYearUtil.convert(value)); } } @CheckForNull @Override Result<LocalDate> convertToModel(@CheckForNull LocalDate value, ValueContext context); @Override LocalDate convertToPresentation(LocalDate value, ValueContext context); }### Answer:
@Test public void testConvertToModel_FourDigitYear_NoConversion() { assertThat((converter.convertToModel(LocalDate.of(2039, 12, 31), context)) .getOrThrow(s -> new AssertionError(s)), is(LocalDate.of(2039, 12, 31))); }
@Test public void testConvertToModel_NullValue() { assertNull((converter.convertToModel(null, context)) .getOrThrow(s -> new AssertionError(s))); }
@Test public void testConvertToModel_MaxTwoDigitYear() { LocalDate date = LocalDate.of(39, 12, 31); assertThat((converter.convertToModel(date, context)) .getOrThrow(s -> new AssertionError(s)), is(TwoDigitYearUtil.convert(date))); } |
### Question:
TwoDigitYearLocalDateConverter implements Converter<LocalDate, LocalDate> { @Override public LocalDate convertToPresentation(LocalDate value, ValueContext context) { return value; } @CheckForNull @Override Result<LocalDate> convertToModel(@CheckForNull LocalDate value, ValueContext context); @Override LocalDate convertToPresentation(LocalDate value, ValueContext context); }### Answer:
@Test public void testConvertToPresentation_FourDigitYear_NoConversion() { assertThat((converter.convertToPresentation(LocalDate.of(2011, 9, 5), context)), is(LocalDate.of(2011, 9, 5))); }
@Test public void testConvertToPresentation_NullValue() { assertNull(converter.convertToPresentation(null, context)); }
@Test public void testConvertToPresentation_ThreeDigitYear_NoConversion() { assertThat((converter.convertToPresentation(LocalDate.of(312, 5, 1), context)), is(LocalDate.of(312, 5, 1))); }
@Test public void testConvertToPresentation_TwoDigitYear_NoConversion() { assertThat((converter.convertToPresentation(LocalDate.of(10, 3, 21), context)), is(LocalDate.of(10, 3, 21))); } |
### Question:
FormattedIntegerToStringConverter extends FormattedNumberToStringConverter<Integer> { @Override protected Integer convertToModel(Number value) { return value.intValue(); } FormattedIntegerToStringConverter(String format); }### Answer:
@Test public void testConvertToModel() { FormattedIntegerToStringConverter converter = new FormattedIntegerToStringConverter("#,##0"); ValueContext context = new ValueContext(Locale.GERMAN); assertThat(converter.convertToModel("1.234", context).getOrThrow(s -> new AssertionError(s)), is(1234)); }
@Test public void testConvertToModel_Null() { FormattedIntegerToStringConverter converter = new FormattedIntegerToStringConverter("#,##0"); ValueContext context = new ValueContext(Locale.GERMAN); assertThat(converter.convertToModel("", context).getOrThrow(s -> new AssertionError(s)), is(nullValue())); } |
### Question:
CaptionAspectDefinition extends ModelToUiAspectDefinition<String> { @Override public Consumer<String> createComponentValueSetter(ComponentWrapper componentWrapper) { return caption -> ((Component)componentWrapper.getComponent()).setCaption(caption); } CaptionAspectDefinition(CaptionType captionType, String staticCaption); @Override Aspect<String> createAspect(); @Override Consumer<String> createComponentValueSetter(ComponentWrapper componentWrapper); @Override boolean supports(WrapperType type); static final String NAME; }### Answer:
@Test public void testCreateComponentValueSetter() { CaptionAspectDefinition captionAspectDefinition = new CaptionAspectDefinition(CaptionType.DYNAMIC, "foo"); Component component = new Label(); ComponentWrapper componentWrapper = new LabelComponentWrapper(component); Consumer<String> componentValueSetter = captionAspectDefinition.createComponentValueSetter(componentWrapper); componentValueSetter.accept("bar"); assertThat(component.getCaption(), is("bar")); } |
### Question:
CaptionAspectDefinition extends ModelToUiAspectDefinition<String> { @Override public boolean supports(WrapperType type) { return super.supports(type) && !ColumnBasedComponentWrapper.COLUMN_BASED_TYPE.isAssignableFrom(type); } CaptionAspectDefinition(CaptionType captionType, String staticCaption); @Override Aspect<String> createAspect(); @Override Consumer<String> createComponentValueSetter(ComponentWrapper componentWrapper); @Override boolean supports(WrapperType type); static final String NAME; }### Answer:
@Test public void testCreateComponentValueSetter_NOPonTable() { CaptionAspectDefinition captionAspectDefinition = new CaptionAspectDefinition(CaptionType.DYNAMIC, "foo"); @SuppressWarnings("deprecation") com.vaadin.v7.ui.Table table = new com.vaadin.v7.ui.Table(); ComponentWrapper componentWrapper = new TableComponentWrapper<String>("4711", table); boolean supported = captionAspectDefinition.supports(componentWrapper.getType()); assertThat(supported, is(false)); } |
### Question:
AvailableValuesAspectDefinition implements LinkkiAspectDefinition { protected AvailableValuesType getAvailableValuesType() { return availableValuesType; } AvailableValuesAspectDefinition(AvailableValuesType availableValuesType,
BiConsumer<C, ListDataProvider<Object>> dataProviderSetter); @Override Handler createUiUpdater(PropertyDispatcher propertyDispatcher, ComponentWrapper componentWrapper); Aspect<Collection<?>> createAspect(String propertyName, Class<?> valueClass); static final String NAME; }### Answer:
@Test public void testGetAvailableValuesType() { for (AvailableValuesType type : AvailableValuesType.values()) { assertThat(new AvailableValuesAspectDefinition<>(type, NOP).getAvailableValuesType(), is(type)); } } |
### Question:
AvailableValuesAspectDefinition implements LinkkiAspectDefinition { protected <T extends Enum<T>> List<?> getValuesDerivedFromDatatype(String propertyName, Class<?> valueClass) { if (valueClass.isEnum()) { @SuppressWarnings("unchecked") Class<T> enumType = (Class<T>)valueClass; return AvailableValuesProvider.enumToValues(enumType, getAvailableValuesType() == AvailableValuesType.ENUM_VALUES_INCL_NULL); } if (valueClass == Boolean.TYPE) { return AvailableValuesProvider.booleanPrimitiveToValues(); } if (valueClass == Boolean.class) { return AvailableValuesProvider.booleanWrapperToValues(); } else { throw new IllegalStateException( "Cannot retrieve list of available values for " + valueClass.getName() + "#" + propertyName); } } AvailableValuesAspectDefinition(AvailableValuesType availableValuesType,
BiConsumer<C, ListDataProvider<Object>> dataProviderSetter); @Override Handler createUiUpdater(PropertyDispatcher propertyDispatcher, ComponentWrapper componentWrapper); Aspect<Collection<?>> createAspect(String propertyName, Class<?> valueClass); static final String NAME; }### Answer:
@Test public void testGetValuesDerivedFromDatatype_NonEnumDatatype() { Assertions.assertThrows(IllegalStateException.class, () -> { new AvailableValuesAspectDefinition<>(AvailableValuesType.DYNAMIC, NOP) .getValuesDerivedFromDatatype("foo", String.class); }); }
@Test public void testGetValuesDerivedFromDatatype() { AvailableValuesAspectDefinition<HasItems<?>> availableValuesAspectDefinition = new AvailableValuesAspectDefinition<>( AvailableValuesType.DYNAMIC, NOP); assertThat(availableValuesAspectDefinition.getValuesDerivedFromDatatype("foo", TestEnum.class), contains(TestEnum.ONE, TestEnum.TWO, TestEnum.THREE)); assertThat(availableValuesAspectDefinition.getValuesDerivedFromDatatype("foo", Boolean.class), contains(null, true, false)); assertThat(availableValuesAspectDefinition.getValuesDerivedFromDatatype("foo", boolean.class), contains(true, false)); } |
### Question:
DateFormatRegistry { @Deprecated public String getPattern(Locale locale) { requireNonNull(locale, "locale must not be null"); String registeredPattern = languagePatterns.get(locale.getLanguage()); if (registeredPattern != null) { return registeredPattern; } else { return defaultLocalePattern(locale); } } @Deprecated String getPattern(Locale locale); @Deprecated
static final String PATTERN_ISO; @Deprecated
static final String PATTERN_DE; }### Answer:
@SuppressWarnings("deprecation") @Test public void testGetPattern() { DateFormatRegistry registry = new DateFormatRegistry(); assertThat(registry.getPattern(GERMAN), is(DateFormatRegistry.PATTERN_DE)); assertThat(registry.getPattern(GERMANY), is(DateFormatRegistry.PATTERN_DE)); assertThat(registry.getPattern(AUSTRIA), is(DateFormatRegistry.PATTERN_DE)); assertThat(registry.getPattern(ENGLISH), is(not(nullValue()))); assertThat(registry.getPattern(ENGLISH), is(not(DateFormatRegistry.PATTERN_DE))); assertThat(registry.getPattern(ENGLISH), is(not(DateFormatRegistry.PATTERN_ISO))); assertThat(registry.getPattern(US), is(not(nullValue()))); assertThat(registry.getPattern(US), is(not(DateFormatRegistry.PATTERN_DE))); assertThat(registry.getPattern(US), is(not(DateFormatRegistry.PATTERN_ISO))); } |
### Question:
AvailableValuesAspectDefinition implements LinkkiAspectDefinition { @SuppressWarnings("unchecked") protected void setDataProvider(ComponentWrapper componentWrapper, ListDataProvider<Object> dataProvider) { dataProviderSetter.accept((C)componentWrapper.getComponent(), dataProvider); } AvailableValuesAspectDefinition(AvailableValuesType availableValuesType,
BiConsumer<C, ListDataProvider<Object>> dataProviderSetter); @Override Handler createUiUpdater(PropertyDispatcher propertyDispatcher, ComponentWrapper componentWrapper); Aspect<Collection<?>> createAspect(String propertyName, Class<?> valueClass); static final String NAME; }### Answer:
@Test public void testSetDataProvider() { @SuppressWarnings("unchecked") BiConsumer<HasItems<?>, ListDataProvider<Object>> dataProviderSetter = mock(BiConsumer.class); AvailableValuesAspectDefinition<HasItems<?>> availableValuesAspectDefinition = new AvailableValuesAspectDefinition<>( AvailableValuesType.DYNAMIC, dataProviderSetter); @SuppressWarnings("unchecked") ListDataProvider<Object> dataProvider = mock(ListDataProvider.class); ComboBox<Object> component = new ComboBox<>(); availableValuesAspectDefinition.setDataProvider(new LabelComponentWrapper(component), dataProvider); verify(dataProviderSetter).accept(component, dataProvider); } |
### Question:
AvailableValuesAspectDefinition implements LinkkiAspectDefinition { protected void handleNullItems(ComponentWrapper componentWrapper, List<?> items) { } AvailableValuesAspectDefinition(AvailableValuesType availableValuesType,
BiConsumer<C, ListDataProvider<Object>> dataProviderSetter); @Override Handler createUiUpdater(PropertyDispatcher propertyDispatcher, ComponentWrapper componentWrapper); Aspect<Collection<?>> createAspect(String propertyName, Class<?> valueClass); static final String NAME; }### Answer:
@Test public void testHandleNullItems() { AvailableValuesAspectDefinition<HasItems<?>> availableValuesAspectDefinition = new AvailableValuesAspectDefinition<>( AvailableValuesType.DYNAMIC, NOP); @SuppressWarnings("unchecked") List<Object> items = mock(List.class); @SuppressWarnings("unchecked") ComboBox<Object> component = mock(ComboBox.class); availableValuesAspectDefinition.handleNullItems(new LabelComponentWrapper(component), items); verifyNoMoreInteractions(component, items); } |
### Question:
TableCreator implements ColumnBasedComponentCreator { @SuppressWarnings("deprecation") @Override public ComponentWrapper createComponent(ContainerPmo<?> containerPmo) { com.vaadin.v7.ui.Table table = containerPmo.isHierarchical() ? new com.vaadin.v7.ui.TreeTable() : new com.vaadin.v7.ui.Table(); table.addStyleName(LinkkiTheme.TABLE); table.setHeightUndefined(); table.setWidth("100%"); table.setSortEnabled(false); return new TableComponentWrapper<>(containerPmo.getClass().getSimpleName(), table); } @SuppressWarnings("deprecation") @Override ComponentWrapper createComponent(ContainerPmo<?> containerPmo); @SuppressWarnings("deprecation") @Override void initColumn(ContainerPmo<?> containerPmo,
ComponentWrapper tableWrapper,
BindingContext bindingContext,
PropertyElementDescriptors elementDesc); }### Answer:
@Test public void testCreateComponent_PmoClassIsUsedAsId() { TableCreator creator = new TableCreator(); com.vaadin.v7.ui.Table table = (com.vaadin.v7.ui.Table)creator.createComponent(new TestTablePmo()) .getComponent(); assertThat(table.getId(), is("TestTablePmo")); } |
### Question:
LinkkiInMemoryContainer extends com.vaadin.v7.data.util.AbstractInMemoryContainer<T, Object, com.vaadin.v7.data.Item> implements com.vaadin.v7.data.Container.Hierarchical { @Override @SuppressWarnings({ "unchecked" }) public Collection<T> getChildren(Object itemId) { List<T> newChildren = children.computeIfAbsent((T)itemId, this::getChildrenTypesafe); newChildren.forEach(c -> { if (!containsId(c)) { getAllItemIds().add(c); } }); return newChildren; } @Override Collection<?> getContainerPropertyIds(); void setItems(Collection<? extends T> items); @Deprecated @Override boolean removeAllItems(); @Deprecated void addAllItems(Collection<T> items); @Override com.vaadin.v7.data.Property<T> getContainerProperty(@CheckForNull Object itemId,
@CheckForNull Object propertyId); @Override @CheckForNull Class<?> getType(@CheckForNull Object propertyId); @Override @SuppressWarnings({ "unchecked" }) Collection<T> getChildren(Object itemId); Collection<T> getExistingChildren(T parent); boolean removeExistingChildren(T item); @CheckForNull @Override T getParent(Object itemId); @Override Collection<?> rootItemIds(); @Override boolean areChildrenAllowed(Object itemId); @Override boolean isRoot(Object itemId); @Override boolean hasChildren(Object itemId); @Override boolean setParent(Object itemId, Object newParentId); @Override boolean setChildrenAllowed(Object itemId, boolean areChildrenAllowed); }### Answer:
@Test public void testGetChildren_ofItemNotContained() { LinkkiInMemoryContainer<TestItem> container = new LinkkiInMemoryContainer<>(); assertThat(container.getChildren(new TestItem(42)), is(empty())); } |
### Question:
LinkkiInMemoryContainer extends com.vaadin.v7.data.util.AbstractInMemoryContainer<T, Object, com.vaadin.v7.data.Item> implements com.vaadin.v7.data.Container.Hierarchical { @CheckForNull @Override public T getParent(Object itemId) { return parents.get(itemId); } @Override Collection<?> getContainerPropertyIds(); void setItems(Collection<? extends T> items); @Deprecated @Override boolean removeAllItems(); @Deprecated void addAllItems(Collection<T> items); @Override com.vaadin.v7.data.Property<T> getContainerProperty(@CheckForNull Object itemId,
@CheckForNull Object propertyId); @Override @CheckForNull Class<?> getType(@CheckForNull Object propertyId); @Override @SuppressWarnings({ "unchecked" }) Collection<T> getChildren(Object itemId); Collection<T> getExistingChildren(T parent); boolean removeExistingChildren(T item); @CheckForNull @Override T getParent(Object itemId); @Override Collection<?> rootItemIds(); @Override boolean areChildrenAllowed(Object itemId); @Override boolean isRoot(Object itemId); @Override boolean hasChildren(Object itemId); @Override boolean setParent(Object itemId, Object newParentId); @Override boolean setChildrenAllowed(Object itemId, boolean areChildrenAllowed); }### Answer:
@Test public void testGetParent_ofItemNotContained() { LinkkiInMemoryContainer<TestItem> container = new LinkkiInMemoryContainer<>(); assertThat(container.getParent(new TestItem(42)), is(nullValue())); } |
### Question:
LinkkiInMemoryContainer extends com.vaadin.v7.data.util.AbstractInMemoryContainer<T, Object, com.vaadin.v7.data.Item> implements com.vaadin.v7.data.Container.Hierarchical { @Override public boolean setParent(Object itemId, Object newParentId) throws UnsupportedOperationException { return false; } @Override Collection<?> getContainerPropertyIds(); void setItems(Collection<? extends T> items); @Deprecated @Override boolean removeAllItems(); @Deprecated void addAllItems(Collection<T> items); @Override com.vaadin.v7.data.Property<T> getContainerProperty(@CheckForNull Object itemId,
@CheckForNull Object propertyId); @Override @CheckForNull Class<?> getType(@CheckForNull Object propertyId); @Override @SuppressWarnings({ "unchecked" }) Collection<T> getChildren(Object itemId); Collection<T> getExistingChildren(T parent); boolean removeExistingChildren(T item); @CheckForNull @Override T getParent(Object itemId); @Override Collection<?> rootItemIds(); @Override boolean areChildrenAllowed(Object itemId); @Override boolean isRoot(Object itemId); @Override boolean hasChildren(Object itemId); @Override boolean setParent(Object itemId, Object newParentId); @Override boolean setChildrenAllowed(Object itemId, boolean areChildrenAllowed); }### Answer:
@Test public void testSetParent() { LinkkiInMemoryContainer<TestItem> container = new LinkkiInMemoryContainer<>(); HierarchicalTestItem testItem1 = new HierarchicalTestItem(23); HierarchicalTestItem testItem2 = new HierarchicalTestItem(42); assertThat(container.setParent(testItem1, testItem2), is(false)); } |
### Question:
LinkkiInMemoryContainer extends com.vaadin.v7.data.util.AbstractInMemoryContainer<T, Object, com.vaadin.v7.data.Item> implements com.vaadin.v7.data.Container.Hierarchical { @Override public boolean areChildrenAllowed(Object itemId) { return hasChildren(itemId); } @Override Collection<?> getContainerPropertyIds(); void setItems(Collection<? extends T> items); @Deprecated @Override boolean removeAllItems(); @Deprecated void addAllItems(Collection<T> items); @Override com.vaadin.v7.data.Property<T> getContainerProperty(@CheckForNull Object itemId,
@CheckForNull Object propertyId); @Override @CheckForNull Class<?> getType(@CheckForNull Object propertyId); @Override @SuppressWarnings({ "unchecked" }) Collection<T> getChildren(Object itemId); Collection<T> getExistingChildren(T parent); boolean removeExistingChildren(T item); @CheckForNull @Override T getParent(Object itemId); @Override Collection<?> rootItemIds(); @Override boolean areChildrenAllowed(Object itemId); @Override boolean isRoot(Object itemId); @Override boolean hasChildren(Object itemId); @Override boolean setParent(Object itemId, Object newParentId); @Override boolean setChildrenAllowed(Object itemId, boolean areChildrenAllowed); }### Answer:
@Test public void testAreChildrenAllowed_ofItemNotContained() { LinkkiInMemoryContainer<TestItem> container = new LinkkiInMemoryContainer<>(); assertThat(container.areChildrenAllowed(new TestItem(42)), is(false)); } |
### Question:
LinkkiInMemoryContainer extends com.vaadin.v7.data.util.AbstractInMemoryContainer<T, Object, com.vaadin.v7.data.Item> implements com.vaadin.v7.data.Container.Hierarchical { @Override public boolean setChildrenAllowed(Object itemId, boolean areChildrenAllowed) throws UnsupportedOperationException { return false; } @Override Collection<?> getContainerPropertyIds(); void setItems(Collection<? extends T> items); @Deprecated @Override boolean removeAllItems(); @Deprecated void addAllItems(Collection<T> items); @Override com.vaadin.v7.data.Property<T> getContainerProperty(@CheckForNull Object itemId,
@CheckForNull Object propertyId); @Override @CheckForNull Class<?> getType(@CheckForNull Object propertyId); @Override @SuppressWarnings({ "unchecked" }) Collection<T> getChildren(Object itemId); Collection<T> getExistingChildren(T parent); boolean removeExistingChildren(T item); @CheckForNull @Override T getParent(Object itemId); @Override Collection<?> rootItemIds(); @Override boolean areChildrenAllowed(Object itemId); @Override boolean isRoot(Object itemId); @Override boolean hasChildren(Object itemId); @Override boolean setParent(Object itemId, Object newParentId); @Override boolean setChildrenAllowed(Object itemId, boolean areChildrenAllowed); }### Answer:
@Test public void testSetChildrenAllowed() { LinkkiInMemoryContainer<TestItem> container = new LinkkiInMemoryContainer<>(); HierarchicalTestItem testItem = new HierarchicalTestItem(23); assertThat(container.setChildrenAllowed(testItem, true), is(false)); } |
### Question:
LinkkiInMemoryContainer extends com.vaadin.v7.data.util.AbstractInMemoryContainer<T, Object, com.vaadin.v7.data.Item> implements com.vaadin.v7.data.Container.Hierarchical { @Override public boolean isRoot(Object itemId) { return roots.contains(itemId); } @Override Collection<?> getContainerPropertyIds(); void setItems(Collection<? extends T> items); @Deprecated @Override boolean removeAllItems(); @Deprecated void addAllItems(Collection<T> items); @Override com.vaadin.v7.data.Property<T> getContainerProperty(@CheckForNull Object itemId,
@CheckForNull Object propertyId); @Override @CheckForNull Class<?> getType(@CheckForNull Object propertyId); @Override @SuppressWarnings({ "unchecked" }) Collection<T> getChildren(Object itemId); Collection<T> getExistingChildren(T parent); boolean removeExistingChildren(T item); @CheckForNull @Override T getParent(Object itemId); @Override Collection<?> rootItemIds(); @Override boolean areChildrenAllowed(Object itemId); @Override boolean isRoot(Object itemId); @Override boolean hasChildren(Object itemId); @Override boolean setParent(Object itemId, Object newParentId); @Override boolean setChildrenAllowed(Object itemId, boolean areChildrenAllowed); }### Answer:
@Test public void testIsRoot_ofItemNotContained() { LinkkiInMemoryContainer<TestItem> container = new LinkkiInMemoryContainer<>(); assertThat(container.isRoot(new TestItem(42)), is(false)); } |
### Question:
LinkkiInMemoryContainer extends com.vaadin.v7.data.util.AbstractInMemoryContainer<T, Object, com.vaadin.v7.data.Item> implements com.vaadin.v7.data.Container.Hierarchical { @Override public boolean hasChildren(Object itemId) { return getHierarchicalItem(itemId) .map(HierarchicalRowPmo::hasChildRows) .orElse(false); } @Override Collection<?> getContainerPropertyIds(); void setItems(Collection<? extends T> items); @Deprecated @Override boolean removeAllItems(); @Deprecated void addAllItems(Collection<T> items); @Override com.vaadin.v7.data.Property<T> getContainerProperty(@CheckForNull Object itemId,
@CheckForNull Object propertyId); @Override @CheckForNull Class<?> getType(@CheckForNull Object propertyId); @Override @SuppressWarnings({ "unchecked" }) Collection<T> getChildren(Object itemId); Collection<T> getExistingChildren(T parent); boolean removeExistingChildren(T item); @CheckForNull @Override T getParent(Object itemId); @Override Collection<?> rootItemIds(); @Override boolean areChildrenAllowed(Object itemId); @Override boolean isRoot(Object itemId); @Override boolean hasChildren(Object itemId); @Override boolean setParent(Object itemId, Object newParentId); @Override boolean setChildrenAllowed(Object itemId, boolean areChildrenAllowed); }### Answer:
@Test public void testHasChildren_ofItemNotContained() { LinkkiInMemoryContainer<TestItem> container = new LinkkiInMemoryContainer<>(); assertThat(container.hasChildren(new TestItem(42)), is(false)); } |
### Question:
PmoBasedSectionFactory { public AbstractSection createSection(Object pmo, BindingContext bindingContext) { return createAndBindSection(pmo, bindingContext); } AbstractSection createSection(Object pmo, BindingContext bindingContext); BaseSection createBaseSection(Object pmo, BindingContext bindingContext); TableSection createTableSection(ContainerPmo<T> pmo, BindingContext bindingContext); static AbstractSection createAndBindSection(Object pmo, BindingContext bindingContext); }### Answer:
@Test public void testCreateSectionHeader() { SCCPmoWithID containerPmo = new SCCPmoWithID(); PmoBasedSectionFactory factory = new PmoBasedSectionFactory(); AbstractSection tableSection = factory.createSection(containerPmo, bindingContext); HorizontalLayout header = (HorizontalLayout)tableSection.getComponent(0); assertThat(header.getComponent(2), instanceOf(Button.class)); assertThat(header.getComponent(2).getCaption(), is("header button")); } |
### Question:
SectionCreationContext { @Deprecated public BaseSection createSection() { return (BaseSection)PmoBasedSectionFactory.createAndBindSection(pmo, bindingContext); } @Deprecated SectionCreationContext(Object pmo, BindingContext bindingContext); @Deprecated BaseSection createSection(); }### Answer:
@Test public void testSetSectionId() { BaseSection section = createContext(new SCCPmoWithID()).createSection(); assertThat(section.getId(), is("test-ID")); }
@Test public void testSetSectionDefaultId() { BaseSection section = createContext(new SCCPmoWithoutID()).createSection(); assertThat(section.getId(), is("SCCPmoWithoutID")); }
@Test public void testSetComponentId() { BaseSection section = createContext(new SCCPmoWithID()).createSection(); assertThat(section.getComponentCount(), is(2)); assertThat(section.getComponent(0).isVisible(), is(false)); GridLayout gridLayout = TestUiUtil.getContentGrid((FormSection)section); @NonNull Component textField = gridLayout.getComponent(1, 0); assertThat(textField.getId(), is("testProperty")); }
@Test public void testSectionWithDefaultLayout_shouldCreateFormLayout() { BaseSection section = createContext(new SCCPmoWithoutID()).createSection(); assertThat(section, is(instanceOf(FormSection.class))); }
@Test public void testSectionWithHorizontalLayout_shouldCreateHorizontalSection() { BaseSection section = createContext(new SectionWithHorizontalLayout()).createSection(); assertThat(section, is(instanceOf(HorizontalSection.class))); }
@Test public void testSectionWithCustomLayout_shouldCreateCustomLayoutSection() { BaseSection section = createContext(new SectionWithCustomLayout()).createSection(); assertThat(section, is(instanceOf(CustomLayoutSection.class))); }
@Test public void testSectionWithoutAnnotation_usesDefaultValues() { BaseSection section = createContext(new SectionWithoutAnnotation()).createSection(); assertThat(section, is(instanceOf(FormSection.class))); assertThat(section.getId(), is(SectionWithoutAnnotation.class.getSimpleName())); assertThat(section.getCaption(), is(nullValue())); assertThat(((FormSection)section).getNumberOfColumns(), is(1)); } |
### Question:
VaadinUiCreator { public static Component createComponent(Object pmo, BindingContext bindingContext) { ComponentWrapper wrapper = UiCreator.createComponent(pmo, bindingContext); return (Component)wrapper.getComponent(); } private VaadinUiCreator(); static Component createComponent(Object pmo, BindingContext bindingContext); }### Answer:
@SuppressWarnings("deprecation") @Test public void testCreateComponent() { TestPmo pmo = new TestPmo(); BindingContext bindingContext = new BindingContext(); Component component = VaadinUiCreator.createComponent(pmo, bindingContext); assertThat(component, instanceOf(org.linkki.core.vaadin.component.section.FormSection.class)); assertThat(bindingContext.getBindings(), hasSize(1)); Binding binding = bindingContext.getBindings().iterator().next(); assertThat(binding.getBoundComponent(), is(component)); assertThat(binding, is(instanceOf(BindingContext.class))); Collection<Binding> elementBindings = ((BindingContext)binding).getBindings(); assertThat(elementBindings.size(), is(1)); assertThat(elementBindings.iterator().next().getBoundComponent(), is(instanceOf(TextField.class))); } |
### Question:
Vaadin8 implements UiFrameworkExtension { @Override public Locale getLocale() { UI ui = UI.getCurrent(); if (ui != null) { Locale locale = ui.getLocale(); if (locale != null) { return locale; } } return Locale.GERMAN; } @Override Locale getLocale(); @Override ComponentWrapperFactory getComponentWrapperFactory(); @Override Stream<?> getChildComponents(Object uiComponent); }### Answer:
@Test public void testGetUiLocale() { assertThat(UI.getCurrent(), is(nullValue())); assertThat(UiFramework.getLocale(), is(Locale.GERMAN)); UI ui = MockUi.mockUi(); when(ui.getLocale()).thenReturn(Locale.ITALIAN); assertThat(UiFramework.getLocale(), is(Locale.ITALIAN)); } |
### Question:
Vaadin8 implements UiFrameworkExtension { @Override public Stream<?> getChildComponents(Object uiComponent) { if (uiComponent instanceof HasComponents) { return StreamUtil.stream((HasComponents)uiComponent); } return Stream.empty(); } @Override Locale getLocale(); @Override ComponentWrapperFactory getComponentWrapperFactory(); @Override Stream<?> getChildComponents(Object uiComponent); }### Answer:
@Test public void testGetChildComponents() { Component component1 = new Label("first label"); Component component2 = new Label("second label"); HasComponents componentWithChildren = new VerticalLayout(component1, component2); Component[] arr = { component1, component2 }; assertThat(UiFramework.get().getChildComponents(componentWithChildren).toArray(), is(arr)); } |
### Question:
DateFieldBindingDefinition implements BindingDefinition { @Override public Component newComponent() { DateField dateField = ComponentFactory.newDateField(); if (StringUtils.isNotBlank(uiDateField.dateFormat())) { dateField.setDateFormat(uiDateField.dateFormat()); } else { Locale locale = UiFramework.getLocale(); dateField.setDateFormat(DateFormats.getPattern(locale)); } return dateField; } DateFieldBindingDefinition(UIDateField uiDateField); @Override Component newComponent(); @Override String label(); @Override EnabledType enabled(); @Override RequiredType required(); @Override VisibleType visible(); @Override String modelAttribute(); @Override String modelObject(); }### Answer:
@Test public void testNewComponent_DefaultDateFormatIsUsed() { assertThat(UiFramework.getLocale(), is(Locale.GERMAN)); DateFieldBindingDefinition adapter = new DateFieldBindingDefinition(defaultAnnotation()); Component component = adapter.newComponent(); assertThat(component, is(instanceOf(DateField.class))); DateField dateField = (DateField)component; assertThat(dateField.getDateFormat(), is(DateFormats.PATTERN_DE)); }
@Test public void testNewComponent_CustomDateFormatIsUsed() { DateFieldBindingDefinition adapter = new DateFieldBindingDefinition(customAnnotation()); Component component = adapter.newComponent(); assertThat(component, is(instanceOf(DateField.class))); DateField dateField = (DateField)component; assertThat(dateField.getDateFormat(), is(CUSTOM_DATE_FORMAT)); } |
### Question:
LabelComponentWrapper extends VaadinComponentWrapper { @Override public void postUpdate() { getLabelComponent().ifPresent(l -> { l.setEnabled(getComponent().isEnabled()); l.setVisible(getComponent().isVisible()); l.setDescription(getComponent().getDescription()); updateRequiredIndicator(l); }); } LabelComponentWrapper(Component component); LabelComponentWrapper(@CheckForNull Label label, Component component); @Override void postUpdate(); @Override void setLabel(String labelText); Optional<Label> getLabelComponent(); @Override String toString(); }### Answer:
@Test public void testPostUpdate_AddsRequiredIndicatorToLabelIfFieldIsRequired() { LabelComponentWrapper wrapper = new LabelComponentWrapper(label, field); field.setRequiredIndicatorVisible(true); wrapper.postUpdate(); assertThat(label.getStyleName(), containsString(LinkkiTheme.REQUIRED_LABEL_COMPONENT_WRAPPER)); }
@Test public void testPostUpdate_DoesNotAddRequiredIndicatorToLabelIfFieldIsNotRequired() { LabelComponentWrapper wrapper = new LabelComponentWrapper(label, field); field.setRequiredIndicatorVisible(false); wrapper.postUpdate(); assertThat(label.getStyleName(), not(containsString(LinkkiTheme.REQUIRED_LABEL_COMPONENT_WRAPPER))); }
@Test public void testPostUpdate_DoesNotAddRequiredIndicatorToLabelIfFieldIsReadOnly() { LabelComponentWrapper wrapper = new LabelComponentWrapper(label, field); field.setRequiredIndicatorVisible(true); field.setReadOnly(true); wrapper.postUpdate(); assertThat(label.getStyleName(), not(containsString(LinkkiTheme.REQUIRED_LABEL_COMPONENT_WRAPPER))); } |
### Question:
CaptionComponentWrapper extends VaadinComponentWrapper { @Override public void setLabel(String labelText) { getComponent().setCaption(StringUtils.isEmpty(labelText) ? null : labelText); } CaptionComponentWrapper(Component component, WrapperType wrapperType); CaptionComponentWrapper(String id, Component component, WrapperType wrapperType); @Override void setLabel(String labelText); @Override String toString(); }### Answer:
@Test public void testSetLabel() { Component component = mock(Component.class); CaptionComponentWrapper wrapper = new CaptionComponentWrapper("testID", component, WrapperType.FIELD); wrapper.setLabel("testLabel"); verify(component).setCaption("testLabel"); }
@Test public void testSetLabel_EmptyString() { Component component = new TextField(); CaptionComponentWrapper wrapper = new CaptionComponentWrapper("testID", component, WrapperType.FIELD); wrapper.setLabel(""); assertThat(component.getCaption(), is(nullValue())); } |
### Question:
FormattedDecimalFieldToStringConverter extends FormattedNumberToStringConverter<Decimal> { @Override protected Decimal convertToModel(Number value) { return Decimal.valueOf(value.doubleValue()); } FormattedDecimalFieldToStringConverter(String format); @Override Result<Decimal> convertToModel(@CheckForNull String value, ValueContext context); @Override String convertToPresentation(@CheckForNull Decimal value, ValueContext context); }### Answer:
@Test public void testConvertToModelWithoutSeparators() { assertThat(converter.convertToModel("17385,89", new ValueContext(Locale.GERMAN)) .getOrThrow(s -> new AssertionError(s)), is(Decimal.valueOf(17385.89))); }
@Test public void testConvertToModelWithNull() { assertThat(converter.convertToModel(null, new ValueContext()) .getOrThrow(s -> new AssertionError(s)), is(Decimal.NULL)); } |
### Question:
FormattedDecimalFieldToStringConverter extends FormattedNumberToStringConverter<Decimal> { @Override public String convertToPresentation(@CheckForNull Decimal value, ValueContext context) { if (value == null || value.isNull()) { return ""; } else { return super.convertToPresentation(value, context); } } FormattedDecimalFieldToStringConverter(String format); @Override Result<Decimal> convertToModel(@CheckForNull String value, ValueContext context); @Override String convertToPresentation(@CheckForNull Decimal value, ValueContext context); }### Answer:
@Test public void testConvertToPresentationWithNull() { assertThat(converter.convertToPresentation(null, new ValueContext()), is("")); } |
### Question:
IdAndNameCaptionProvider implements ItemCaptionProvider<Object> { @Override public String getCaption(Object o) { return getName(o) + " [" + getId(o) + "]"; } @Override String getCaption(Object o); }### Answer:
@Test public void testIdAndNameCaptionProvider_AnonymousClass() { ItemCaptionProvider<Object> provider = new IdAndNameCaptionProvider(); assertThat(provider.getCaption(TestEnum.VALUE1), is("name1 [id1]")); }
@Test public void testIdAndNameCaptionProvider_AllMethods() { ItemCaptionProvider<Object> provider = new IdAndNameCaptionProvider(); assertThat(provider.getCaption(AllMethodsEnum.VALUE), is("getName(Locale) [id]")); }
@Test public void testIdAndNameCaptionProvider_MissingGetIdMethod() { ItemCaptionProvider<Object> provider = new IdAndNameCaptionProvider(); Assertions.assertThrows(IllegalStateException.class, () -> { provider.getCaption(UnnamedEnum.VALUE); }); } |
### Question:
ApplicationLayout extends VerticalLayout implements ViewDisplay { @Override public void showView(View view) { if (view instanceof Component) { setMainArea((Component)view); } else { throw new IllegalArgumentException( "View is not a component: " + view); } } ApplicationLayout(ApplicationHeader header, @CheckForNull ApplicationFooter footer); @Override void showView(View view); }### Answer:
@Test public void testShowView() { setUpApplicationLayout(); assertThat(applicationLayout.getComponentCount(), is(3)); assertThat(applicationLayout.getComponent(1), is(instanceOf(EmptyView.class))); View view = mock(View.class, withSettings().extraInterfaces(Component.class)); applicationLayout.showView(view); assertThat(applicationLayout.getComponentCount(), is(3)); assertThat(applicationLayout.getComponent(1), is(view)); View view2 = mock(View.class, withSettings().extraInterfaces(Component.class)); applicationLayout.showView(view2); assertThat(applicationLayout.getComponentCount(), is(3)); assertThat(applicationLayout.getComponent(1), is(view2)); }
@Test public void testShowView_NoFooter() { applicationLayout = new ApplicationLayout(header, null); assertThat(applicationLayout.getComponentCount(), is(2)); assertThat(applicationLayout.getComponent(1), is(instanceOf(EmptyView.class))); View view = mock(View.class, withSettings().extraInterfaces(Component.class)); applicationLayout.showView(view); assertThat(applicationLayout.getComponentCount(), is(2)); assertThat(applicationLayout.getComponent(1), is(view)); View view2 = mock(View.class, withSettings().extraInterfaces(Component.class)); applicationLayout.showView(view2); assertThat(applicationLayout.getComponentCount(), is(2)); assertThat(applicationLayout.getComponent(1), is(view2)); } |
### Question:
LinkkiUi extends UI { @Override protected void init(VaadinRequest request) { requireNonNull(applicationConfig, "configure must be called before any other methods to set applicationConfig and applicationLayout"); setErrorHandler(createErrorHandler()); VaadinSession vaadinSession = VaadinSession.getCurrent(); if (vaadinSession != null) { vaadinSession.setConverterFactory(applicationConfig.getConverterFactory()); vaadinSession.setErrorHandler(getErrorHandler()); } Page.getCurrent().setTitle(getPageTitle()); setContent(applicationLayout); } @SuppressFBWarnings(value = "NP_NONNULL_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR", justification = "applicationConfig/Layout will be non-null once configure was called") protected LinkkiUi(); @SuppressFBWarnings(value = "NP_NONNULL_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR", justification = "applicationConfig/Layout will be non-null once configure was called") LinkkiUi(ApplicationConfig applicationConfig); @Override ApplicationNavigator getNavigator(); ApplicationConfig getApplicationConfig(); ApplicationLayout getApplicationLayout(); @SuppressFBWarnings(value = "RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE", justification = "when called from the constructor before configure") @Override void setContent(@CheckForNull Component content); static LinkkiUi getCurrent(); static ApplicationConfig getCurrentApplicationConfig(); static ApplicationNavigator getCurrentApplicationNavigator(); static ApplicationLayout getCurrentApplicationLayout(); }### Answer:
@Test public void testInit() { initUi(); assertThat(UI.getCurrent().getContent(), is(linkkiUi.getApplicationLayout())); } |
### Question:
SidebarSheet { protected void unselect() { getButton().removeStyleName(LinkkiApplicationTheme.SIDEBAR_SELECTED); getContent().setVisible(false); } @Deprecated SidebarSheet(Resource icon, Component content, String tooltip); SidebarSheet(Resource icon, String name, Component content); SidebarSheet(Resource icon, String name, Component content, UiUpdateObserver uiUpdateObserver); SidebarSheet(Resource icon, String name, Supplier<Component> contentSupplier); SidebarSheet(Resource icon, String name, Supplier<Component> contentSupplier,
@CheckForNull UiUpdateObserver uiUpdateObserver); Button getButton(); Component getContent(); String getName(); @Override String toString(); }### Answer:
@Test public void testUnselect_checkVisibilitySetToFalse() { HorizontalLayout content = new HorizontalLayout(); SidebarSheet sheet = createSideBarSheet(content); sheet.unselect(); assertThat(content.isVisible(), is(false)); } |
### Question:
SidebarSheet { protected void select() { getContent().setVisible(true); getButton().addStyleName(LinkkiApplicationTheme.SIDEBAR_SELECTED); uiUpdateObserver.ifPresent(UiUpdateObserver::uiUpdated); } @Deprecated SidebarSheet(Resource icon, Component content, String tooltip); SidebarSheet(Resource icon, String name, Component content); SidebarSheet(Resource icon, String name, Component content, UiUpdateObserver uiUpdateObserver); SidebarSheet(Resource icon, String name, Supplier<Component> contentSupplier); SidebarSheet(Resource icon, String name, Supplier<Component> contentSupplier,
@CheckForNull UiUpdateObserver uiUpdateObserver); Button getButton(); Component getContent(); String getName(); @Override String toString(); }### Answer:
@Test public void testSelect_checkVisibilitySetToTrue() { HorizontalLayout content = new HorizontalLayout(); SidebarSheet sheet = createSideBarSheet(content); sheet.select(); assertThat(content.isVisible(), is(true)); }
@Test public void testSelect_CheckObserver() { HorizontalLayout content = new HorizontalLayout(); SidebarSheet sidebarSheet = new SidebarSheet(FontAwesome.STAR_HALF_FULL, "Test SidebarSheet", content, () -> triggered = true); sidebarSheet.select(); assertThat(triggered, is(true)); } |
### Question:
SidebarSheet { @Override public String toString() { return name; } @Deprecated SidebarSheet(Resource icon, Component content, String tooltip); SidebarSheet(Resource icon, String name, Component content); SidebarSheet(Resource icon, String name, Component content, UiUpdateObserver uiUpdateObserver); SidebarSheet(Resource icon, String name, Supplier<Component> contentSupplier); SidebarSheet(Resource icon, String name, Supplier<Component> contentSupplier,
@CheckForNull UiUpdateObserver uiUpdateObserver); Button getButton(); Component getContent(); String getName(); @Override String toString(); }### Answer:
@Test public void testToString() { SidebarSheet sheet = new SidebarSheet(FontAwesome.ADJUST, "Foo", new TextField()); assertThat(sheet.toString(), is("Foo")); } |
### Question:
SidebarLayout extends CssLayout { public void select(SidebarSheet sheet) { if (!sidebarSheets.contains(sheet)) { throw new IllegalArgumentException("The sheet " + sheet + " is not part of this SidebarLayout"); } if (selected == sheet) { return; } Component content = sheet.getContent(); if (content.getParent() == null) { contentArea.addComponent(content); } else if (content.getParent() != contentArea) { throw new IllegalStateException("Content of the selected sidebar sheet already has a parent!"); } if (selected != null) { selected.unselect(); } this.selected = sheet; sheet.select(); } SidebarLayout(); void addSheets(Stream<SidebarSheet> sheets); void addSheets(Iterable<SidebarSheet> sheets); void addSheets(@NonNull SidebarSheet... sheets); void addSheet(SidebarSheet sheet); void select(SidebarSheet sheet); SidebarSheet getSelected(); List<SidebarSheet> getSidebarSheets(); }### Answer:
@Test public void testSelect_NotRegistered() { SidebarLayout sidebarLayout = new SidebarLayout(); SidebarSheet sheet1 = new SidebarSheet(ANY_ICON, ANY_STRING, createNewContent()); Assertions.assertThrows(IllegalArgumentException.class, () -> { sidebarLayout.select(sheet1); }); } |
### Question:
OkCancelDialog extends Window { @SuppressFBWarnings(value = "RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE", justification = "yeah, we know...") @Override public void setContent(@CheckForNull Component content) { if (mainArea == null) { super.setContent(content); } else { mainArea.removeAllComponents(); mainArea.addComponent(content); } } protected OkCancelDialog(String caption, Handler okHandler, Handler cancelHandler,
ButtonOption buttonOption, Component... contentComponents); @Deprecated OkCancelDialog(String caption); @Deprecated OkCancelDialog(String caption, Handler okHandler); @Deprecated OkCancelDialog(String caption, Handler okHandler, ButtonOption buttonOption); @Deprecated OkCancelDialog(String caption, Component content, Handler okHandler, ButtonOption buttonOption); @SuppressFBWarnings(value = "RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE", justification = "yeah, we know...") @Override void setContent(@CheckForNull Component content); void setSize(String width, String height); MessageList validate(); ValidationService getValidationService(); void setValidationService(ValidationService validationService); void setBeforeOkHandler(Handler beforeOkHandler); OkCancelDialog open(); void addContent(Component c); void addContent(Component c, float expandRatio); boolean isOkPressed(); ValidationDisplayState getValidationDisplayState(); boolean isCancelPressed(); static Builder builder(String caption); }### Answer:
@Test public void testSetContent() { OkCancelDialog dialog = OkCancelDialog.builder("").build(); assertThat(DialogTestUtil.getContents(dialog).size(), is(0)); dialog.setContent(new Label()); assertThat(DialogTestUtil.getContents(dialog), hasSize(1)); assertThat(dialog, is(showingEnabledOkButton())); } |
### Question:
OkCancelDialog extends Window { protected void ok() { okHandler.apply(); } protected OkCancelDialog(String caption, Handler okHandler, Handler cancelHandler,
ButtonOption buttonOption, Component... contentComponents); @Deprecated OkCancelDialog(String caption); @Deprecated OkCancelDialog(String caption, Handler okHandler); @Deprecated OkCancelDialog(String caption, Handler okHandler, ButtonOption buttonOption); @Deprecated OkCancelDialog(String caption, Component content, Handler okHandler, ButtonOption buttonOption); @SuppressFBWarnings(value = "RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE", justification = "yeah, we know...") @Override void setContent(@CheckForNull Component content); void setSize(String width, String height); MessageList validate(); ValidationService getValidationService(); void setValidationService(ValidationService validationService); void setBeforeOkHandler(Handler beforeOkHandler); OkCancelDialog open(); void addContent(Component c); void addContent(Component c, float expandRatio); boolean isOkPressed(); ValidationDisplayState getValidationDisplayState(); boolean isCancelPressed(); static Builder builder(String caption); }### Answer:
@Test public void testOk() { Handler okHandler = mock(Handler.class); Handler cancelHandler = mock(Handler.class); OkCancelDialog dialog = OkCancelDialog.builder("") .okHandler(okHandler) .cancelHandler(cancelHandler) .build(); dialog.open(); assertThat(UI.getCurrent().getWindows(), hasSize(1)); DialogTestUtil.clickOkButton(dialog); verify(okHandler).apply(); verify(cancelHandler, never()).apply(); assertThat(UI.getCurrent().getWindows(), hasSize(0)); } |
### Question:
OkCancelDialog extends Window { public static Builder builder(String caption) { return new Builder(caption); } protected OkCancelDialog(String caption, Handler okHandler, Handler cancelHandler,
ButtonOption buttonOption, Component... contentComponents); @Deprecated OkCancelDialog(String caption); @Deprecated OkCancelDialog(String caption, Handler okHandler); @Deprecated OkCancelDialog(String caption, Handler okHandler, ButtonOption buttonOption); @Deprecated OkCancelDialog(String caption, Component content, Handler okHandler, ButtonOption buttonOption); @SuppressFBWarnings(value = "RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE", justification = "yeah, we know...") @Override void setContent(@CheckForNull Component content); void setSize(String width, String height); MessageList validate(); ValidationService getValidationService(); void setValidationService(ValidationService validationService); void setBeforeOkHandler(Handler beforeOkHandler); OkCancelDialog open(); void addContent(Component c); void addContent(Component c, float expandRatio); boolean isOkPressed(); ValidationDisplayState getValidationDisplayState(); boolean isCancelPressed(); static Builder builder(String caption); }### Answer:
@Test public void testContent() { Label content1 = new Label("1"); Label content2 = new Label("2"); OkCancelDialog dialog = OkCancelDialog.builder("caption") .content(content1, content2) .build(); assertThat(DialogTestUtil.getContents(dialog), contains(content1, content2)); }
@Test public void testButtonOption() { OkCancelDialog dialog = OkCancelDialog.builder("").buttonOption(ButtonOption.OK_ONLY).build(); assertThat(DialogTestUtil.getButtons(dialog), hasSize(1)); } |
### Question:
MetaAnnotation { public boolean isPresentOn(@CheckForNull Annotation annotation) { if (annotation != null) { return repeatable ? annotation.annotationType().getAnnotationsByType(metaAnnotationClass).length > 0 : annotation.annotationType().isAnnotationPresent(metaAnnotationClass); } else { return false; } } private MetaAnnotation(Class<META> metaAnnotationClass); static MetaAnnotation<META> of(Class<META> metaAnnotationClass); boolean isRepeatable(); boolean isPresentOnAnyAnnotationOn(AnnotatedElement annotatedElement); boolean isPresentOn(@CheckForNull Annotation annotation); Optional<META> findOn(Annotation annotation); Stream<META> findAllOn(Annotation annotation); Stream<Annotation> findAnnotatedAnnotationsOn(AnnotatedElement annotatedElement); BinaryOperator<A> onlyOneOn(AnnotatedElement annotatedElement); Supplier<? extends IllegalArgumentException> missingAnnotation(Annotation annotation,
AnnotatedElement annotatedElement,
String checkerMethod); }### Answer:
@Test public void testIsPresentOn() { assertThat(MetaAnnotation.of(MetaMarkerAnnotation.class).isPresentOn(annotatedAnnotation)); } |
### Question:
CaptionComponentWrapper implements ComponentWrapper { @Override public void setId(String id) { component.setId(id); } CaptionComponentWrapper(Component component, WrapperType wrapperType); CaptionComponentWrapper(String id, Component component, WrapperType wrapperType); @Override void setId(String id); @Override void setLabel(String labelText); @Override void setEnabled(boolean enabled); @Override void setVisible(boolean visible); @Override void setTooltip(String text); @Override Component getComponent(); @Override void setValidationMessages(MessageList messagesForProperty); @Override WrapperType getType(); @Override void registerBinding(Binding binding); @Override String toString(); }### Answer:
@Test public void testSetId() { Component component = mock(Component.class); CaptionComponentWrapper wrapper = new CaptionComponentWrapper("testID", component, WrapperType.FIELD); verify(component).setId("testID"); wrapper.setId("anotherId"); verify(component).setId("anotherId"); } |
### Question:
CaptionComponentWrapper implements ComponentWrapper { @Override public void setLabel(String labelText) { component.setCaption(labelText); } CaptionComponentWrapper(Component component, WrapperType wrapperType); CaptionComponentWrapper(String id, Component component, WrapperType wrapperType); @Override void setId(String id); @Override void setLabel(String labelText); @Override void setEnabled(boolean enabled); @Override void setVisible(boolean visible); @Override void setTooltip(String text); @Override Component getComponent(); @Override void setValidationMessages(MessageList messagesForProperty); @Override WrapperType getType(); @Override void registerBinding(Binding binding); @Override String toString(); }### Answer:
@Test public void testSetLabel() { Component component = mock(Component.class); CaptionComponentWrapper wrapper = new CaptionComponentWrapper("testID", component, WrapperType.FIELD); wrapper.setLabel("testLabel"); verify(component).setCaption("testLabel"); } |
### Question:
CaptionComponentWrapper implements ComponentWrapper { @Override public void setEnabled(boolean enabled) { component.setEnabled(enabled); } CaptionComponentWrapper(Component component, WrapperType wrapperType); CaptionComponentWrapper(String id, Component component, WrapperType wrapperType); @Override void setId(String id); @Override void setLabel(String labelText); @Override void setEnabled(boolean enabled); @Override void setVisible(boolean visible); @Override void setTooltip(String text); @Override Component getComponent(); @Override void setValidationMessages(MessageList messagesForProperty); @Override WrapperType getType(); @Override void registerBinding(Binding binding); @Override String toString(); }### Answer:
@Test public void testSetEnabled() { Component component = mock(Component.class); CaptionComponentWrapper wrapper = new CaptionComponentWrapper("testID", component, WrapperType.FIELD); wrapper.setEnabled(true); verify(component).setEnabled(true); wrapper.setEnabled(false); verify(component).setEnabled(false); } |
### Question:
CaptionComponentWrapper implements ComponentWrapper { @Override public void setVisible(boolean visible) { component.setVisible(visible); } CaptionComponentWrapper(Component component, WrapperType wrapperType); CaptionComponentWrapper(String id, Component component, WrapperType wrapperType); @Override void setId(String id); @Override void setLabel(String labelText); @Override void setEnabled(boolean enabled); @Override void setVisible(boolean visible); @Override void setTooltip(String text); @Override Component getComponent(); @Override void setValidationMessages(MessageList messagesForProperty); @Override WrapperType getType(); @Override void registerBinding(Binding binding); @Override String toString(); }### Answer:
@Test public void testSetVisible() { Component component = mock(Component.class); CaptionComponentWrapper wrapper = new CaptionComponentWrapper("testID", component, WrapperType.FIELD); wrapper.setVisible(true); verify(component).setVisible(true); wrapper.setVisible(false); verify(component).setVisible(false); } |
### Question:
CaptionComponentWrapper implements ComponentWrapper { @Override public void setTooltip(String text) { if (component instanceof AbstractComponent) { ((AbstractComponent)component).setDescription(text); } } CaptionComponentWrapper(Component component, WrapperType wrapperType); CaptionComponentWrapper(String id, Component component, WrapperType wrapperType); @Override void setId(String id); @Override void setLabel(String labelText); @Override void setEnabled(boolean enabled); @Override void setVisible(boolean visible); @Override void setTooltip(String text); @Override Component getComponent(); @Override void setValidationMessages(MessageList messagesForProperty); @Override WrapperType getType(); @Override void registerBinding(Binding binding); @Override String toString(); }### Answer:
@Test public void testSetTooltip() { AbstractComponent component = mock(AbstractComponent.class); CaptionComponentWrapper wrapper = new CaptionComponentWrapper("testID", component, WrapperType.FIELD); wrapper.setTooltip("testTip"); verify(component).setDescription("testTip"); } |
### Question:
CaptionComponentWrapper implements ComponentWrapper { @Override public Component getComponent() { return component; } CaptionComponentWrapper(Component component, WrapperType wrapperType); CaptionComponentWrapper(String id, Component component, WrapperType wrapperType); @Override void setId(String id); @Override void setLabel(String labelText); @Override void setEnabled(boolean enabled); @Override void setVisible(boolean visible); @Override void setTooltip(String text); @Override Component getComponent(); @Override void setValidationMessages(MessageList messagesForProperty); @Override WrapperType getType(); @Override void registerBinding(Binding binding); @Override String toString(); }### Answer:
@Test public void testGetComponent() { Component component = mock(Component.class); CaptionComponentWrapper wrapper = new CaptionComponentWrapper("testID", component, WrapperType.FIELD); assertThat(wrapper.getComponent(), is(sameInstance(component))); } |
### Question:
CaptionComponentWrapper implements ComponentWrapper { @Override public void setValidationMessages(MessageList messagesForProperty) { if (component instanceof AbstractComponent) { AbstractComponent field = (AbstractComponent)component; field.setComponentError(getErrorHandler(messagesForProperty)); } } CaptionComponentWrapper(Component component, WrapperType wrapperType); CaptionComponentWrapper(String id, Component component, WrapperType wrapperType); @Override void setId(String id); @Override void setLabel(String labelText); @Override void setEnabled(boolean enabled); @Override void setVisible(boolean visible); @Override void setTooltip(String text); @Override Component getComponent(); @Override void setValidationMessages(MessageList messagesForProperty); @Override WrapperType getType(); @Override void registerBinding(Binding binding); @Override String toString(); }### Answer:
@Test public void testSetValidationMessages() { AbstractComponent component = mock(AbstractComponent.class); CaptionComponentWrapper wrapper = new CaptionComponentWrapper("testID", component, WrapperType.FIELD); ArgumentCaptor<ErrorMessage> errorMessageCaptor = ArgumentCaptor.forClass(ErrorMessage.class); MessageList messages = new MessageList(Message.newError("e", "testError"), Message.newWarning("w", "testWarning")); wrapper.setValidationMessages(messages); verify(component).setComponentError(errorMessageCaptor.capture()); @NonNull ErrorMessage errorMessage = errorMessageCaptor.getValue(); assertThat(errorMessage.getErrorLevel(), is(ErrorLevel.ERROR)); assertThat(errorMessage.getFormattedHtmlMessage(), containsString("testError")); assertThat(errorMessage.getFormattedHtmlMessage(), containsString("testWarning")); }
@Test public void testSetValidationMessages_Empty() { AbstractComponent component = mock(AbstractComponent.class); CaptionComponentWrapper wrapper = new CaptionComponentWrapper("testID", component, WrapperType.FIELD); MessageList messages = new MessageList(); wrapper.setValidationMessages(messages); verify(component).setComponentError(null); } |
### Question:
CaptionComponentWrapper implements ComponentWrapper { @Override public WrapperType getType() { return wrapperType; } CaptionComponentWrapper(Component component, WrapperType wrapperType); CaptionComponentWrapper(String id, Component component, WrapperType wrapperType); @Override void setId(String id); @Override void setLabel(String labelText); @Override void setEnabled(boolean enabled); @Override void setVisible(boolean visible); @Override void setTooltip(String text); @Override Component getComponent(); @Override void setValidationMessages(MessageList messagesForProperty); @Override WrapperType getType(); @Override void registerBinding(Binding binding); @Override String toString(); }### Answer:
@Test public void testGetType() { Component component = mock(Component.class); assertThat(new CaptionComponentWrapper("testID", component, WrapperType.FIELD).getType(), is(WrapperType.FIELD)); assertThat(new CaptionComponentWrapper("testID", component, WrapperType.LAYOUT).getType(), is(WrapperType.LAYOUT)); } |
### Question:
MetaAnnotation { public Optional<META> findOn(Annotation annotation) { return repeatable ? findAllOn(annotation).reduce((a1, a2) -> { throw new IllegalArgumentException(annotation.annotationType() + " has multiple @" + metaAnnotationClass.getSimpleName() + " annotations. Please use " + MetaAnnotation.class.getSimpleName() + "#findAllOn(Annotation) for repeatable annotations."); }) : Optional.ofNullable(annotation.annotationType().getAnnotation(metaAnnotationClass)); } private MetaAnnotation(Class<META> metaAnnotationClass); static MetaAnnotation<META> of(Class<META> metaAnnotationClass); boolean isRepeatable(); boolean isPresentOnAnyAnnotationOn(AnnotatedElement annotatedElement); boolean isPresentOn(@CheckForNull Annotation annotation); Optional<META> findOn(Annotation annotation); Stream<META> findAllOn(Annotation annotation); Stream<Annotation> findAnnotatedAnnotationsOn(AnnotatedElement annotatedElement); BinaryOperator<A> onlyOneOn(AnnotatedElement annotatedElement); Supplier<? extends IllegalArgumentException> missingAnnotation(Annotation annotation,
AnnotatedElement annotatedElement,
String checkerMethod); }### Answer:
@Test public void testFindOn() { Optional<MetaMarkerAnnotation> metaMarkerAnnotation = MetaAnnotation.of(MetaMarkerAnnotation.class) .findOn(annotatedAnnotation); assertThat(metaMarkerAnnotation.isPresent()); assertThat(metaMarkerAnnotation.get().value(), is("foo")); } |
### Question:
JodaLocalDateToStringConverter implements Converter<String, LocalDate> { @CheckForNull @Override public LocalDate convertToModel(@CheckForNull String value, @CheckForNull Class<? extends LocalDate> targetType, @CheckForNull Locale locale) throws Converter.ConversionException { throw new UnsupportedOperationException(getClass().getName() + " only supports convertToPresentation"); } @CheckForNull @Override LocalDate convertToModel(@CheckForNull String value,
@CheckForNull Class<? extends LocalDate> targetType,
@CheckForNull Locale locale); @CheckForNull @Override String convertToPresentation(@CheckForNull LocalDate value,
@CheckForNull Class<? extends String> targetType,
@CheckForNull Locale locale); static DateTimeFormatter getFormat(Locale locale); @Override Class<LocalDate> getModelType(); @Override Class<String> getPresentationType(); }### Answer:
@Test public void testConvertToModel() { Assertions.assertThrows(UnsupportedOperationException.class, () -> { new JodaLocalDateToStringConverter().convertToModel(null, null, null); }); } |
### Question:
JodaLocalDateToStringConverter implements Converter<String, LocalDate> { @CheckForNull @Override public String convertToPresentation(@CheckForNull LocalDate value, @CheckForNull Class<? extends String> targetType, @CheckForNull Locale locale) throws Converter.ConversionException { if (value == null) { return ""; } return getFormat(getNullsafeLocale(locale)).print(value); } @CheckForNull @Override LocalDate convertToModel(@CheckForNull String value,
@CheckForNull Class<? extends LocalDate> targetType,
@CheckForNull Locale locale); @CheckForNull @Override String convertToPresentation(@CheckForNull LocalDate value,
@CheckForNull Class<? extends String> targetType,
@CheckForNull Locale locale); static DateTimeFormatter getFormat(Locale locale); @Override Class<LocalDate> getModelType(); @Override Class<String> getPresentationType(); }### Answer:
@Test public void testConvertToPresentation_null_shouldReturnEmptyString() { String presentation = new JodaLocalDateToStringConverter().convertToPresentation(null, String.class, null); assertNotNull(presentation); assertThat(presentation, is("")); }
@Test public void testConvertToPresentation() { LocalDate date = LocalDate.now(); String presentation = new JodaLocalDateToStringConverter().convertToPresentation(date, null, Locale.GERMANY); assertNotNull(presentation); assertThat(presentation, is(date.toString(DateFormats.PATTERN_DE))); } |
### Question:
JodaLocalDateTimeToStringConverter implements Converter<String, LocalDateTime> { @CheckForNull @Override public LocalDateTime convertToModel(@CheckForNull String value, @CheckForNull Class<? extends LocalDateTime> targetType, @CheckForNull Locale locale) throws ConversionException { throw new UnsupportedOperationException(getClass().getName() + " only supports convertToPresentation"); } @CheckForNull @Override LocalDateTime convertToModel(@CheckForNull String value,
@CheckForNull Class<? extends LocalDateTime> targetType,
@CheckForNull Locale locale); @CheckForNull @Override String convertToPresentation(@CheckForNull LocalDateTime value,
@CheckForNull Class<? extends String> targetType,
@CheckForNull Locale locale); @Override Class<LocalDateTime> getModelType(); @Override Class<String> getPresentationType(); }### Answer:
@Test public void testConvertToModel() { Assertions.assertThrows(UnsupportedOperationException.class, () -> { new JodaLocalDateTimeToStringConverter().convertToModel(null, null, null); }); } |
### Question:
MetaAnnotation { public Stream<META> findAllOn(Annotation annotation) { return Arrays.stream(annotation.annotationType().getAnnotationsByType(metaAnnotationClass)); } private MetaAnnotation(Class<META> metaAnnotationClass); static MetaAnnotation<META> of(Class<META> metaAnnotationClass); boolean isRepeatable(); boolean isPresentOnAnyAnnotationOn(AnnotatedElement annotatedElement); boolean isPresentOn(@CheckForNull Annotation annotation); Optional<META> findOn(Annotation annotation); Stream<META> findAllOn(Annotation annotation); Stream<Annotation> findAnnotatedAnnotationsOn(AnnotatedElement annotatedElement); BinaryOperator<A> onlyOneOn(AnnotatedElement annotatedElement); Supplier<? extends IllegalArgumentException> missingAnnotation(Annotation annotation,
AnnotatedElement annotatedElement,
String checkerMethod); }### Answer:
@Test public void testFindAllOn() { List<MetaMarkerAnnotation> metaMarkerAnnotation = MetaAnnotation.of(MetaMarkerAnnotation.class) .findAllOn(annotatedAnnotation).collect(Collectors.toList()); assertThat(metaMarkerAnnotation, hasSize(1)); assertThat(metaMarkerAnnotation.get(0).value(), is("foo")); } |
### Question:
TableCreator implements ColumnBasedComponentCreator { @Override public ComponentWrapper createComponent(ContainerPmo<?> containerPmo) { Table table = containerPmo.isHierarchical() ? new TreeTable() : new Table(); table.addStyleName(LinkkiTheme.TABLE); table.setHeightUndefined(); table.setWidth("100%"); table.setSortEnabled(false); return new TableComponentWrapper<>(containerPmo.getClass().getSimpleName(), table); } @Override ComponentWrapper createComponent(ContainerPmo<?> containerPmo); @Override void initColumn(ContainerPmo<?> containerPmo,
ComponentWrapper tableWrapper,
BindingContext bindingContext,
PropertyElementDescriptors elementDesc); }### Answer:
@Test public void testCreateComponent_PmoClassIsUsedAsId() { TableCreator creator = new TableCreator(); Table table = (Table)creator.createComponent(new TestTablePmo()).getComponent(); assertThat(table.getId(), is("TestTablePmo")); } |
### Question:
MetaAnnotation { public boolean isRepeatable() { return repeatable; } private MetaAnnotation(Class<META> metaAnnotationClass); static MetaAnnotation<META> of(Class<META> metaAnnotationClass); boolean isRepeatable(); boolean isPresentOnAnyAnnotationOn(AnnotatedElement annotatedElement); boolean isPresentOn(@CheckForNull Annotation annotation); Optional<META> findOn(Annotation annotation); Stream<META> findAllOn(Annotation annotation); Stream<Annotation> findAnnotatedAnnotationsOn(AnnotatedElement annotatedElement); BinaryOperator<A> onlyOneOn(AnnotatedElement annotatedElement); Supplier<? extends IllegalArgumentException> missingAnnotation(Annotation annotation,
AnnotatedElement annotatedElement,
String checkerMethod); }### Answer:
@Test public void testIsRepeatable() { assertThat(MetaAnnotation.of(MetaMarkerAnnotation.class).isRepeatable(), is(false)); assertThat(MetaAnnotation.of(RepeatableMetaMarkerAnnotation.class).isRepeatable()); } |
### Question:
SectionCreationContext { @Deprecated public BaseSection createSection() { return (BaseSection)sectionBuilder.createSection(); } @Deprecated SectionCreationContext(Object pmo, BindingContext bindingContext); @Deprecated BaseSection createSection(); }### Answer:
@Test public void testSetSectionId() { BaseSection section = createContext(new SCCPmoWithID()).createSection(); assertThat(section.getId(), is("test-ID")); }
@Test public void testSetSectionDefaultId() { BaseSection section = createContext(new SCCPmoWithoutID()).createSection(); assertThat(section.getId(), is("SCCPmoWithoutID")); }
@Test public void testSetComponentId() { BaseSection section = createContext(new SCCPmoWithID()).createSection(); assertThat(section.getComponentCount(), is(2)); @NonNull Panel panel = (Panel)section.getComponent(1); @NonNull GridLayout gridLayout = (GridLayout)panel.getContent(); @NonNull Component textField = gridLayout.getComponent(1, 0); assertThat(textField.getId(), is("testProperty")); }
@Test public void testSectionWithDefaultLayout_shouldCreateFormLayout() { BaseSection section = createContext(new SCCPmoWithoutID()).createSection(); assertThat(section, is(instanceOf(FormSection.class))); }
@Test public void testSectionWithHorizontalLayout_shouldCreateHorizontalSection() { BaseSection section = createContext(new SectionWithHorizontalLayout()).createSection(); assertThat(section, is(instanceOf(HorizontalSection.class))); }
@Test public void testSectionWithCustomLayout_shouldCreateCustomLayoutSection() { BaseSection section = createContext(new SectionWithCustomLayout()).createSection(); assertThat(section, is(instanceOf(CustomLayoutSection.class))); }
@Test public void testSectionWithoutAnnotation_usesDefaultValues() { BaseSection section = createContext(new SectionWithoutAnnotation()).createSection(); assertThat(section, is(instanceOf(FormSection.class))); assertThat(section.getId(), is(SectionWithoutAnnotation.class.getSimpleName())); assertThat(section.getCaption(), is(nullValue())); assertThat(((FormSection)section).getNumberOfColumns(), is(1)); } |
### Question:
TabSheetArea extends VerticalLayout implements Area { protected List<Page> getTabs() { return StreamUtil.stream(() -> tabSheet.iterator()) .filter(c -> c instanceof Page) .map(c -> (Page)c) .collect(Collectors.toList()); } TabSheetArea(); TabSheetArea(boolean preserveHeader); @PostConstruct final void init(); TabSheet getTabSheet(); @Override void reloadBindings(); }### Answer:
@Test public void testGetTabs() { Page tabPage1 = mock(Page.class); Page tabPage2 = mock(Page.class); TabSheetArea tabSheetArea = new TestArea(); assertThat(tabSheetArea.getTabs(), is(empty())); tabSheetArea.addTab(tabPage1, "1"); tabSheetArea.addTab(tabPage2, "2"); assertThat(tabSheetArea.getTabs(), contains(tabPage1, tabPage2)); } |
### Question:
LinkkiInMemoryContainer extends AbstractInMemoryContainer<T, Object, Item> implements Container.Hierarchical { public void setItems(Collection<? extends T> items) { requireNonNull(items, "items must not be null"); getAllItemIds().clear(); getAllItemIds().addAll(items); fireItemSetChange(); } @Override Collection<?> getContainerPropertyIds(); void setItems(Collection<? extends T> items); @Deprecated @Override boolean removeAllItems(); @Deprecated void addAllItems(Collection<T> items); @Override @CheckForNull Property<T> getContainerProperty(@CheckForNull Object itemId, Object propertyId); @Override @CheckForNull Class<?> getType(@CheckForNull Object propertyId); @Override @SuppressWarnings({ "unchecked" }) Collection<T> getChildren(Object itemId); Collection<T> getExistingChildren(T parent); boolean removeExistingChildren(T item); @CheckForNull @Override T getParent(Object itemId); @Override Collection<?> rootItemIds(); @Override boolean areChildrenAllowed(Object itemId); @Override boolean isRoot(Object itemId); @Override boolean hasChildren(Object itemId); @Override boolean setParent(Object itemId, Object newParentId); @Override boolean setChildrenAllowed(Object itemId, boolean areChildrenAllowed); }### Answer:
@Test public void testBackupListShouldBeClearedOnRemoveAllItems() { LinkkiInMemoryContainer<TestItem> container = new LinkkiInMemoryContainer<>(); container.setItems(Collections.singletonList(new TestItem())); assertThat(container.getItemIds(), hasSize(1)); container.setItems(Collections.emptyList()); assertThat(container.getItemIds(), hasSize(0)); }
@Test public void testEqualsOfWrapperShouldOnlyCheckReference() { TestItem testItem = new TestItem(42); LinkkiInMemoryContainer<TestItem> container = new LinkkiInMemoryContainer<>(); container.setItems(Collections.singletonList(testItem)); TestItem equalItem = new TestItem(42); assertThat(testItem, is(equalItem)); assertThat(container.getItemIds().get(0), is(equalItem)); assertThat(container.getItemIds().get(0), is(testItem)); } |
### Question:
LinkkiInMemoryContainer extends AbstractInMemoryContainer<T, Object, Item> implements Container.Hierarchical { @Override @SuppressWarnings({ "unchecked" }) public Collection<T> getChildren(Object itemId) { return children.computeIfAbsent((T)itemId, this::getChildrenTypesafe); } @Override Collection<?> getContainerPropertyIds(); void setItems(Collection<? extends T> items); @Deprecated @Override boolean removeAllItems(); @Deprecated void addAllItems(Collection<T> items); @Override @CheckForNull Property<T> getContainerProperty(@CheckForNull Object itemId, Object propertyId); @Override @CheckForNull Class<?> getType(@CheckForNull Object propertyId); @Override @SuppressWarnings({ "unchecked" }) Collection<T> getChildren(Object itemId); Collection<T> getExistingChildren(T parent); boolean removeExistingChildren(T item); @CheckForNull @Override T getParent(Object itemId); @Override Collection<?> rootItemIds(); @Override boolean areChildrenAllowed(Object itemId); @Override boolean isRoot(Object itemId); @Override boolean hasChildren(Object itemId); @Override boolean setParent(Object itemId, Object newParentId); @Override boolean setChildrenAllowed(Object itemId, boolean areChildrenAllowed); }### Answer:
@Test public void testGetChildren_ofItemNotContained() { LinkkiInMemoryContainer<TestItem> container = new LinkkiInMemoryContainer<>(); assertThat(container.getChildren(new TestItem(42)), is(empty())); } |
### Question:
LinkkiInMemoryContainer extends AbstractInMemoryContainer<T, Object, Item> implements Container.Hierarchical { @CheckForNull @Override public T getParent(Object itemId) { return parents.get(itemId); } @Override Collection<?> getContainerPropertyIds(); void setItems(Collection<? extends T> items); @Deprecated @Override boolean removeAllItems(); @Deprecated void addAllItems(Collection<T> items); @Override @CheckForNull Property<T> getContainerProperty(@CheckForNull Object itemId, Object propertyId); @Override @CheckForNull Class<?> getType(@CheckForNull Object propertyId); @Override @SuppressWarnings({ "unchecked" }) Collection<T> getChildren(Object itemId); Collection<T> getExistingChildren(T parent); boolean removeExistingChildren(T item); @CheckForNull @Override T getParent(Object itemId); @Override Collection<?> rootItemIds(); @Override boolean areChildrenAllowed(Object itemId); @Override boolean isRoot(Object itemId); @Override boolean hasChildren(Object itemId); @Override boolean setParent(Object itemId, Object newParentId); @Override boolean setChildrenAllowed(Object itemId, boolean areChildrenAllowed); }### Answer:
@Test public void testGetParent_ofItemNotContained() { LinkkiInMemoryContainer<TestItem> container = new LinkkiInMemoryContainer<>(); assertThat(container.getParent(new TestItem(42)), is(nullValue())); } |
### Question:
LinkkiInMemoryContainer extends AbstractInMemoryContainer<T, Object, Item> implements Container.Hierarchical { @Override public boolean setParent(Object itemId, Object newParentId) throws UnsupportedOperationException { return false; } @Override Collection<?> getContainerPropertyIds(); void setItems(Collection<? extends T> items); @Deprecated @Override boolean removeAllItems(); @Deprecated void addAllItems(Collection<T> items); @Override @CheckForNull Property<T> getContainerProperty(@CheckForNull Object itemId, Object propertyId); @Override @CheckForNull Class<?> getType(@CheckForNull Object propertyId); @Override @SuppressWarnings({ "unchecked" }) Collection<T> getChildren(Object itemId); Collection<T> getExistingChildren(T parent); boolean removeExistingChildren(T item); @CheckForNull @Override T getParent(Object itemId); @Override Collection<?> rootItemIds(); @Override boolean areChildrenAllowed(Object itemId); @Override boolean isRoot(Object itemId); @Override boolean hasChildren(Object itemId); @Override boolean setParent(Object itemId, Object newParentId); @Override boolean setChildrenAllowed(Object itemId, boolean areChildrenAllowed); }### Answer:
@Test public void testSetParent() { LinkkiInMemoryContainer<TestItem> container = new LinkkiInMemoryContainer<>(); HierarchicalTestItem testItem1 = new HierarchicalTestItem(23); HierarchicalTestItem testItem2 = new HierarchicalTestItem(42); assertThat(container.setParent(testItem1, testItem2), is(false)); } |
### Question:
LinkkiInMemoryContainer extends AbstractInMemoryContainer<T, Object, Item> implements Container.Hierarchical { @Override public boolean areChildrenAllowed(Object itemId) { return hasChildren(itemId); } @Override Collection<?> getContainerPropertyIds(); void setItems(Collection<? extends T> items); @Deprecated @Override boolean removeAllItems(); @Deprecated void addAllItems(Collection<T> items); @Override @CheckForNull Property<T> getContainerProperty(@CheckForNull Object itemId, Object propertyId); @Override @CheckForNull Class<?> getType(@CheckForNull Object propertyId); @Override @SuppressWarnings({ "unchecked" }) Collection<T> getChildren(Object itemId); Collection<T> getExistingChildren(T parent); boolean removeExistingChildren(T item); @CheckForNull @Override T getParent(Object itemId); @Override Collection<?> rootItemIds(); @Override boolean areChildrenAllowed(Object itemId); @Override boolean isRoot(Object itemId); @Override boolean hasChildren(Object itemId); @Override boolean setParent(Object itemId, Object newParentId); @Override boolean setChildrenAllowed(Object itemId, boolean areChildrenAllowed); }### Answer:
@Test public void testAreChildrenAllowed_ofItemNotContained() { LinkkiInMemoryContainer<TestItem> container = new LinkkiInMemoryContainer<>(); assertThat(container.areChildrenAllowed(new TestItem(42)), is(false)); } |
### Question:
LinkkiInMemoryContainer extends AbstractInMemoryContainer<T, Object, Item> implements Container.Hierarchical { @Override public boolean setChildrenAllowed(Object itemId, boolean areChildrenAllowed) throws UnsupportedOperationException { return false; } @Override Collection<?> getContainerPropertyIds(); void setItems(Collection<? extends T> items); @Deprecated @Override boolean removeAllItems(); @Deprecated void addAllItems(Collection<T> items); @Override @CheckForNull Property<T> getContainerProperty(@CheckForNull Object itemId, Object propertyId); @Override @CheckForNull Class<?> getType(@CheckForNull Object propertyId); @Override @SuppressWarnings({ "unchecked" }) Collection<T> getChildren(Object itemId); Collection<T> getExistingChildren(T parent); boolean removeExistingChildren(T item); @CheckForNull @Override T getParent(Object itemId); @Override Collection<?> rootItemIds(); @Override boolean areChildrenAllowed(Object itemId); @Override boolean isRoot(Object itemId); @Override boolean hasChildren(Object itemId); @Override boolean setParent(Object itemId, Object newParentId); @Override boolean setChildrenAllowed(Object itemId, boolean areChildrenAllowed); }### Answer:
@Test public void testSetChildrenAllowed() { LinkkiInMemoryContainer<TestItem> container = new LinkkiInMemoryContainer<>(); HierarchicalTestItem testItem = new HierarchicalTestItem(23); assertThat(container.setChildrenAllowed(testItem, true), is(false)); } |
### Question:
LinkkiInMemoryContainer extends AbstractInMemoryContainer<T, Object, Item> implements Container.Hierarchical { @Override public boolean isRoot(Object itemId) { return containsId(itemId); } @Override Collection<?> getContainerPropertyIds(); void setItems(Collection<? extends T> items); @Deprecated @Override boolean removeAllItems(); @Deprecated void addAllItems(Collection<T> items); @Override @CheckForNull Property<T> getContainerProperty(@CheckForNull Object itemId, Object propertyId); @Override @CheckForNull Class<?> getType(@CheckForNull Object propertyId); @Override @SuppressWarnings({ "unchecked" }) Collection<T> getChildren(Object itemId); Collection<T> getExistingChildren(T parent); boolean removeExistingChildren(T item); @CheckForNull @Override T getParent(Object itemId); @Override Collection<?> rootItemIds(); @Override boolean areChildrenAllowed(Object itemId); @Override boolean isRoot(Object itemId); @Override boolean hasChildren(Object itemId); @Override boolean setParent(Object itemId, Object newParentId); @Override boolean setChildrenAllowed(Object itemId, boolean areChildrenAllowed); }### Answer:
@Test public void testIsRoot_ofItemNotContained() { LinkkiInMemoryContainer<TestItem> container = new LinkkiInMemoryContainer<>(); assertThat(container.isRoot(new TestItem(42)), is(false)); } |
### Question:
LinkkiInMemoryContainer extends AbstractInMemoryContainer<T, Object, Item> implements Container.Hierarchical { @Override public boolean hasChildren(Object itemId) { return getHierarchicalItem(itemId) .map(HierarchicalRowPmo::hasChildRows) .orElse(false); } @Override Collection<?> getContainerPropertyIds(); void setItems(Collection<? extends T> items); @Deprecated @Override boolean removeAllItems(); @Deprecated void addAllItems(Collection<T> items); @Override @CheckForNull Property<T> getContainerProperty(@CheckForNull Object itemId, Object propertyId); @Override @CheckForNull Class<?> getType(@CheckForNull Object propertyId); @Override @SuppressWarnings({ "unchecked" }) Collection<T> getChildren(Object itemId); Collection<T> getExistingChildren(T parent); boolean removeExistingChildren(T item); @CheckForNull @Override T getParent(Object itemId); @Override Collection<?> rootItemIds(); @Override boolean areChildrenAllowed(Object itemId); @Override boolean isRoot(Object itemId); @Override boolean hasChildren(Object itemId); @Override boolean setParent(Object itemId, Object newParentId); @Override boolean setChildrenAllowed(Object itemId, boolean areChildrenAllowed); }### Answer:
@Test public void testHasChildren_ofItemNotContained() { LinkkiInMemoryContainer<TestItem> container = new LinkkiInMemoryContainer<>(); assertThat(container.hasChildren(new TestItem(42)), is(false)); } |
### Question:
Vaadin7 implements UiFrameworkExtension { @Override public Locale getLocale() { UI ui = UI.getCurrent(); if (ui != null) { Locale locale = ui.getLocale(); if (locale != null) { return locale; } } return Locale.GERMAN; } @Override Locale getLocale(); @Override ComponentWrapperFactory getComponentWrapperFactory(); @Override Stream<?> getChildComponents(Object uiComponent); }### Answer:
@Test public void testGetUiLocale() { assertThat(UI.getCurrent(), is(nullValue())); assertThat(UiFramework.getLocale(), is(Locale.GERMAN)); UI ui = MockUi.mockUi(); when(ui.getLocale()).thenReturn(Locale.ITALIAN); assertThat(UiFramework.getLocale(), is(Locale.ITALIAN)); } |
### Question:
Vaadin7 implements UiFrameworkExtension { @Override public Stream<?> getChildComponents(Object uiComponent) { if (uiComponent instanceof HasComponents) { return StreamUtil.stream((HasComponents)uiComponent); } return Stream.empty(); } @Override Locale getLocale(); @Override ComponentWrapperFactory getComponentWrapperFactory(); @Override Stream<?> getChildComponents(Object uiComponent); }### Answer:
@Test public void testGetChildComponents() { Component component1 = new Label("first label"); Component component2 = new Label("second label"); HasComponents componentWithChildren = new VerticalLayout(component1, component2); Component[] arr = { component1, component2 }; assertThat(UiFramework.get().getChildComponents(componentWithChildren).toArray(), is(arr)); } |
### Question:
UiFramework { public static UiFrameworkExtension get() { return Services.get(UiFrameworkExtension.class); } private UiFramework(); static Locale getLocale(); static ComponentWrapperFactory getComponentWrapperFactory(); static UiFrameworkExtension get(); static Stream<?> getChildComponents(Object uiComponent); }### Answer:
@Test public void testGet() { assertThat(UiFramework.get(), is(instanceOf(TestUiFramework.class))); } |
### Question:
ComponentAnnotationReader { public static boolean isComponentDefinition(@CheckForNull Annotation annotation) { return LINKKI_COMPONENT_ANNOTATION.isPresentOn(annotation); } private ComponentAnnotationReader(); static boolean isComponentDefinition(@CheckForNull Annotation annotation); static boolean isComponentDefinitionPresent(AnnotatedElement annotatedElement); static Stream<Method> getComponentDefinitionMethods(Class<?> pmoClass); static LinkkiComponentDefinition getComponentDefinition(
A annotation,
AnnotatedElement annotatedElement); static Optional<LinkkiComponentDefinition> findComponentDefinition(AnnotatedElement annotatedElement); static Annotation getComponentDefinitionAnnotation(AnnotatedElement annotatedElement, Object pmo); static final String COMPONENT_PROPERTY_SUFFIX; }### Answer:
@Test public void testIsLinkkiComponentDefinition() throws Exception { assertTrue(ComponentAnnotationReader .isComponentDefinition(ClassWithComponentAnnotatedAnnotations.class.getMethod("annotated") .getAnnotation(AnnotationWithComponentAnnotation.class))); assertFalse(ComponentAnnotationReader .isComponentDefinition(ClassWithComponentAnnotatedAnnotations.class .getMethod("annotatedWithoutComponent") .getAnnotation(AnnotationWithoutComponentAnnotation.class))); } |
### Question:
PositionAnnotationReader { public static int getPosition(AnnotatedElement element) { return Arrays.stream(element.getAnnotations()) .filter(a -> a.annotationType().isAnnotationPresent(LinkkiPositioned.class)) .map(PositionAnnotationReader::getPosition) .reduce((a, b) -> verifySamePosition(element, a, b)) .orElseGet(() -> getDeprecatedPosition(element)); } private PositionAnnotationReader(); static int getPosition(AnnotatedElement element); static int getPosition(Annotation annotation); }### Answer:
@Test public void testGetPositionAnnotatedElement() throws Exception { int position = PositionAnnotationReader.getPosition(PosTestPmo.class.getMethod("test")); assertThat(position, is(42)); }
@Test public void testGetPositionAnnotatedElement_SamePosTwice() throws Exception { int position = PositionAnnotationReader.getPosition(PosTestPmo.class.getMethod("testSamePos")); assertThat(position, is(42)); }
@Test public void testGetPositionAnnotatedElement_DiffPos() { Assertions.assertThrows(IllegalArgumentException.class, () -> { PositionAnnotationReader.getPosition(PosTestPmo.class.getMethod("testDiffPos")); }); }
@Test public void testGetPositionAnnotatedElement_BindingDefinition() throws Exception { int position = PositionAnnotationReader.getPosition(PosTestPmo.class.getMethod("testDeprecated")); assertThat(position, is(4711)); } |
### Question:
LayoutAnnotationReader { public static boolean isLayoutDefinition(@CheckForNull Annotation annotation) { return LINKKI_LAYOUT_ANNOTATION.isPresentOn(annotation); } private LayoutAnnotationReader(); static boolean isLayoutDefinition(@CheckForNull Annotation annotation); static Optional<LinkkiLayoutDefinition> findLayoutDefinition(AnnotatedElement annotatedElement); }### Answer:
@Test public void testIsLayoutDefinition() { assertThat(LayoutAnnotationReader.isLayoutDefinition(DummyPmo.class.getAnnotation(DummyLayout.class))); assertThat(LayoutAnnotationReader.isLayoutDefinition(DummyLayout.class.getAnnotation(LinkkiLayout.class)), is(false)); } |
### Question:
LayoutAnnotationReader { public static Optional<LinkkiLayoutDefinition> findLayoutDefinition(AnnotatedElement annotatedElement) { return LINKKI_LAYOUT_ANNOTATION .findAnnotatedAnnotationsOn(annotatedElement) .reduce(LINKKI_LAYOUT_ANNOTATION.onlyOneOn(annotatedElement)) .map(annotation -> getLayoutDefinition(annotation, annotatedElement)); } private LayoutAnnotationReader(); static boolean isLayoutDefinition(@CheckForNull Annotation annotation); static Optional<LinkkiLayoutDefinition> findLayoutDefinition(AnnotatedElement annotatedElement); }### Answer:
@Test public void testFindLayoutDefinition() { Optional<LinkkiLayoutDefinition> layoutDefinition = LayoutAnnotationReader.findLayoutDefinition(DummyPmo.class); assertThat(layoutDefinition, is(present())); assertThat(layoutDefinition.get(), is(instanceOf(DummyLayoutDefinition.class))); assertThat(LayoutAnnotationReader.findLayoutDefinition(String.class), is(absent())); } |
### Question:
Sections { public static String getSectionId(Object pmo) { Optional<Method> idMethod = BeanUtils.getMethod(pmo.getClass(), (m) -> m.isAnnotationPresent(SectionID.class)); return idMethod.map(m -> getIdFromSectionIdMethod(pmo, m)).orElse(pmo.getClass().getSimpleName()); } private Sections(); static String getSectionId(Object pmo); static Optional<ButtonPmo> getEditButtonPmo(Object pmo); }### Answer:
@Test public void testGetSectionId() { assertThat(Sections.getSectionId(new SectionPmoWithoutId()), is(SectionPmoWithoutId.class.getSimpleName())); TestSectionPmo testSectionPmo = new TestSectionPmo(); testSectionPmo.setId("foo"); assertThat(Sections.getSectionId(testSectionPmo), is("foo")); } |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.