@Test (dataProvider="generateStates") public void testState(boolean canHandle, boolean isEnabled, boolean useConstructor) { Mockito.when(action.canHandle(context)).thenReturn(canHandle); Mockito.when(action.isEnabled()).thenReturn(isEnabled); ContextAwareButton button = useConstructor ? new ContextAwareButton(action, context) : new ContextAwareButton(action); if (!useConstructor) { button.setContext(context); } Assert.assertEquals(button.isVisible(), canHandle); Assert.assertEquals(button.isEnabled(), isEnabled); }
public void setContext(ActionContext context) { if (context != null) { Action a = getAction(); if (a instanceof ContextAwareAction) { ContextAwareAction action = (ContextAwareAction) a; setVisible(action.canHandle(context)); setEnabled(action.isEnabled()); } } else { setVisible(false); setEnabled(false); } }
ContextAwareButton extends JButton { public void setContext(ActionContext context) { if (context != null) { Action a = getAction(); if (a instanceof ContextAwareAction) { ContextAwareAction action = (ContextAwareAction) a; setVisible(action.canHandle(context)); setEnabled(action.isEnabled()); } } else { setVisible(false); setEnabled(false); } } }
ContextAwareButton extends JButton { public void setContext(ActionContext context) { if (context != null) { Action a = getAction(); if (a instanceof ContextAwareAction) { ContextAwareAction action = (ContextAwareAction) a; setVisible(action.canHandle(context)); setEnabled(action.isEnabled()); } } else { setVisible(false); setEnabled(false); } } ContextAwareButton(ContextAwareAction action);  ContextAwareButton(ContextAwareAction action, ActionContext context); }
ContextAwareButton extends JButton { public void setContext(ActionContext context) { if (context != null) { Action a = getAction(); if (a instanceof ContextAwareAction) { ContextAwareAction action = (ContextAwareAction) a; setVisible(action.canHandle(context)); setEnabled(action.isEnabled()); } } else { setVisible(false); setEnabled(false); } } ContextAwareButton(ContextAwareAction action);  ContextAwareButton(ContextAwareAction action, ActionContext context); @Override void setIcon(Icon icon); @Override void setText(String text); void setContext(ActionContext context); }
ContextAwareButton extends JButton { public void setContext(ActionContext context) { if (context != null) { Action a = getAction(); if (a instanceof ContextAwareAction) { ContextAwareAction action = (ContextAwareAction) a; setVisible(action.canHandle(context)); setEnabled(action.isEnabled()); } } else { setVisible(false); setEnabled(false); } } ContextAwareButton(ContextAwareAction action);  ContextAwareButton(ContextAwareAction action, ActionContext context); @Override void setIcon(Icon icon); @Override void setText(String text); void setContext(ActionContext context);  }