ContextAwareButton extends JButton { @Override public void setText(String text) { Object name = getAction().getValue(Action.NAME); if (name != null && !name.equals(text)) { this.setToolTipText(name.toString()); } super.setText(text); } ContextAwareButton(ContextAwareAction action);  ContextAwareButton(ContextAwareAction action, ActionContext context); @Override void setIcon(Icon icon); @Override void setText(String text); void setContext(ActionContext context);  }
@Test public void testToolTip() { ContextAwareButton button = new ContextAwareButton(action); Assert.assertTrue(button.getToolTipText() == null || button.getToolTipText().isEmpty()); button.setText(ACTION_NAME); Assert.assertTrue(button.getToolTipText() == null || button.getToolTipText().isEmpty()); button.setText("Something else"); Assert.assertEquals(button.getToolTipText(), ACTION_NAME); }