1   /*
2    * Copyright 2002-2007 the original author or authors.
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of 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,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.springframework.richclient.command.config;
17  
18  import javax.swing.JButton;
19  
20  /**
21   * Test case for <code>ToolBarCommandButtonConfigurer</code>
22   * 
23   * @author Peter De Bruycker
24   */
25  public class ToolBarCommandButtonConfigurerTests extends CommandButtonConfigurerTestCase {
26  
27  	public void testDefaults() {
28  		ToolBarCommandButtonConfigurer configurer= new ToolBarCommandButtonConfigurer();
29  		
30  		assertFalse(configurer.isShowText());
31  		assertTrue(configurer.isTextBelowIcon());
32  	}
33  	
34  	public void testConfigureWithDefaults() {
35  		ToolBarCommandButtonConfigurer configurer = new ToolBarCommandButtonConfigurer();
36  		JButton button = new JButton();
37  
38  		configurer.configure(button, null, getCommandFaceDescriptor());
39  
40  		assertEquals(null, button.getText());
41  		assertEquals(getCommandFaceDescriptor().getIcon(), button.getIcon());
42  		assertEquals(getCommandFaceDescriptor().getCaption(), button.getToolTipText());
43  	}
44  	
45  	public void testConfigureWithShowTextTrue() {
46  		ToolBarCommandButtonConfigurer configurer = new ToolBarCommandButtonConfigurer();
47  		configurer.setShowText(true);
48  		
49  		JButton button = new JButton();
50  
51  		configurer.configure(button, null, getCommandFaceDescriptor());
52  
53  		assertEquals(getCommandFaceDescriptor().getText(), button.getText());
54  		assertEquals(getCommandFaceDescriptor().getIcon(), button.getIcon());
55  		assertEquals(getCommandFaceDescriptor().getCaption(), button.getToolTipText());
56  		
57  		assertEquals(JButton.BOTTOM, button.getVerticalTextPosition());
58  		assertEquals(JButton.CENTER, button.getHorizontalTextPosition());
59  	}
60  	
61  	public void testConfigureWithShowTextTrueAndTextBelowIconFalse() {
62  		ToolBarCommandButtonConfigurer configurer = new ToolBarCommandButtonConfigurer();
63  		configurer.setShowText(true);
64  		configurer.setTextBelowIcon(false);
65  		
66  		JButton button = new JButton();
67  
68  		configurer.configure(button, null, getCommandFaceDescriptor());
69  
70  		assertEquals(getCommandFaceDescriptor().getText(), button.getText());
71  		assertEquals(getCommandFaceDescriptor().getIcon(), button.getIcon());
72  		assertEquals(getCommandFaceDescriptor().getCaption(), button.getToolTipText());
73  		
74  		assertEquals(JButton.CENTER, button.getVerticalTextPosition());
75  		assertEquals(JButton.TRAILING, button.getHorizontalTextPosition());
76  	}
77  	
78  	protected CommandButtonConfigurer createConfigurer() {
79  		return new ToolBarCommandButtonConfigurer();
80  	}
81  }