Skip to content

Instantly share code, notes, and snippets.

@rhiguchi
Created January 11, 2011 03:32
Show Gist options
  • Save rhiguchi/773970 to your computer and use it in GitHub Desktop.
Save rhiguchi/773970 to your computer and use it in GitHub Desktop.
/**
* Creating a instance by using FEST Reflection for testing of Swing Application Framework
* require import static org.fest.reflect.core.Reflection.*;
*/
protected static <C extends Application> C createApplicationInstance(Class<C> appClass, String[] args) {
C application =
staticMethod("create")
.withReturnType(appClass)
.withParameterTypes(Class.class)
.in(appClass)
.invoke(appClass);
method("initialize")
.withParameterTypes(String[].class)
.in(application)
.invoke((Object)args);
method("startup").in(application).invoke();
return application;
}
@rhiguchi
Copy link
Author

Usage:

private static MyApplication application;

@BeforeClass
public static void setUpBeforeClass() {
    final String[] args = new String[]{};
    application = GuiActionRunner.execute(new GuiQuery<MyApplication>(){
        protected MyApplication executeInEDT() throws Throwable {
            MyApplication application = 
                createApplicationInstance(MyApplication.class, args);

            // Remove slashes if you like.
            //method("waitForReady").in(application).invoke();
            return application;
        }}
    );
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment