forked from jooby-project/jooby
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIssue1786.java
More file actions
52 lines (44 loc) · 1.72 KB
/
Copy pathIssue1786.java
File metadata and controls
52 lines (44 loc) · 1.72 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
package tests;
import io.jooby.MockContext;
import io.jooby.MockRouter;
import io.jooby.StatusCode;
import io.jooby.apt.MvcModuleCompilerRunner;
import io.jooby.exception.MissingValueException;
import org.junit.jupiter.api.Test;
import source.Controller1786;
import source.Controller1786b;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
public class Issue1786 {
@Test
public void shouldThrowMissingValueExceptionIfRequiredStringParamNotSpecified() throws Exception {
new MvcModuleCompilerRunner(new Controller1786())
.module(app -> {
MockRouter router = new MockRouter(app);
assertThrows(MissingValueException.class, () -> router.get("/required-string-param"));
});
}
@Test
public void shouldThrowMissingValueExceptionIfRequiredParamNotSpecified() throws Exception {
new MvcModuleCompilerRunner(new Controller1786b())
.example(Expected1786b.class)
.module(app -> {
MockRouter router = new MockRouter(app);
assertThrows(MissingValueException.class, () -> router.get("/required-param"));
});
}
@Test
public void shouldReturnValueIfRequiredStringParamSpecified() throws Exception {
new MvcModuleCompilerRunner(new Controller1786())
.module(app -> {
final String expectedValue = "non-null string";
MockContext ctx = new MockContext();
ctx.setQueryString("value=" + expectedValue);
MockRouter router = new MockRouter(app);
router.get("/required-string-param", ctx, rsp -> {
assertEquals(StatusCode.OK, rsp.getStatusCode());
assertEquals(expectedValue, rsp.value());
});
});
}
}