forked from jooby-project/jooby
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLifeCycleTest.java
More file actions
85 lines (68 loc) · 2.22 KB
/
LifeCycleTest.java
File metadata and controls
85 lines (68 loc) · 2.22 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
package org.jooby;
import java.io.IOException;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import org.junit.Test;
public class LifeCycleTest {
static class ShouldNotAllowStaticMethod {
@PostConstruct
public static void start() {
}
}
static class ShouldNotAllowPrivateMethod {
@PreDestroy
private void destroy() {
}
}
static class ShouldNotAllowMethodWithArguments {
@PostConstruct
public void start(final int arg) {
}
}
static class ShouldNotAllowMethodWithReturnType {
@PostConstruct
public String start() {
return null;
}
}
static class ShouldNotWrapRuntimeException {
@PostConstruct
public void start() {
throw new RuntimeException("intetional err");
}
}
static class ShouldWrapNoRuntimeException {
@PostConstruct
public void start() throws IOException {
throw new IOException("intetional err");
}
}
@Test(expected = IllegalArgumentException.class)
public void noStaticMethod() {
LifeCycle.lifeCycleAnnotation(ShouldNotAllowStaticMethod.class, PostConstruct.class);
}
@Test(expected = IllegalArgumentException.class)
public void shouldNotAllowPrivateMethod() {
LifeCycle.lifeCycleAnnotation(ShouldNotAllowPrivateMethod.class, PreDestroy.class);
}
@Test(expected = IllegalArgumentException.class)
public void shouldNotAllowMethodWithArguments() {
LifeCycle.lifeCycleAnnotation(ShouldNotAllowMethodWithArguments.class, PostConstruct.class);
}
@Test(expected = IllegalArgumentException.class)
public void shouldNotAllowMethodWithReturnType() {
LifeCycle.lifeCycleAnnotation(ShouldNotAllowMethodWithReturnType.class, PostConstruct.class);
}
@Test(expected = RuntimeException.class)
public void shouldNotWrapRuntimeExceptin() throws Throwable {
LifeCycle.lifeCycleAnnotation(ShouldNotWrapRuntimeException.class, PostConstruct.class)
.get().accept(new ShouldNotWrapRuntimeException());
;
}
@Test(expected = IllegalStateException.class)
public void shouldWrapException() throws Throwable {
LifeCycle.lifeCycleAnnotation(ShouldWrapNoRuntimeException.class, PostConstruct.class)
.get().accept(new ShouldWrapNoRuntimeException());
;
}
}