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  import junit.framework.TestCase;
21  
22  import org.springframework.richclient.image.EmptyIcon;
23  
24  /**
25   * Abstract base class for <code>CommandButtonConfigurer</code>
26   * implementations
27   * 
28   * @author Peter De Bruycker
29   */
30  public abstract class CommandButtonConfigurerTestCase extends TestCase {
31  
32  	private CommandButtonConfigurer configurer;
33  
34  	private CommandFaceDescriptor descriptor;
35  
36  	public final void testConfigureWithNullDescriptor() {
37  		try {
38  			configurer.configure(new JButton(), null, null);
39  			fail("Should throw IllegalArgumentException");
40  		}
41  		catch (IllegalArgumentException e) {
42  			pass();
43  		}
44  	}
45  
46  	public final void testConfigureWithNullButton() {
47  		try {
48  			configurer.configure(null, null, descriptor);
49  			fail("Should throw IllegalArgumentException");
50  		}
51  		catch (IllegalArgumentException e) {
52  			pass();
53  		}
54  	}
55  
56  	private static void pass() {
57  		// test passes
58  	}
59  
60  	protected final void setUp() throws Exception {
61  		configurer = createConfigurer();
62  		assertNotNull("Configurer cannot be null", configurer);
63  
64  		descriptor = new CommandFaceDescriptor();
65  		CommandButtonIconInfo iconInfo = new CommandButtonIconInfo(EmptyIcon.SMALL);
66  		CommandButtonLabelInfo labelInfo = CommandButtonLabelInfo.valueOf("test");
67  		descriptor.setIconInfo(iconInfo);
68  		descriptor.setLabelInfo(labelInfo);
69  		descriptor.setCaption("Tool tip");
70  	}
71  
72  	protected final CommandFaceDescriptor getCommandFaceDescriptor() {
73  		return descriptor;
74  	}
75  
76  	protected abstract CommandButtonConfigurer createConfigurer();
77  }