-
Notifications
You must be signed in to change notification settings - Fork 1
/
TestParallel.java
56 lines (47 loc) · 1.92 KB
/
TestParallel.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
package arclibrary.utils.events;
import lombok.*;
import lombok.experimental.*;
import org.junit.*;
public class TestParallel{
@Test
public void notOverlaps(){
boolean[] visited = {false, false};
EventSender<EventData> senderA = new EventSender<>("methodA", EventData.signature);
EventReceiver<EventData> receiverA = EventReceiver.from(senderA);
EventSender<EventData> senderB = new EventSender<>("methodB", EventData.signature);
EventReceiver<EventData> receiverB = EventReceiver.from(senderB);
String expectedA = new EventData("a", 1).toString();
String expectedB = new EventData("b", 2).toString();
receiverA.postObject(data -> {
Assert.assertEquals(expectedA, data.toString());
Assert.assertFalse("methodA invokes twice", visited[0]);
visited[0] = true;
});
receiverB.postObject(data -> {
Assert.assertEquals(expectedB, data.toString());
Assert.assertFalse("methodB invokes twice", visited[1]);
visited[1] = true;
});
senderA.setParameters(new EventData("a",1));
senderA.fire();
senderB.setParameters(new EventData("b",2));
senderB.fire();
Assert.assertTrue("methodA not invoked",visited[0]);
Assert.assertTrue("methodB not invoked",visited[1]);
visited[0]=visited[1]=false;
senderB.setParameters(new EventData("b",2));
senderB.fire();
senderA.setParameters(new EventData("a",1));
senderA.fire();
Assert.assertTrue("methodA not invoked",visited[0]);
Assert.assertTrue("methodB not invoked",visited[1]);
}
@AllArgsConstructor
@ToString
@FieldDefaults(level = AccessLevel.PUBLIC)
private static class EventData{
static final EventSignature<EventData> signature = EventSignature.fromClass(EventData.class);
String title;
int id;
}
}