001 /*
002 * Created on Feb 16, 2007
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
005 * in compliance with the License. You may obtain a copy of the License at
006 *
007 * http://www.apache.org/licenses/LICENSE-2.0
008 *
009 * Unless required by applicable law or agreed to in writing, software distributed under the License
010 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
011 * or implied. See the License for the specific language governing permissions and limitations under
012 * the License.
013 *
014 * Copyright @2007-2010 the original author or authors.
015 */
016 package org.fest.swing.fixture;
017
018 import static org.fest.swing.core.BasicRobot.robotWithCurrentAwtHierarchy;
019
020 import java.awt.Dimension;
021 import java.awt.Window;
022
023 import org.fest.swing.core.BasicRobot;
024 import org.fest.swing.core.Robot;
025 import org.fest.swing.exception.ComponentLookupException;
026 import org.fest.swing.lock.ScreenLock;
027
028 /**
029 * Understands functional testing of <code>{@link Window}</code>s:
030 * <ul>
031 * <li>user input simulation</li>
032 * <li>state verification</li>
033 * <li>property value query</li>
034 * </ul>
035 * @param <T> the type of window handled by this fixture.
036 *
037 * @author Alex Ruiz
038 */
039 public abstract class WindowFixture<T extends Window> extends ContainerFixture<T> implements CommonComponentFixture,
040 WindowLikeContainerFixture, JPopupMenuInvokerFixture {
041
042 /**
043 * Creates a new <code>{@link WindowFixture}</code>. This constructor creates a new <code>{@link Robot}</code>
044 * containing the current AWT hierarchy.
045 * @param type the type of <code>Window</code> to find using the created <code>Robot</code>.
046 * @throws NullPointerException if the given <code>Window</code> type is <code>null</code>.
047 * @throws ComponentLookupException if a <code>Window</code> having a matching type could not be found.
048 * @throws ComponentLookupException if more than one <code>Window</code> having a matching type is found.
049 * @see BasicRobot#robotWithCurrentAwtHierarchy()
050 */
051 public WindowFixture(Class<? extends T> type) {
052 this(robotWithCurrentAwtHierarchy(), type);
053 }
054
055 /**
056 * Creates a new <code>{@link WindowFixture}</code>.
057 * @param robot performs simulation of user events on a <code>Window</code>.
058 * @param type the type of <code>Window</code> to find using the given <code>Robot</code>.
059 * @throws NullPointerException if the given robot is <code>null</code>.
060 * @throws NullPointerException if the given <code>Window</code> type is <code>null</code>.
061 * @throws ComponentLookupException if a <code>Window</code> having a matching type could not be found.
062 * @throws ComponentLookupException if more than one <code>Window</code> having a matching type is found.
063 */
064 public WindowFixture(Robot robot, Class<? extends T> type) {
065 super(robot, type);
066 }
067
068 /**
069 * Creates a new <code>{@link WindowFixture}</code>. This constructor creates a new
070 * <code>{@link Robot}</code> containing the current AWT hierarchy.
071 * @param name the name of the <code>Window</code> to find.
072 * @param type the type of <code>Window</code> to find using the created <code>Robot</code>.
073 * @throws NullPointerException if the given <code>Window</code> type is <code>null</code>.
074 * @throws ComponentLookupException if a <code>Window</code> having a matching name could not be found.
075 * @throws ComponentLookupException if more than one <code>Window</code> having a matching name is found.
076 * @see BasicRobot#robotWithCurrentAwtHierarchy()
077 */
078 public WindowFixture(String name, Class<? extends T> type) {
079 this(robotWithCurrentAwtHierarchy(), name, type);
080 }
081
082 /**
083 * Creates a new <code>{@link WindowFixture}</code>.
084 * @param robot performs simulation of user events on a <code>Window</code>.
085 * @param name the name of the <code>Window</code> to find using the given <code>Robot</code>.
086 * @param type the type of <code>Window</code> to find using the given <code>Robot</code>.
087 * @throws NullPointerException if the given robot is <code>null</code>.
088 * @throws NullPointerException if the given <code>Window</code> type is <code>null</code>.
089 * @throws ComponentLookupException if a <code>Window</code> having a matching name could not be found.
090 * @throws ComponentLookupException if more than one <code>Window</code> having a matching name is found.
091 */
092 public WindowFixture(Robot robot, String name, Class<? extends T> type) {
093 super(robot, name, type);
094 }
095
096 /**
097 * Creates a new <code>{@link WindowFixture}</code>. This constructor creates a new <code>{@link Robot}</code>
098 * containing the current AWT hierarchy.
099 * @param target the <code>Window</code> to be managed by this fixture.
100 * @throws NullPointerException if the given target <code>Window</code> is <code>null</code>.
101 */
102 public WindowFixture(T target) {
103 this(robotWithCurrentAwtHierarchy(), target);
104 }
105
106 /**
107 * Creates a new <code>{@link WindowFixture}</code>.
108 * @param robot performs simulation of user events on the given <code>Window</code>.
109 * @param target the <code>Window</code> to be managed by this fixture.
110 * @throws NullPointerException if the given robot is <code>null</code>.
111 * @throws NullPointerException if the given target <code>Window</code> is <code>null</code>.
112 */
113 public WindowFixture(Robot robot, T target) {
114 super(robot, target);
115 }
116
117 /**
118 * Shows this fixture's <code>{@link Window}</code>.
119 * @return this fixture.
120 */
121 protected abstract WindowFixture<T> show();
122
123 /**
124 * Shows this fixture's <code>{@link Window}</code>, resized to the given size.
125 * @param size the size to resize this fixture's <code>Window</code> to.
126 * @return this fixture.
127 */
128 protected abstract WindowFixture<T> show(Dimension size);
129
130 /**
131 * Cleans up any used resources (keyboard, mouse, open windows and <code>{@link ScreenLock}</code>) used by this
132 * robot.
133 */
134 public final void cleanUp() {
135 robot.cleanUp();
136 }
137 }