Clover Coverage Report - FEST Swing 1.2
Coverage timestamp: Tue Jun 1 2010 15:19:25 PDT
../../../../img/srcFileCovDistChart10.png 0% of files have more coverage
19   171   19   1
0   86   1   19
19     1  
1    
 
  JAppletDriver       Line # 44 19 0% 19 0 100% 1.0
 
No Tests
 
1    /*
2    * Created on Mar 30, 2010
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
5    * the License. You may obtain a copy of the License at
6    *
7    * http://www.apache.org/licenses/LICENSE-2.0
8    *
9    * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
10    * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11    * specific language governing permissions and limitations under the License.
12    *
13    * Copyright @2010 the original author or authors.
14    */
15    package org.fest.swing.driver;
16   
17    import static org.fest.swing.edt.GuiActionRunner.execute;
18   
19    import java.applet.AppletContext;
20    import java.net.URL;
21   
22    import javax.swing.JApplet;
23   
24    import org.fest.swing.annotation.RunsInEDT;
25    import org.fest.swing.core.Robot;
26    import org.fest.swing.edt.GuiQuery;
27    import org.fest.swing.edt.GuiTask;
28   
29    /**
30    * Understands functional testing of <code>{@link JApplet}</code>s:
31    * <ul>
32    * <li>user input simulation</li>
33    * <li>state verification</li>
34    * <li>property value query</li>
35    * </ul>
36    * This class is intended for internal use only. Please use the classes in the package
37    * <code>{@link org.fest.swing.fixture}</code> in your tests.
38    *
39    * @author Mel Llaguno
40    * @author Alex Ruiz
41    *
42    * @since 1.2
43    */
 
44    public class JAppletDriver extends ComponentDriver {
45   
46    /**
47    * Creates a new </code>{@link JAppletDriver}</code>.
48    * @param robot the robot to use simulate user input.
49    */
 
50  7 toggle public JAppletDriver(Robot robot) {
51  7 super(robot);
52    }
53   
54    /**
55    * Returns the <code>{@link AppletContext}</code> of the given <code>{@link JApplet}</code>.
56    * @param applet the given {@code JApplet}.
57    * @return the {@code AppletContext} of the given {@code JApplet}.
58    */
 
59  1 toggle @RunsInEDT
60    public AppletContext appletContextOf(JApplet applet) {
61  1 return appletContext(applet);
62    }
63   
 
64  1 toggle @RunsInEDT
65    private static AppletContext appletContext(final JApplet applet) {
66  1 return execute(new GuiQuery<AppletContext>() {
 
67  1 toggle protected AppletContext executeInEDT() {
68  1 return applet.getAppletContext();
69    }
70    });
71    }
72   
73    /**
74    * Requests the given <code>{@link JApplet}</code> to be resized.
75    * @param applet the given {@code JApplet}.
76    * @param width the new width.
77    * @param height the new height.
78    */
 
79  1 toggle @RunsInEDT
80    public void resize(JApplet applet, int width, int height) {
81  1 doResize(applet, width, height);
82    }
83   
 
84  1 toggle @RunsInEDT
85    private static void doResize(final JApplet applet, final int width, final int height) {
86  1 execute(new GuiTask() {
 
87  1 toggle protected void executeInEDT() {
88  1 applet.resize(width, height);
89    }
90    });
91    }
92   
93    /**
94    * Returns the URL of the directory that contains the given <code>{@link JApplet}</code>.
95    * @param applet the given {@code JApplet}.
96    * @return the URL of the directory that contains the given {@code JApplet}.
97    */
 
98  1 toggle @RunsInEDT
99    public URL codeBaseOf(JApplet applet) {
100  1 return codeBase(applet);
101    }
102   
 
103  1 toggle @RunsInEDT
104    private static URL codeBase(final JApplet applet) {
105  1 return execute(new GuiQuery<URL>() {
 
106  1 toggle protected URL executeInEDT() {
107  1 return applet.getCodeBase();
108    }
109    });
110    }
111   
112    /**
113    * Returns the URL of the document the given <code>{@link JApplet}</code> is embedded.
114    * @param applet the given {@code JApplet}.
115    * @return the URL of the document the given {@code JApplet} is embedded.
116    */
 
117  1 toggle @RunsInEDT
118    public URL documentBaseOf(JApplet applet) {
119  1 return documentBase(applet);
120    }
121   
 
122  1 toggle @RunsInEDT
123    private static URL documentBase(final JApplet applet) {
124  1 return execute(new GuiQuery<URL>() {
 
125  1 toggle protected URL executeInEDT() {
126  1 return applet.getDocumentBase();
127    }
128    });
129    }
130   
131    /**
132    * Returns the value of the named parameter in the given <code>{@link JApplet}</code> in the HTML tag, or
133    * <code>null</code> if not set.
134    * @param applet the given {@code JApplet}.
135    * @param parameterName a parameter name.
136    * @return the value of the named parameter in the given {code JApplet} in the HTML tag, or <code>null</code> if not
137    * set.
138    */
 
139  1 toggle @RunsInEDT
140    public String parameterValue(JApplet applet, String parameterName) {
141  1 return parameter(applet, parameterName);
142    }
143   
 
144  1 toggle @RunsInEDT
145    private static String parameter(final JApplet applet, final String parameterName) {
146  1 return execute(new GuiQuery<String>() {
 
147  1 toggle protected String executeInEDT() {
148  1 return applet.getParameter(parameterName);
149    }
150    });
151    }
152   
153    /**
154    * Indicates whether the given <code>{@link JApplet}</code> is active or not.
155    * @param applet the given {@code JApplet}.
156    * @return <code>true</code> if the given {@code JApplet} is active; <code>false</code> otherwise.
157    */
 
158  2 toggle @RunsInEDT
159    public boolean isActive(JApplet applet) {
160  2 return active(applet);
161    }
162   
 
163  2 toggle @RunsInEDT
164    private static boolean active(final JApplet applet) {
165  2 return execute(new GuiQuery<Boolean>() {
 
166  2 toggle protected Boolean executeInEDT() {
167  2 return applet.isActive();
168    }
169    });
170    }
171    }