001    /*
002     * Copyright 2002-2004 the original author or authors.
003     *
004     * Licensed under the Apache License, Version 2.0 (the "License"); you may not
005     * use this file except in compliance with the License. You may obtain a copy of
006     * 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, WITHOUT
012     * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
013     * License for the specific language governing permissions and limitations under
014     * the License.
015     */
016    package org.springframework.richclient.application.config;
017    
018    import junit.framework.Assert;
019    import junit.framework.TestCase;
020    
021    import org.easymock.EasyMock;
022    import org.springframework.richclient.application.ApplicationWindow;
023    
024    
025    /**
026     * Provides unit tests for the {@link ApplicationWindowSetter} class.
027     *
028     * @author Kevin Stembridge
029     * @since 0.3
030     *
031     */
032    public class ApplicationWindowSetterTests extends TestCase {
033    
034        /**
035         * Creates a new uninitialized {@code ApplicationWindowSetterTests}.
036         */
037        public ApplicationWindowSetterTests() {
038            super();
039        }
040    
041        /**
042         * Confirms that the constructor throws an IllegalArgumentException when passed a null window.
043         */
044        public void testConstructor() {
045            
046            try {
047                new ApplicationWindowSetter(null);
048                Assert.fail("Should have thrown an IllegalArgumentException for null ApplicationWindow");
049            }
050            catch(IllegalArgumentException e) {
051                //test passes
052            }
053            
054        }
055        
056        /**
057         * Confirms that the postProcessBeforeInitialization method correctly sets the window on the 
058         * windowAware object. 
059         */
060        public void testPostProcessBeforeInit() {
061            
062            //create required mocks
063            ApplicationWindow window = (ApplicationWindow) EasyMock.createMock(ApplicationWindow.class);
064            ApplicationWindowAware windowAware 
065                    = (ApplicationWindowAware) EasyMock.createMock(ApplicationWindowAware.class);
066            
067            //confirm null bean is ok
068            ApplicationWindowSetter windowSetter = new ApplicationWindowSetter(window);
069            EasyMock.replay(windowAware);
070            EasyMock.replay(window);
071            windowSetter.postProcessBeforeInitialization(null, "bogusBeanName");
072            EasyMock.verify(windowAware);
073            EasyMock.verify(window);
074            
075            //confirm that the windowAware has its window set
076            EasyMock.reset(window);
077            EasyMock.reset(windowAware);
078            
079            windowAware.setApplicationWindow(window);
080            
081            EasyMock.replay(window);
082            EasyMock.replay(windowAware);
083            
084            windowSetter.postProcessBeforeInitialization(windowAware, "bogusBeanName");
085            
086            EasyMock.verify(window);
087            EasyMock.verify(windowAware);
088            
089        }
090    
091    }