1   /*
2    * Copyright 2002-2007 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.dialog;
17  
18  import java.awt.event.WindowAdapter;
19  import java.awt.event.WindowEvent;
20  
21  import javax.swing.SwingUtilities;
22  
23  import org.springframework.binding.value.support.ValueHolder;
24  import org.springframework.richclient.test.SpringRichTestCase;
25  
26  /**
27   * Skeleton test for ApplicationDialog
28   * 
29   * @author Peter De Bruycker
30   */
31  public abstract class ApplicationDialogTestCase extends SpringRichTestCase {
32  	private ApplicationDialog applicationDialog;
33  
34  	private OnAboutToShow onAboutToShow = new OnAboutToShow();
35  
36  	public void testSetAndGetTitle() {
37  		applicationDialog.setTitle("new title");
38  
39  		assertEquals("new title", applicationDialog.getTitle());
40  		assertEquals("new title", applicationDialog.getDialog().getTitle());
41  
42  		applicationDialog.setTitle("other title");
43  
44  		assertEquals("other title", applicationDialog.getTitle());
45  		assertEquals("other title", applicationDialog.getDialog().getTitle());
46  	}
47  
48  	public void testOnAboutToShowIsCalled() {
49  		applicationDialog.getDialog().addWindowListener(new WindowAdapter() {
50  			public void windowOpened(WindowEvent e) {
51  				SwingUtilities.invokeLater(new Runnable() {
52  					public void run() {
53  						applicationDialog.getDialog().dispose();
54  					}
55  				});
56  			}
57  		});
58  		applicationDialog.showDialog();
59  
60  		assertTrue(onAboutToShow.wasRun());
61  	}
62  
63  	protected final void doSetUp() throws Exception {
64  		applicationDialog = createApplicationDialog(onAboutToShow);
65  
66  		assertNotNull(applicationDialog);
67  
68  		doMoreSetUp();
69  	}
70  
71  	protected void doMoreSetUp() throws Exception {
72  
73  	}
74  
75  	protected abstract ApplicationDialog createApplicationDialog(Runnable onAboutToShow);
76  
77  	private static class OnAboutToShow implements Runnable {
78  		public ValueHolder booleanHolder = new ValueHolder();
79  
80  		public void run() {
81  			booleanHolder.setValue(Boolean.TRUE);
82  		}
83  
84  		public boolean wasRun() {
85  			return Boolean.TRUE.equals(booleanHolder.getValue());
86  		}
87  	}
88  }