001 /* 002 * Copyright 2002-2007 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.dialog; 017 018 import java.awt.event.WindowAdapter; 019 import java.awt.event.WindowEvent; 020 021 import javax.swing.SwingUtilities; 022 023 import org.springframework.binding.value.support.ValueHolder; 024 import org.springframework.richclient.test.SpringRichTestCase; 025 026 /** 027 * Skeleton test for ApplicationDialog 028 * 029 * @author Peter De Bruycker 030 */ 031 public abstract class ApplicationDialogTestCase extends SpringRichTestCase { 032 private ApplicationDialog applicationDialog; 033 034 private OnAboutToShow onAboutToShow = new OnAboutToShow(); 035 036 public void testSetAndGetTitle() { 037 applicationDialog.setTitle("new title"); 038 039 assertEquals("new title", applicationDialog.getTitle()); 040 assertEquals("new title", applicationDialog.getDialog().getTitle()); 041 042 applicationDialog.setTitle("other title"); 043 044 assertEquals("other title", applicationDialog.getTitle()); 045 assertEquals("other title", applicationDialog.getDialog().getTitle()); 046 } 047 048 public void testOnAboutToShowIsCalled() { 049 applicationDialog.getDialog().addWindowListener(new WindowAdapter() { 050 public void windowOpened(WindowEvent e) { 051 SwingUtilities.invokeLater(new Runnable() { 052 public void run() { 053 applicationDialog.getDialog().dispose(); 054 } 055 }); 056 } 057 }); 058 applicationDialog.showDialog(); 059 060 assertTrue(onAboutToShow.wasRun()); 061 } 062 063 protected final void doSetUp() throws Exception { 064 applicationDialog = createApplicationDialog(onAboutToShow); 065 066 assertNotNull(applicationDialog); 067 068 doMoreSetUp(); 069 } 070 071 protected void doMoreSetUp() throws Exception { 072 073 } 074 075 protected abstract ApplicationDialog createApplicationDialog(Runnable onAboutToShow); 076 077 private static class OnAboutToShow implements Runnable { 078 public ValueHolder booleanHolder = new ValueHolder(); 079 080 public void run() { 081 booleanHolder.setValue(Boolean.TRUE); 082 } 083 084 public boolean wasRun() { 085 return Boolean.TRUE.equals(booleanHolder.getValue()); 086 } 087 } 088 }