2 * Back 2 Browser Bytecode Translator
3 * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, version 2 of the License.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. Look for COPYING file in the top folder.
16 * If not, see http://opensource.org/licenses/GPL-2.0.
18 package org.apidesign.bck2brwsr.vmtest;
20 import java.util.ArrayList;
21 import java.util.Arrays;
22 import java.util.List;
23 import org.apidesign.bck2brwsr.launcher.Launcher;
24 import org.apidesign.bck2brwsr.vmtest.impl.CompareCase;
25 import org.testng.annotations.Factory;
27 /** A TestNG {@link Factory} that seeks for {@link Compare} and {@link BrwsrTest} annotations
28 * in provided class and builds set of tests that verify the functionality of <b>Bck2Brwsr</b>
29 * based system. Use as:
31 * {@code @}{@link Factory} public static create() {
32 * return @{link VMTest}.{@link #create(java.lang.Class) create}(YourClass.class);
34 * where <code>YourClass</code> contains methods annotated with
35 * {@link Compare} and {@link BrwsrTest} annotations.
37 * @author Jaroslav Tulach <jtulach@netbeans.org>
39 public final class VMTest {
40 private final List<Class> classes = new ArrayList<>();
41 private final List<String> launcher = new ArrayList<>();
46 /** Inspects <code>clazz</code> and for each method annotated by
47 * {@link Compare} or {@link BrwsrTest} creates
50 * Each {@link Compare} instance runs the test in different virtual
51 * machine and at the end they compare the results.
53 * Each {@link BrwsrTest} annotated method is executed once in {@link Launcher started
56 * @param clazz the class (or classes) to inspect
57 * @return the set of created tests
59 public static Object[] create(Class clazz) {
60 return newTests().withClasses(clazz).build();
63 /** Creates new builder for test execution. Continue with methods
64 * like {@link #withClasses(java.lang.Class[])} or {@link #withLaunchers(java.lang.String[])}.
65 * Finish the process by calling {@link #build()}.
67 * @return new instance of a builder
70 public static VMTest newTests() {
74 /** Adds class (or classes) to the test execution. The classes are inspected
75 * to contain methods annotated by
76 * {@link Compare} or {@link BrwsrTest}. Appropriate set of TestNG test
77 * cases is then created.
79 * Each {@link Compare} instance runs the test in different virtual
80 * machine and at the end they compare the results.
82 * Each {@link BrwsrTest} annotated method is executed once in {@link Launcher started
85 * @param classes one or more classes to inspect
88 public final VMTest withClasses(Class... classes) {
89 this.classes.addAll(Arrays.asList(classes));
93 /** Adds list of launchers that should be used to execute tests defined
94 * by {@link Compare} and {@link BrwsrTest} annotations. This value
95 * can be overrided by using <code>vmtest.brwsrs</code> property.
96 * List of supported launchers is available in the documentation of
99 * @param launcher names of one or more launchers to use for the execution
103 public final VMTest withLaunchers(String... launcher) {
104 this.launcher.addAll(Arrays.asList(launcher));
108 /** Assembles the provided information into the final array of tests.
109 * @return array of TestNG tests
112 public final Object[] build() {
113 return CompareCase.create(
114 launcher.toArray(new String[0]),
115 classes.toArray(new Class[0])