1 /*
2 * Copyright 2004-2008 the Seasar Foundation and the Others.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of 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,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13 * either express or implied. See the License for the specific language
14 * governing permissions and limitations under the License.
15 */
16 package org.seasar.eclipse.common.util;
17
18 import junit.framework.TestCase;
19
20 import org.eclipse.swt.SWT;
21 import org.eclipse.swt.widgets.Display;
22 import org.eclipse.swt.widgets.Shell;
23
24 /**
25 * {@link SWT} の {@link Display} や {@link Shell} オブジェクトを使用するテストケースのための基底クラスです。<br />
26 *
27 * @author y-komori
28 */
29 public abstract class AbstractShellTest extends TestCase {
30 protected Display display;
31
32 protected Shell shell;
33
34 private boolean useShell;
35
36 protected AbstractShellTest() {
37 this(false);
38 }
39
40 protected AbstractShellTest(final boolean useShell) {
41 super();
42 this.useShell = useShell;
43 }
44
45 @Override
46 protected void setUp() throws Exception {
47 display = Display.getCurrent();
48 if (display == null) {
49 display = new Display();
50 }
51
52 if (useShell) {
53 shell = display.getActiveShell();
54 if (shell == null) {
55 shell = new Shell(display);
56 }
57 }
58 }
59
60 @Override
61 protected void tearDown() throws Exception {
62 if (useShell) {
63 if (shell != null) {
64 shell.dispose();
65 }
66 }
67
68 if (display != null) {
69 display.dispose();
70 }
71 }
72 }