/
AllInvocationsFinder.java
58 lines (50 loc) · 1.93 KB
/
AllInvocationsFinder.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
/*
* Copyright (c) 2007 Mockito contributors
* This program is made available under the terms of the MIT License.
*/
package org.mockito.internal.invocation.finder;
import java.util.*;
import org.mockito.internal.invocation.InvocationComparator;
import org.mockito.internal.stubbing.StubbingComparator;
import org.mockito.internal.util.DefaultMockingDetails;
import org.mockito.invocation.Invocation;
import org.mockito.stubbing.Stubbing;
public class AllInvocationsFinder {
private AllInvocationsFinder() {}
/**
* gets all invocations from mocks. Invocations are ordered earlier first.
*
* @param mocks mocks
* @return invocations
*/
public static List<Invocation> find(Iterable<?> mocks) {
Set<Invocation> invocationsInOrder = new TreeSet<Invocation>(new InvocationComparator());
for (Object mock : mocks) {
Collection<Invocation> fromSingleMock =
new DefaultMockingDetails(mock).getInvocations();
invocationsInOrder.addAll(fromSingleMock);
}
return new LinkedList<Invocation>(invocationsInOrder);
}
/**
* Gets all stubbings from mocks. Invocations are ordered earlier first.
*
* @param mocks mocks
* @return stubbings
*/
public static Set<Stubbing> findStubbings(Iterable<?> mocks) {
Set<Stubbing> stubbings = new TreeSet<Stubbing>(new StubbingComparator());
for (Object mock : mocks) {
// TODO due to the limited scope of static mocks they cannot be processed
// it would rather be required to trigger this stubbing control upon releasing
// the static mock.
if (mock instanceof Class<?>) {
continue;
}
Collection<? extends Stubbing> fromSingleMock =
new DefaultMockingDetails(mock).getStubbings();
stubbings.addAll(fromSingleMock);
}
return stubbings;
}
}