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.support;
17  
18  import org.easymock.EasyMock;
19  
20  import org.springframework.richclient.test.SpringRichTestCase;
21  import org.springframework.richclient.application.PageListener;
22  import org.springframework.richclient.application.ApplicationWindow;
23  import org.springframework.richclient.application.config.ApplicationLifecycleAdvisor;
24  import org.springframework.richclient.application.config.DefaultApplicationLifecycleAdvisor;
25  import org.springframework.richclient.application.config.ApplicationWindowConfigurer;
26  import org.springframework.richclient.command.CommandGroup;
27  
28  /**
29   * Test cases for {@link DefaultApplicationWindow}.
30   * 
31   * @author Andy DePue
32   */
33  public class DefaultApplicationWindowTests extends SpringRichTestCase {
34  
35      public void testRegressionFailureToRemovePageListener() {
36          PageListener pageListener = (PageListener)EasyMock.createNiceMock(PageListener.class);
37          EasyMock.replay(pageListener);
38          DefaultApplicationWindow daw = new DefaultApplicationWindow();
39          daw.addPageListener(pageListener);
40  
41          try {
42              daw.removePageListener(pageListener);
43          } catch(IllegalArgumentException iae) {
44              iae.printStackTrace();
45              fail("DefaultApplicationWindow.removePageListener threw IllegalArgumentException when removing a valid pageListener: " + iae);
46          }
47      }
48  
49      /**
50       * Mocks out various methods on the returned ApplicationLifecycleAdvisor
51       * as they are not needed for the current unit test(s) and will throw
52       * exceptions without further setup for the test.  If more unit tests
53       * are added to this class in the future, then the returned
54       * ApplicationLifecycleAdvisor should be revisited to ensure it still
55       * meets the needs of this test case.
56       */
57      protected ApplicationLifecycleAdvisor createApplicationLifecycleAdvisor() {
58          return new DefaultApplicationLifecycleAdvisor() {
59              public void onPreWindowOpen(ApplicationWindowConfigurer configurer) {
60              }
61              public void onCommandsCreated(ApplicationWindow window) {
62              }
63              public ApplicationWindowCommandManager createWindowCommandManager() {
64                  return null;
65              }
66              public CommandGroup getMenuBarCommandGroup() {
67                  return null;
68              }
69              public CommandGroup getToolBarCommandGroup() {
70                  return null;
71              }
72          };
73      }
74  }