chromium just returns 404 in case the URL has been revoked. Throw exceptions by ownself.
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.lang.annotation.Annotation;
21 import java.util.ArrayList;
22 import java.util.Arrays;
23 import java.util.List;
24 import org.apidesign.bck2brwsr.launcher.Launcher;
25 import org.apidesign.bck2brwsr.vmtest.impl.CompareCase;
26 import org.testng.annotations.Factory;
28 /** A TestNG {@link Factory} that seeks for {@link Compare} and {@link BrwsrTest} annotations
29 * in provided class and builds set of tests that verify the functionality of <b>Bck2Brwsr</b>
30 * based system. Use as:
32 * {@code @}{@link Factory} public static create() {
33 * return @{link VMTest}.{@link #create(java.lang.Class) create}(YourClass.class);
35 * where <code>YourClass</code> contains methods annotated with
36 * {@link Compare} and {@link BrwsrTest} annotations.
38 * @author Jaroslav Tulach <jtulach@netbeans.org>
40 public final class VMTest {
41 private final List<Class> classes = new ArrayList<>();
42 private final List<String> launcher = new ArrayList<>();
43 private Class<? extends Annotation> annotation = BrwsrTest.class;
48 /** Inspects <code>clazz</code> and for each method annotated by
49 * {@link Compare} or {@link BrwsrTest} creates
52 * Each {@link Compare} instance runs the test in different virtual
53 * machine and at the end they compare the results.
55 * Each {@link BrwsrTest} annotated method is executed once in {@link Launcher started
58 * @param clazz the class (or classes) to inspect
59 * @return the set of created tests
61 public static Object[] create(Class clazz) {
62 return newTests().withClasses(clazz).build();
65 /** Creates new builder for test execution. Continue with methods
66 * like {@link #withClasses(java.lang.Class[])} or {@link #withLaunchers(java.lang.String[])}.
67 * Finish the process by calling {@link #build()}.
69 * @return new instance of a builder
72 public static VMTest newTests() {
76 /** Adds class (or classes) to the test execution. The classes are inspected
77 * to contain methods annotated by
78 * {@link Compare} or {@link BrwsrTest}. Appropriate set of TestNG test
79 * cases is then created.
81 * Each {@link Compare} instance runs the test in different virtual
82 * machine and at the end they compare the results.
84 * Each {@link BrwsrTest} annotated method is executed once in {@link Launcher started
87 * @param classes one or more classes to inspect
90 public final VMTest withClasses(Class... classes) {
91 this.classes.addAll(Arrays.asList(classes));
95 /** Adds list of launchers that should be used to execute tests defined
96 * by {@link Compare} and {@link BrwsrTest} annotations. This value
97 * can be overrided by using <code>vmtest.brwsrs</code> property.
98 * List of supported launchers is available in the documentation of
101 * @param launcher names of one or more launchers to use for the execution
105 public final VMTest withLaunchers(String... launcher) {
106 this.launcher.addAll(Arrays.asList(launcher));
110 /** Specifies which annotation annotates the test methods
112 * default it is the {@link BrwsrTest} annotation. Methods in
113 * {@link #withClasses(java.lang.Class[]) test classes} annotated by
114 * this annotation will be executed.
116 * @param aClass an annotation class
120 public final VMTest withTestAnnotation(Class<? extends Annotation> aClass) {
121 if (!aClass.isAnnotation()) {
122 throw new IllegalStateException();
124 this.annotation = aClass;
128 /** Assembles the provided information into the final array of tests.
129 * @return array of TestNG tests
132 public final Object[] build() {
133 return CompareCase.create(
134 launcher.toArray(new String[0]),
135 classes.toArray(new Class[0]),