forked from jooby-project/jooby
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJsBootTest.java
More file actions
119 lines (102 loc) · 3.25 KB
/
JsBootTest.java
File metadata and controls
119 lines (102 loc) · 3.25 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
package org.jooby;
import static org.easymock.EasyMock.expect;
import java.io.File;
import java.util.function.Supplier;
import org.jooby.internal.js.JsJooby;
import org.jooby.test.MockUnit;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
@RunWith(PowerMockRunner.class)
@PrepareForTest({Jooby.class, File.class })
public class JsBootTest {
@BeforeClass
public static void before() {
System.setProperty("logback.configurationFile", "logback.xml");
}
@AfterClass
public static void after() {
System.setProperty("logback.configurationFile", "");
}
@SuppressWarnings("unchecked")
@Test
public void jsboot() throws Exception {
String jsfile = "app.js";
String[] args = new String[0];
new MockUnit(Jooby.class, Supplier.class)
.expect(unit -> {
Supplier<Jooby> supplier = unit.get(Supplier.class);
expect(supplier.get()).andReturn(unit.get(Jooby.class));
})
.expect(unit -> {
JsJooby js = unit.constructor(JsJooby.class)
.build();
File file = unit.constructor(File.class)
.args(String.class)
.build(jsfile);
expect(js.run(file)).andReturn(unit.get(Supplier.class));
})
.expect(unit -> {
Jooby jooby = unit.get(Jooby.class);
jooby.start(args);
})
.run(unit -> {
Jooby.main(args);
});
}
@SuppressWarnings("unchecked")
@Test
public void jsbootWith1Arg() throws Exception {
String jsfile = "app.js";
String[] args = {jsfile, "foo" };
new MockUnit(Jooby.class, Supplier.class)
.expect(unit -> {
Supplier<Jooby> supplier = unit.get(Supplier.class);
expect(supplier.get()).andReturn(unit.get(Jooby.class));
})
.expect(unit -> {
JsJooby js = unit.constructor(JsJooby.class)
.build();
File file = unit.constructor(File.class)
.args(String.class)
.build(jsfile);
expect(js.run(file)).andReturn(unit.get(Supplier.class));
})
.expect(unit -> {
Jooby jooby = unit.get(Jooby.class);
jooby.start("foo");
})
.run(unit -> {
Jooby.main(args);
});
}
@SuppressWarnings("unchecked")
@Test
public void jsbootWithArgs() throws Exception {
String jsfile = "app.js";
String[] args = {jsfile, "foo", "bar" };
new MockUnit(Jooby.class, Supplier.class)
.expect(unit -> {
Supplier<Jooby> supplier = unit.get(Supplier.class);
expect(supplier.get()).andReturn(unit.get(Jooby.class));
})
.expect(unit -> {
JsJooby js = unit.constructor(JsJooby.class)
.build();
File file = unit.constructor(File.class)
.args(String.class)
.build(jsfile);
expect(js.run(file)).andReturn(unit.get(Supplier.class));
})
.expect(unit -> {
Jooby jooby = unit.get(Jooby.class);
jooby.start("foo", "bar");
})
.run(unit -> {
Jooby.main(args);
});
}
}