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
11   108   7   2.2
2   33   0.64   5
5     1.4  
1    
 
  ApplicationLauncher       Line # 55 11 0% 7 0 100% 1.0
 
No Tests
 
1    /*
2    * Created on May 23, 2008
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5    * in compliance with 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
10    * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11    * or implied. See the License for the specific language governing permissions and limitations under
12    * the License.
13    *
14    * Copyright @2008-2010 the original author or authors.
15    */
16    package org.fest.swing.launcher;
17   
18    import static org.fest.reflect.core.Reflection.staticMethod;
19    import static org.fest.swing.util.Arrays.copyOf;
20    import static org.fest.util.Strings.concat;
21    import static org.fest.util.Strings.quote;
22   
23    import org.fest.reflect.exception.ReflectionError;
24    import org.fest.swing.exception.UnexpectedException;
25   
26    /**
27    * Understands execution of a Java application from a class that has a "main" method.
28    * <p>
29    * The following example shows how to start an application without any arguments:
30    *
31    * <pre>
32    * ApplicationLauncher.application(JavaApp.class).start();
33    *
34    * // or
35    *
36    * ApplicationLauncher.{@link #application(String) application}(&quot;org.fest.swing.application.JavaApp&quot;).{@link #start() start}();
37    * </pre>
38    *
39    * </p>
40    * <p>
41    * The following example shows how to start an application with arguments:
42    *
43    * <pre>
44    * ApplicationLauncher.{@link #application(Class) application}(JavaApp.class).{@link #withArgs(String...) withArgs}(&quot;arg1&quot;, &quot;arg2&quot;).{@link #start() start}();
45    *
46    * // or
47    *
48    * ApplicationLauncher.{@link #application(String) application}(&quot;org.fest.swing.application.JavaApp&quot;).{@link #withArgs(String...) withArgs}(&quot;arg1&quot;, &quot;arg2&quot;).{@link #start() start}();
49    * </pre>
50    *
51    * </p>
52    *
53    * @author Yvonne Wang
54    */
 
55    public class ApplicationLauncher {
56   
57    /**
58    * Starting point of the fluent interface.
59    * @param applicationTypeName the fully qualified name of the class containing the "main" method.
60    * @return the created <code>ApplicationStarter</code>.
61    * @throws UnexpectedException if the class specified in the given name cannot be loaded.
62    */
 
63  2 toggle public static ApplicationLauncher application(String applicationTypeName) {
64  2 try {
65  2 Class<?> applicationType = Thread.currentThread().getContextClassLoader().loadClass(applicationTypeName);
66  1 return application(applicationType);
67    } catch (ClassNotFoundException e) {
68  1 throw new UnexpectedException(concat("Unable to load class ", quote(applicationTypeName)), e);
69    }
70    }
71   
72    /**
73    * Starting point of the fluent interface.
74    * @param applicationType the class containing the "main" method.
75    * @return the created <code>ApplicationStarter</code>.
76    */
 
77  4 toggle public static ApplicationLauncher application(Class<?> applicationType) {
78  4 return new ApplicationLauncher(applicationType);
79    }
80   
81    private final Class<?> applicationType;
82    private String[] args = new String[0];
83   
 
84  4 toggle private ApplicationLauncher(Class<?> applicationType) {
85  4 this.applicationType = applicationType;
86    }
87   
88    /**
89    * Specifies the arguments to pass to the "main" method. Please note that the arguments to pass are specific to your
90    * application. JVM-specific arguments are ignored (e.g. -Xms, -Xmx)
91    * @param newArgs the arguments to pass to the "main" method.
92    * @return this <code>ApplicationStarter</code>.
93    * @throws NullPointerException if <code>newArgs</code> is <code>null</code>.
94    */
 
95  2 toggle public ApplicationLauncher withArgs(String...newArgs) {
96  1 if (newArgs == null) throw new NullPointerException("The array of arguments should not be null");
97  1 args = copyOf(newArgs);
98  1 return this;
99    }
100   
101    /**
102    * Starts the application.
103    * @throws ReflectionError if the "main" method cannot be invoked.
104    */
 
105  3 toggle public void start() {
106  3 staticMethod("main").withParameterTypes(String[].class).in(applicationType).invoke(new Object[] { args });
107    }
108    }