-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
/
DefaultRegisteredInvocations.java
65 lines (54 loc) · 1.73 KB
/
DefaultRegisteredInvocations.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
/*
* Copyright (c) 2007 Mockito contributors
* This program is made available under the terms of the MIT License.
*/
package org.mockito.internal.verification;
import static org.mockito.internal.util.ObjectMethodsGuru.isToStringMethod;
import java.io.Serializable;
import java.util.LinkedList;
import java.util.List;
import java.util.stream.Collectors;
import org.mockito.invocation.Invocation;
public class DefaultRegisteredInvocations implements RegisteredInvocations, Serializable {
private static final long serialVersionUID = -2674402327380736290L;
private final LinkedList<Invocation> invocations = new LinkedList<>();
@Override
public void add(Invocation invocation) {
synchronized (invocations) {
invocations.add(invocation);
}
}
@Override
public void removeLast() {
// TODO: add specific test for synchronization of this block (it is tested by
// InvocationContainerImplTest at the moment)
synchronized (invocations) {
if (!invocations.isEmpty()) {
invocations.removeLast();
}
}
}
@Override
public List<Invocation> getAll() {
List<Invocation> copiedList;
synchronized (invocations) {
copiedList = new LinkedList<>(invocations);
}
return copiedList
.stream()
.filter(invocation -> !isToStringMethod(invocation.getMethod()))
.collect(Collectors.toList());
}
@Override
public void clear() {
synchronized (invocations) {
invocations.clear();
}
}
@Override
public boolean isEmpty() {
synchronized (invocations) {
return invocations.isEmpty();
}
}
}