### Question:
ButtonBindingDefinition implements BindingDefinition { @Override public Button newComponent() { Button button = ComponentFactory.newButton(); if (buttonAnnotation.showIcon()) { button.setIcon(buttonAnnotation.icon()); } for (String styleName : buttonAnnotation.styleNames()) { button.addStyleName(styleName); } if (buttonAnnotation.shortcutKeyCode() != -1) { button.setClickShortcut(buttonAnnotation.shortcutKeyCode(), buttonAnnotation.shortcutModifierKeys()); } return button; } ButtonBindingDefinition(UIButton annotation); @Override Button newComponent(); @Override String label(); @Override EnabledType enabled(); @Override VisibleType visible(); @Override RequiredType required(); @Override String modelObject(); @Override String modelAttribute();  }### Answer:
@Test public void testNewComponent_DefaultAnnotations() { ButtonBindingDefinition adapter = new ButtonBindingDefinition(defaultAnnotation()); Component component = adapter.newComponent(); assertThat(component, is(instanceOf(Button.class))); Button button = (Button)component; assertThat(button.getIcon(), is(nullValue())); assertThat(button.getStyleName(), is("")); }
@Test public void testNewComponent_CustomAnnotationsAreUsed() { ButtonBindingDefinition adapter = new ButtonBindingDefinition(customAnnotation()); Component component = adapter.newComponent(); assertThat(component, is(instanceOf(Button.class))); Button button = (Button)component; assertThat(button.getIcon(), is(VaadinIcons.AMBULANCE)); assertThat(button.getStyleName(), is(ValoTheme.BUTTON_ICON_ONLY)); }
@SuppressWarnings("deprecation") @Test public void testNewComponent_UseShortcutKeyCode() { Button button = new ButtonBindingDefinition(shortcutButton()).newComponent(); assertThat(button, not(nullValue())); Button buttonSpy = spy(button); buttonSpy.setClickShortcut(KeyCode.ENTER); verify(buttonSpy).removeShortcutListener(clickShortcutCaptor.capture()); @NonNull ClickShortcut value = clickShortcutCaptor.getValue(); assertThat(value.getKeyCode(), is(KeyCode.E)); assertThat(value.getModifiers(), is(new int[] { ModifierKey.ALT })); }
@Test public void testNewComponent_CustomAnnotationsAreUsed() { ButtonBindingDefinition adapter = new ButtonBindingDefinition(customAnnotation()); Component component = adapter.newComponent(); assertThat(component, is(instanceOf(Button.class))); Button button = (Button)component; assertThat(button.getIcon(), is(FontAwesome.AMBULANCE)); assertThat(button.getStyleName(), is(ValoTheme.BUTTON_ICON_ONLY)); }
@Test public void testNewComponent_UseShortcutKeyCode() { Button button = new ButtonBindingDefinition(shortcutButton()).newComponent(); assertThat(button, not(nullValue())); Button buttonSpy = spy(button); buttonSpy.setClickShortcut(KeyCode.ENTER); verify(buttonSpy).removeShortcutListener(clickShortcutCaptor.capture()); @NonNull ClickShortcut value = clickShortcutCaptor.getValue(); assertThat(value.getKeyCode(), is(KeyCode.E)); assertThat(value.getModifiers(), is(new int[] { ModifierKey.ALT })); }