This repository was archived by the owner on Mar 3, 2026. It is now read-only.
forked from jooby-project/jooby
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJoobyRunTest.java
More file actions
81 lines (68 loc) · 2.01 KB
/
JoobyRunTest.java
File metadata and controls
81 lines (68 loc) · 2.01 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
package org.jooby;
import static org.easymock.EasyMock.expect;
import java.util.Arrays;
import java.util.function.Supplier;
import org.jooby.test.MockUnit;
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, System.class })
public class JoobyRunTest {
@SuppressWarnings("serial")
public static class ArgEx extends RuntimeException {
public ArgEx(final String[] args) {
super(Arrays.toString(args));
}
}
public static class NoopApp extends Jooby {
@Override
public void start(final String... args) {
}
}
public static class NoopAppEx extends Jooby {
@Override
public void start(final String... args) {
throw new ArgEx(args);
}
}
@SuppressWarnings({"unchecked", "rawtypes" })
@Test
public void runSupplier() throws Exception {
String[] args = {};
new MockUnit(Supplier.class, Jooby.class)
.expect(unit -> {
Supplier supplier = unit.get(Supplier.class);
expect(supplier.get()).andReturn(unit.get(Jooby.class));
})
.expect(unit -> {
Jooby jooby = unit.get(Jooby.class);
jooby.start(args);
})
.run(unit -> {
Jooby.run(unit.get(Supplier.class), args);
});
}
@SuppressWarnings({"unchecked", "rawtypes" })
@Test
public void runSupplierArg() throws Exception {
String[] args = {"foo" };
new MockUnit(Supplier.class, Jooby.class)
.expect(unit -> {
Supplier supplier = unit.get(Supplier.class);
expect(supplier.get()).andReturn(unit.get(Jooby.class));
})
.expect(unit -> {
Jooby jooby = unit.get(Jooby.class);
jooby.start(args);
})
.run(unit -> {
Jooby.run(unit.get(Supplier.class), args);
});
}
@Test
public void runClass() throws Throwable {
Jooby.run(NoopApp.class);
}
}