1 /*
2 * Copyright 2002-2004 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.application.config;
17
18 import junit.framework.Assert;
19 import junit.framework.TestCase;
20
21 import org.easymock.EasyMock;
22 import org.springframework.richclient.application.ApplicationWindow;
23
24
25 /**
26 * Provides unit tests for the {@link ApplicationWindowSetter} class.
27 *
28 * @author Kevin Stembridge
29 * @since 0.3
30 *
31 */
32 public class ApplicationWindowSetterTests extends TestCase {
33
34 /**
35 * Creates a new uninitialized {@code ApplicationWindowSetterTests}.
36 */
37 public ApplicationWindowSetterTests() {
38 super();
39 }
40
41 /**
42 * Confirms that the constructor throws an IllegalArgumentException when passed a null window.
43 */
44 public void testConstructor() {
45
46 try {
47 new ApplicationWindowSetter(null);
48 Assert.fail("Should have thrown an IllegalArgumentException for null ApplicationWindow");
49 }
50 catch(IllegalArgumentException e) {
51 //test passes
52 }
53
54 }
55
56 /**
57 * Confirms that the postProcessBeforeInitialization method correctly sets the window on the
58 * windowAware object.
59 */
60 public void testPostProcessBeforeInit() {
61
62 //create required mocks
63 ApplicationWindow window = (ApplicationWindow) EasyMock.createMock(ApplicationWindow.class);
64 ApplicationWindowAware windowAware
65 = (ApplicationWindowAware) EasyMock.createMock(ApplicationWindowAware.class);
66
67 //confirm null bean is ok
68 ApplicationWindowSetter windowSetter = new ApplicationWindowSetter(window);
69 EasyMock.replay(windowAware);
70 EasyMock.replay(window);
71 windowSetter.postProcessBeforeInitialization(null, "bogusBeanName");
72 EasyMock.verify(windowAware);
73 EasyMock.verify(window);
74
75 //confirm that the windowAware has its window set
76 EasyMock.reset(window);
77 EasyMock.reset(windowAware);
78
79 windowAware.setApplicationWindow(window);
80
81 EasyMock.replay(window);
82 EasyMock.replay(windowAware);
83
84 windowSetter.postProcessBeforeInitialization(windowAware, "bogusBeanName");
85
86 EasyMock.verify(window);
87 EasyMock.verify(windowAware);
88
89 }
90
91 }