forked from google/thread-weaver
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNameManagerTest.java
More file actions
63 lines (52 loc) · 1.79 KB
/
NameManagerTest.java
File metadata and controls
63 lines (52 loc) · 1.79 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
/*
* Copyright 2009 Weaver authors
*
* This code is part of the Weaver tutorial and may be freely used.
*/
import com.google.testing.threadtester.AnnotatedTestRunner;
import com.google.testing.threadtester.ThreadedAfter;
import com.google.testing.threadtester.ThreadedBefore;
import com.google.testing.threadtester.ThreadedMain;
import com.google.testing.threadtester.ThreadedSecondary;
import junit.framework.TestCase;
import java.util.Arrays;
import java.util.List;
/**
* Unit test for NameManager. Demonstrates use of
* {@link com.google.testing.threadtester.AnnotatedTestRunner}.
*
* @author alasdair.mackintosh@gmail.com (Alasdair Mackintosh)
*/
public class NameManagerTest extends TestCase {
private static final String HELLO = "Hello";
private volatile NameManager nameManager;
public void testPutIfAbsent() {
// Create an AnnotatedTestRunner that will run the threaded tests defined in
// this class. These tests are expected to makes calls to NameManager.
AnnotatedTestRunner runner = new AnnotatedTestRunner();
runner.runTests(this.getClass(), NameManager.class);
}
@ThreadedBefore
public void before() {
// Set up a new NameManager instance for the test
nameManager = new NameManager();
}
@ThreadedMain
public void main() {
// Add a new element to the list in the main test thread
nameManager.setNames(Arrays.asList("a", "b", "c"));
}
@ThreadedSecondary
public void secondary() {
// Add a new element to the list in the secondary test thread
nameManager.setNames(Arrays.asList("a", "b", "c"));
}
@ThreadedAfter
public void after() {
List<String> names = nameManager.getNames();
assertEquals(3, names.size());
assertEquals("a", names.get(0));
assertEquals("b", names.get(1));
assertEquals("c", names.get(2));
}
}