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.support;
017
018 import org.easymock.EasyMock;
019
020 import org.springframework.richclient.test.SpringRichTestCase;
021 import org.springframework.richclient.application.PageListener;
022 import org.springframework.richclient.application.ApplicationWindow;
023 import org.springframework.richclient.application.config.ApplicationLifecycleAdvisor;
024 import org.springframework.richclient.application.config.DefaultApplicationLifecycleAdvisor;
025 import org.springframework.richclient.application.config.ApplicationWindowConfigurer;
026 import org.springframework.richclient.command.CommandGroup;
027
028 /**
029 * Test cases for {@link DefaultApplicationWindow}.
030 *
031 * @author Andy DePue
032 */
033 public class DefaultApplicationWindowTests extends SpringRichTestCase {
034
035 public void testRegressionFailureToRemovePageListener() {
036 PageListener pageListener = (PageListener)EasyMock.createNiceMock(PageListener.class);
037 EasyMock.replay(pageListener);
038 DefaultApplicationWindow daw = new DefaultApplicationWindow();
039 daw.addPageListener(pageListener);
040
041 try {
042 daw.removePageListener(pageListener);
043 } catch(IllegalArgumentException iae) {
044 iae.printStackTrace();
045 fail("DefaultApplicationWindow.removePageListener threw IllegalArgumentException when removing a valid pageListener: " + iae);
046 }
047 }
048
049 /**
050 * Mocks out various methods on the returned ApplicationLifecycleAdvisor
051 * as they are not needed for the current unit test(s) and will throw
052 * exceptions without further setup for the test. If more unit tests
053 * are added to this class in the future, then the returned
054 * ApplicationLifecycleAdvisor should be revisited to ensure it still
055 * meets the needs of this test case.
056 */
057 protected ApplicationLifecycleAdvisor createApplicationLifecycleAdvisor() {
058 return new DefaultApplicationLifecycleAdvisor() {
059 public void onPreWindowOpen(ApplicationWindowConfigurer configurer) {
060 }
061 public void onCommandsCreated(ApplicationWindow window) {
062 }
063 public ApplicationWindowCommandManager createWindowCommandManager() {
064 return null;
065 }
066 public CommandGroup getMenuBarCommandGroup() {
067 return null;
068 }
069 public CommandGroup getToolBarCommandGroup() {
070 return null;
071 }
072 };
073 }
074 }