View Javadoc

1   // Copyright (C) 2008 Philip Aston
2   // All rights reserved.
3   //
4   // This file is part of The Grinder software distribution. Refer to
5   // the file LICENSE which is part of The Grinder distribution for
6   // licensing details. The Grinder distribution is available on the
7   // Internet at http://grinder.sourceforge.net/
8   //
9   // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
10  // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
11  // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
12  // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
13  // COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
14  // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
15  // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
16  // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
17  // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
18  // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
19  // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
20  // OF THE POSSIBILITY OF SUCH DAMAGE.
21  
22  package net.grinder.console.swingui;
23  
24  import java.awt.event.ActionEvent;
25  
26  import javax.swing.AbstractAction;
27  import javax.swing.Action;
28  import javax.swing.ImageIcon;
29  
30  import junit.framework.TestCase;
31  
32  
33  /**
34   * Unit tests for {@link CustomJButton}.
35   *
36   * @author Philip Aston
37   */
38  public class TestCustomJButton extends TestCase {
39  
40    public void testCustomJButton() throws Exception {
41      final CustomJButton button = new CustomJButton();
42  
43      final Action action = new AbstractAction() {
44        public void actionPerformed(ActionEvent e) {
45        }
46      };
47  
48      button.setAction(action);
49      assertNull(button.getRolloverIcon());
50  
51      final ImageIcon image1 = new ImageIcon();
52      action.putValue(CustomAction.ROLLOVER_ICON, image1);
53      assertNull(button.getRolloverIcon());
54  
55      button.setAction(action);
56      assertSame(image1, button.getRolloverIcon());
57    }
58  }