-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
Copy pathNestedTestContexts.java
66 lines (53 loc) · 1.49 KB
/
NestedTestContexts.java
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
package org.junit.lambda.proposal02.examples;
import org.junit.Before;
import org.junit.lambda.proposal02.Context;
import org.junit.lambda.proposal02.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertTrue;
/**
* Tests can be nested in hierarchies using nested context classes.
* The top level @Context annotation is optional to provide JUnit4 compatibility
* @Before, @After, @BeforeClass, @AfterClass work for every context
*/
@Context("Main Context")
public class NestedTestContexts {
Object it;
@Before
public void init() {
it = new Object() {
@Override
public String toString() {
return "object under test";
}
};
}
@Context("New object")
class SubContext1 {
@Test
public void testToString() {
assertEquals("object under test", it.toString());
}
@Test
public void testHashCode() {
assertTrue(it.hashCode() != 0);
}
}
@Context("Equality")
class SubContext2 {
Object other;
@Before
public void init() {
other = new Object() {
@Override
public String toString() {
return "other object";
}
};
}
@Test
public void differentObjectsAreDifferent() {
assertNotEquals(it, other);
}
}
}