1   /*
2    * Copyright 2002-2007 the original author or authors.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5    * use this file except in compliance with the License. You may obtain a copy of
6    * the License at
7    *
8    * http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13   * License for the specific language governing permissions and limitations under
14   * the License.
15   */
16  package org.springframework.richclient.command;
17  
18  import javax.swing.JButton;
19  
20  import junit.framework.TestCase;
21  
22  /**
23   * Testcase for ActionCommand
24   * 
25   * @author Peter De Bruycker
26   */
27  public class ActionCommandTests extends TestCase {
28  
29  	public void testOnButtonAttached() {
30  		final boolean[] executed = { false };
31  
32  		ActionCommand command = new ActionCommand() {
33  			protected void doExecuteCommand() {
34  				executed[0] = true;
35  			}
36  		};
37  		command.setActionCommand("theActionCommand");
38  
39  		JButton button = new JButton("test");
40  
41  		command.onButtonAttached(button);
42  
43  		assertEquals("theActionCommand", button.getActionCommand());
44  
45  		button.doClick();
46  		assertTrue(executed[0]);
47  	}
48  
49  	public void testOnButtonAttachedWithDisplayDialog() {
50  		ActionCommand command = new ActionCommand() {
51  			protected void doExecuteCommand() {
52  				// do nothing
53  			}
54  		};
55  		command.setDisplaysInputDialog(true);
56  
57  		JButton button = new JButton();
58  		button.setText(null);
59  
60  		command.onButtonAttached(button);
61  
62  		assertEquals(null, button.getText());
63  	}
64  
65  }