Repository navigation
Expand file tree
/
Copy pathRouteForwardingTest.java
More file actions
135 lines (117 loc) · 3.71 KB
/
Copy pathRouteForwardingTest.java
File metadata and controls
135 lines (117 loc) · 3.71 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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
package org.jooby;
import static org.easymock.EasyMock.expect;
import static org.junit.Assert.assertEquals;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.jooby.test.MockUnit;
import org.junit.Test;
public class RouteForwardingTest {
@Test
public void consumes() throws Exception {
List<MediaType> consumes = Arrays.asList(MediaType.js);
new MockUnit(Route.class)
.expect(unit -> {
Route route = unit.get(Route.class);
expect(route.consumes()).andReturn(consumes);
})
.run(unit -> {
assertEquals(consumes, new Route.Forwarding(unit.get(Route.class)).consumes());
});
}
@Test
public void produces() throws Exception {
List<MediaType> produces = Arrays.asList(MediaType.js);
new MockUnit(Route.class)
.expect(unit -> {
Route route = unit.get(Route.class);
expect(route.produces()).andReturn(produces);
})
.run(unit -> {
assertEquals(produces, new Route.Forwarding(unit.get(Route.class)).produces());
});
}
@Test
public void name() throws Exception {
new MockUnit(Route.class)
.expect(unit -> {
Route route = unit.get(Route.class);
expect(route.name()).andReturn("xXX");
})
.run(unit -> {
assertEquals("xXX", new Route.Forwarding(unit.get(Route.class)).name());
});
}
@Test
public void path() throws Exception {
new MockUnit(Route.class)
.expect(unit -> {
Route route = unit.get(Route.class);
expect(route.path()).andReturn("/xXX");
})
.run(unit -> {
assertEquals("/xXX", new Route.Forwarding(unit.get(Route.class)).path());
});
}
@Test
public void pattern() throws Exception {
new MockUnit(Route.class)
.expect(unit -> {
Route route = unit.get(Route.class);
expect(route.pattern()).andReturn("/**/*");
})
.run(unit -> {
assertEquals("/**/*", new Route.Forwarding(unit.get(Route.class)).pattern());
});
}
@Test(expected = NullPointerException.class)
public void nullRoute() throws Exception {
new Route.Forwarding(null);
}
@Test
public void toStr() throws Exception {
new MockUnit(Route.class)
.run(unit -> {
assertEquals(unit.get(Route.class).toString(),
new Route.Forwarding(unit.get(Route.class)).toString());
});
}
@Test
public void verb() throws Exception {
new MockUnit(Route.class)
.expect(unit -> {
Route route = unit.get(Route.class);
expect(route.method()).andReturn("OPTIONS");
})
.run(unit -> {
assertEquals("OPTIONS", new Route.Forwarding(unit.get(Route.class)).method());
});
}
@Test
public void vars() throws Exception {
Map<Object, String> vars = new HashMap<>();
new MockUnit(Route.class)
.expect(unit -> {
Route route = unit.get(Route.class);
expect(route.vars()).andReturn(vars);
})
.run(unit -> {
assertEquals(vars, new Route.Forwarding(unit.get(Route.class)).vars());
});
}
@Test
public void unwrap() throws Exception {
new MockUnit(Route.class)
.run(unit -> {
Route route = unit.get(Route.class);
assertEquals(route, Route.Forwarding.unwrap(new Route.Forwarding(route)));
// 2 level
assertEquals(route,
Route.Forwarding.unwrap(new Route.Forwarding(new Route.Forwarding(route))));
// 3 level
assertEquals(route, Route.Forwarding.unwrap(new Route.Forwarding(new Route.Forwarding(
new Route.Forwarding(route)))));
});
}
}