001    /*
002     * Copyright 2002-2007 the original author or authors.
003     * 
004     * Licensed under the Apache License, Version 2.0 (the "License");
005     * you may not use this file except in compliance with the License.
006     * You may obtain a copy of the License at
007     * 
008     *      http://www.apache.org/licenses/LICENSE-2.0
009     * 
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed under the License is distributed on an "AS IS" BASIS,
012     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013     * See the License for the specific language governing permissions and
014     * limitations under the License.
015     */
016    package org.springframework.richclient.command.config;
017    
018    import javax.swing.JButton;
019    
020    import junit.framework.TestCase;
021    
022    import org.springframework.richclient.image.EmptyIcon;
023    
024    /**
025     * Abstract base class for <code>CommandButtonConfigurer</code>
026     * implementations
027     * 
028     * @author Peter De Bruycker
029     */
030    public abstract class CommandButtonConfigurerTestCase extends TestCase {
031    
032            private CommandButtonConfigurer configurer;
033    
034            private CommandFaceDescriptor descriptor;
035    
036            public final void testConfigureWithNullDescriptor() {
037                    try {
038                            configurer.configure(new JButton(), null, null);
039                            fail("Should throw IllegalArgumentException");
040                    }
041                    catch (IllegalArgumentException e) {
042                            pass();
043                    }
044            }
045    
046            public final void testConfigureWithNullButton() {
047                    try {
048                            configurer.configure(null, null, descriptor);
049                            fail("Should throw IllegalArgumentException");
050                    }
051                    catch (IllegalArgumentException e) {
052                            pass();
053                    }
054            }
055    
056            private static void pass() {
057                    // test passes
058            }
059    
060            protected final void setUp() throws Exception {
061                    configurer = createConfigurer();
062                    assertNotNull("Configurer cannot be null", configurer);
063    
064                    descriptor = new CommandFaceDescriptor();
065                    CommandButtonIconInfo iconInfo = new CommandButtonIconInfo(EmptyIcon.SMALL);
066                    CommandButtonLabelInfo labelInfo = CommandButtonLabelInfo.valueOf("test");
067                    descriptor.setIconInfo(iconInfo);
068                    descriptor.setLabelInfo(labelInfo);
069                    descriptor.setCaption("Tool tip");
070            }
071    
072            protected final CommandFaceDescriptor getCommandFaceDescriptor() {
073                    return descriptor;
074            }
075    
076            protected abstract CommandButtonConfigurer createConfigurer();
077    }