-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestIntegration.java
More file actions
89 lines (71 loc) · 2.92 KB
/
Copy pathTestIntegration.java
File metadata and controls
89 lines (71 loc) · 2.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package integration;
import integration.test.TestEventExecution;
import model.integration.TestBootstrapper;
import model.integration.service.TestService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.reflections8.Reflections;
import org.reflections8.scanners.SubTypesScanner;
import org.reflections8.scanners.TypeAnnotationsScanner;
import org.reflections8.util.ConfigurationBuilder;
import org.reflections8.util.FilterBuilder;
import institute.isshoni.winry.api.Winry;
import institute.isshoni.winry.api.annotation.Bootstrap;
import institute.isshoni.winry.internal.WinryContext;
import java.util.Set;
import java.util.concurrent.ExecutionException;
import static org.junit.Assert.fail;
@RunWith(Parameterized.class)
public class TestIntegration {
// run specific bootstrapper for debugging
public static void main(String... args) {
new TestIntegration(TestEventExecution.class, "").testBootstrapper();
}
@Parameterized.Parameters(name = "{index} : {1}")
public static Object[][] testClasses() {
Reflections reflections = new Reflections(new ConfigurationBuilder()
.addScanners(new TypeAnnotationsScanner(), new SubTypesScanner(false))
.forPackages("integration.test")
.filterInputsBy(new FilterBuilder().includePackage("integration.test")));
Set<Class<?>> classes = reflections.getTypesAnnotatedWith(Bootstrap.class);
Object[][] objects = new Object[classes.size()][2];
int x = 0;
for (Class<?> clazz : classes) {
Bootstrap bootstrap = clazz.getAnnotation(Bootstrap.class);
objects[x][0] = clazz;
objects[x][1] = bootstrap.name();
x++;
}
return objects;
}
private final Class<?> bootstrapped;
public TestIntegration(Class<?> bootstrapped, String testName) {
this.bootstrapped = bootstrapped;
}
@Test
public void testBootstrapper() {
TestService service = new TestService();
try {
Winry.bootstrap(this.bootstrapped, new Object[] { service });
} catch (ExecutionException | InterruptedException e) {
e.printStackTrace();
fail("Bootstrap method threw an exception!");
}
if (!service.hasRun()) {
fail("No bootstrapped methods were executed!");
}
if (service.getFailureMessage() != null) {
fail(service.getFailureMessage());
}
WinryContext.getContextFor(service).ifPresentOrElse(context -> {
try {
if (!((TestBootstrapper) context.getBootstrapper()).hasRun()) {
fail("Bootstrapper didn't run.");
}
} catch (ClassCastException e) {
fail("Bootstrapper is not TestBootstrapper!");
}
}, () -> fail("Cannot get WinryContext from provided service object!"));
}
}