# HG changeset patch # User Jaroslav Tulach # Date 1367181509 -7200 # Node ID 6415da7d00b6ae53c7ab679c95359d1dd7150f6b # Parent 4f619536533fe74573b4b4ed17d5909157d6fd0c Turning VMTest into a builder pattern diff -r 4f619536533f -r 6415da7d00b6 rt/vmtest/src/main/java/org/apidesign/bck2brwsr/vmtest/VMTest.java --- a/rt/vmtest/src/main/java/org/apidesign/bck2brwsr/vmtest/VMTest.java Sun Apr 28 22:15:00 2013 +0200 +++ b/rt/vmtest/src/main/java/org/apidesign/bck2brwsr/vmtest/VMTest.java Sun Apr 28 22:38:29 2013 +0200 @@ -17,6 +17,9 @@ */ package org.apidesign.bck2brwsr.vmtest; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; import org.apidesign.bck2brwsr.launcher.Launcher; import org.apidesign.bck2brwsr.vmtest.impl.CompareCase; import org.testng.annotations.Factory; @@ -34,6 +37,9 @@ * @author Jaroslav Tulach */ public final class VMTest { + private final List classes = new ArrayList<>(); + private final List launcher = new ArrayList<>(); + private VMTest() { } @@ -50,7 +56,63 @@ * @param clazz the class (or classes) to inspect * @return the set of created tests */ - public static Object[] create(Class... clazz) { - return CompareCase.create(clazz); + public static Object[] create(Class clazz) { + return newTests().addClass(clazz).build(); + } + + /** Creates new builder for test execution. Continue with methods + * like {@link #addClass(java.lang.Class[])} or {@link #addLauncher(java.lang.String[])}. + * Finish the process by calling {@link #build()}. + * + * @return new instance of a builder + * @since 0.7 + */ + public static VMTest newTests() { + return new VMTest(); + } + + /** Adds class (or classes) to the test execution. The classes are inspected + * to contain methods annotated by + * {@link Compare} or {@link BrwsrTest}. Appropriate set of TestNG test + * cases is then created. + *

+ * Each {@link Compare} instance runs the test in different virtual + * machine and at the end they compare the results. + *

+ * Each {@link BrwsrTest} annotated method is executed once in {@link Launcher started + * browser}. + * + * @param classes one or more classes to inspect + * @since 0.7 + */ + public final VMTest addClass(Class... classes) { + this.classes.addAll(Arrays.asList(classes)); + return this; + } + + /** Adds list of launchers that should be used to execute tests defined + * by {@link Compare} and {@link BrwsrTest} annotations. This value + * can be overrided by using vmtest.brwsrs property. + * List of supported launchers is available in the documentation of + * {@link Launcher}. + * + * @param launcher names of one or more launchers to use for the execution + * of tests + * @since 0.7 + */ + public final VMTest addLauncher(String... launcher) { + this.launcher.addAll(Arrays.asList(launcher)); + return this; + } + + /** Assembles the provided information into the final array of tests. + * @return array of TestNG tests + * @since 0.7 + */ + public final Object[] build() { + return CompareCase.create( + launcher.toArray(new String[0]), + classes.toArray(new Class[0]) + ); } } diff -r 4f619536533f -r 6415da7d00b6 rt/vmtest/src/main/java/org/apidesign/bck2brwsr/vmtest/impl/CompareCase.java --- a/rt/vmtest/src/main/java/org/apidesign/bck2brwsr/vmtest/impl/CompareCase.java Sun Apr 28 22:15:00 2013 +0200 +++ b/rt/vmtest/src/main/java/org/apidesign/bck2brwsr/vmtest/impl/CompareCase.java Sun Apr 28 22:38:29 2013 +0200 @@ -53,19 +53,16 @@ * @param clazz the class to inspect * @return the set of created tests */ - public static Object[] create(Class... classes) { + public static Object[] create(String[] brwsr, Class[] classes) { List ret = new ArrayList<>(); final LaunchSetup l = LaunchSetup.INSTANCE; ret.add(l); - String[] brwsr; { String p = System.getProperty("vmtest.brwsrs"); if (p != null) { brwsr = p.split(","); - } else { - brwsr = new String[0]; } }