mockito / mockito
Showing 194 of 202 files from the diff.

@@ -28,6 +28,7 @@
Loading
28 28
        this.invocationListeners = settings.getInvocationListeners();
29 29
    }
30 30
31 +
    @Override
31 32
    public Object handle(Invocation invocation) throws Throwable {
32 33
        try {
33 34
            Object returnedValue = mockHandler.handle(invocation);
@@ -61,10 +62,12 @@
Loading
61 62
        }
62 63
    }
63 64
65 +
    @Override
64 66
    public MockCreationSettings<T> getMockSettings() {
65 67
        return mockHandler.getMockSettings();
66 68
    }
67 69
70 +
    @Override
68 71
    public InvocationContainer getInvocationContainer() {
69 72
        return mockHandler.getInvocationContainer();
70 73
    }

@@ -68,12 +68,14 @@
Loading
68 68
69 69
    private final ListUtil.Filter<Field> notFinalOrStatic =
70 70
            new ListUtil.Filter<Field>() {
71 +
                @Override
71 72
                public boolean isOut(Field object) {
72 73
                    return Modifier.isFinal(object.getModifiers())
73 74
                            || Modifier.isStatic(object.getModifiers());
74 75
                }
75 76
            };
76 77
78 +
    @Override
77 79
    public boolean processInjection(
78 80
            Field injectMocksField, Object injectMocksFieldOwner, Set<Object> mockCandidates) {
79 81
        FieldInitializationReport report =

@@ -16,10 +16,12 @@
Loading
16 16
        this.prefix = prefix;
17 17
    }
18 18
19 +
    @Override
19 20
    public boolean matches(String actual) {
20 21
        return actual != null && actual.startsWith(prefix);
21 22
    }
22 23
24 +
    @Override
23 25
    public String toString() {
24 26
        return "startsWith(\"" + prefix + "\")";
25 27
    }

@@ -46,7 +46,7 @@
Loading
46 46
     */
47 47
    @SuppressWarnings("unchecked")
48 48
    private Set<Field> scan() {
49 -
        Set<Field> mockDependentFields = new HashSet<Field>();
49 +
        Set<Field> mockDependentFields = new HashSet<>();
50 50
        Field[] fields = clazz.getDeclaredFields();
51 51
        for (Field field : fields) {
52 52
            if (null != field.getAnnotation(InjectMocks.class)) {

@@ -37,30 +37,37 @@
Loading
37 37
        isAbstract = (method.getModifiers() & Modifier.ABSTRACT) != 0;
38 38
    }
39 39
40 +
    @Override
40 41
    public String getName() {
41 42
        return methodName;
42 43
    }
43 44
45 +
    @Override
44 46
    public Class<?> getReturnType() {
45 47
        return returnType;
46 48
    }
47 49
50 +
    @Override
48 51
    public Class<?>[] getParameterTypes() {
49 52
        return parameterTypes;
50 53
    }
51 54
55 +
    @Override
52 56
    public Class<?>[] getExceptionTypes() {
53 57
        return exceptionTypes;
54 58
    }
55 59
60 +
    @Override
56 61
    public boolean isVarArgs() {
57 62
        return isVarArgs;
58 63
    }
59 64
65 +
    @Override
60 66
    public boolean isAbstract() {
61 67
        return isAbstract;
62 68
    }
63 69
70 +
    @Override
64 71
    public Method getJavaMethod() {
65 72
        if (method != null) {
66 73
            return method;
@@ -92,20 +99,40 @@
Loading
92 99
93 100
    @Override
94 101
    public boolean equals(Object obj) {
95 -
        if (this == obj) return true;
96 -
        if (obj == null) return false;
97 -
        if (getClass() != obj.getClass()) return false;
102 +
        if (this == obj) {
103 +
            return true;
104 +
        }
105 +
        if (obj == null) {
106 +
            return false;
107 +
        }
108 +
        if (getClass() != obj.getClass()) {
109 +
            return false;
110 +
        }
98 111
        SerializableMethod other = (SerializableMethod) obj;
99 112
        if (declaringClass == null) {
100 -
            if (other.declaringClass != null) return false;
101 -
        } else if (!declaringClass.equals(other.declaringClass)) return false;
113 +
            if (other.declaringClass != null) {
114 +
                return false;
115 +
            }
116 +
        } else if (!declaringClass.equals(other.declaringClass)) {
117 +
            return false;
118 +
        }
102 119
        if (methodName == null) {
103 -
            if (other.methodName != null) return false;
104 -
        } else if (!methodName.equals(other.methodName)) return false;
105 -
        if (!Arrays.equals(parameterTypes, other.parameterTypes)) return false;
120 +
            if (other.methodName != null) {
121 +
                return false;
122 +
            }
123 +
        } else if (!methodName.equals(other.methodName)) {
124 +
            return false;
125 +
        }
126 +
        if (!Arrays.equals(parameterTypes, other.parameterTypes)) {
127 +
            return false;
128 +
        }
106 129
        if (returnType == null) {
107 -
            if (other.returnType != null) return false;
108 -
        } else if (!returnType.equals(other.returnType)) return false;
130 +
            if (other.returnType != null) {
131 +
                return false;
132 +
            }
133 +
        } else if (!returnType.equals(other.returnType)) {
134 +
            return false;
135 +
        }
109 136
        return true;
110 137
    }
111 138
}

@@ -4,7 +4,7 @@
Loading
4 4
 */
5 5
package org.mockito.internal.reporting;
6 6
7 -
public class Pluralizer {
7 +
public final class Pluralizer {
8 8
9 9
    public static String pluralize(int number) {
10 10
        return number == 1 ? "1 time" : number + " times";
@@ -17,4 +17,6 @@
Loading
17 17
            return "were exactly " + x + " interactions";
18 18
        }
19 19
    }
20 +
21 +
    private Pluralizer() {}
20 22
}

@@ -12,10 +12,12 @@
Loading
12 12
13 13
    public static final Any ANY = new Any();
14 14
15 +
    @Override
15 16
    public boolean matches(Object actual) {
16 17
        return true;
17 18
    }
18 19
20 +
    @Override
19 21
    public String toString() {
20 22
        return "<any>";
21 23
    }

@@ -39,6 +39,7 @@
Loading
39 39
     */
40 40
    public static <T, A> Answer<T> toAnswer(final Answer1<T, A> answer) {
41 41
        return new Answer<T>() {
42 +
            @Override
42 43
            @SuppressWarnings("unchecked")
43 44
            public T answer(InvocationOnMock invocation) throws Throwable {
44 45
                return answer.answer((A) invocation.getArgument(0));
@@ -54,6 +55,7 @@
Loading
54 55
     */
55 56
    public static <A> Answer<Void> toAnswer(final VoidAnswer1<A> answer) {
56 57
        return new Answer<Void>() {
58 +
            @Override
57 59
            @SuppressWarnings("unchecked")
58 60
            public Void answer(InvocationOnMock invocation) throws Throwable {
59 61
                answer.answer((A) invocation.getArgument(0));
@@ -72,6 +74,7 @@
Loading
72 74
     */
73 75
    public static <T, A, B> Answer<T> toAnswer(final Answer2<T, A, B> answer) {
74 76
        return new Answer<T>() {
77 +
            @Override
75 78
            @SuppressWarnings("unchecked")
76 79
            public T answer(InvocationOnMock invocation) throws Throwable {
77 80
                return answer.answer((A) invocation.getArgument(0), (B) invocation.getArgument(1));
@@ -88,6 +91,7 @@
Loading
88 91
     */
89 92
    public static <A, B> Answer<Void> toAnswer(final VoidAnswer2<A, B> answer) {
90 93
        return new Answer<Void>() {
94 +
            @Override
91 95
            @SuppressWarnings("unchecked")
92 96
            public Void answer(InvocationOnMock invocation) throws Throwable {
93 97
                answer.answer((A) invocation.getArgument(0), (B) invocation.getArgument(1));
@@ -107,6 +111,7 @@
Loading
107 111
     */
108 112
    public static <T, A, B, C> Answer<T> toAnswer(final Answer3<T, A, B, C> answer) {
109 113
        return new Answer<T>() {
114 +
            @Override
110 115
            @SuppressWarnings("unchecked")
111 116
            public T answer(InvocationOnMock invocation) throws Throwable {
112 117
                return answer.answer(
@@ -127,6 +132,7 @@
Loading
127 132
     */
128 133
    public static <A, B, C> Answer<Void> toAnswer(final VoidAnswer3<A, B, C> answer) {
129 134
        return new Answer<Void>() {
135 +
            @Override
130 136
            @SuppressWarnings("unchecked")
131 137
            public Void answer(InvocationOnMock invocation) throws Throwable {
132 138
                answer.answer(
@@ -150,6 +156,7 @@
Loading
150 156
     */
151 157
    public static <T, A, B, C, D> Answer<T> toAnswer(final Answer4<T, A, B, C, D> answer) {
152 158
        return new Answer<T>() {
159 +
            @Override
153 160
            @SuppressWarnings("unchecked")
154 161
            public T answer(InvocationOnMock invocation) throws Throwable {
155 162
                return answer.answer(
@@ -172,6 +179,7 @@
Loading
172 179
     */
173 180
    public static <A, B, C, D> Answer<Void> toAnswer(final VoidAnswer4<A, B, C, D> answer) {
174 181
        return new Answer<Void>() {
182 +
            @Override
175 183
            @SuppressWarnings("unchecked")
176 184
            public Void answer(InvocationOnMock invocation) throws Throwable {
177 185
                answer.answer(
@@ -197,6 +205,7 @@
Loading
197 205
     */
198 206
    public static <T, A, B, C, D, E> Answer<T> toAnswer(final Answer5<T, A, B, C, D, E> answer) {
199 207
        return new Answer<T>() {
208 +
            @Override
200 209
            @SuppressWarnings("unchecked")
201 210
            public T answer(InvocationOnMock invocation) throws Throwable {
202 211
                return answer.answer(
@@ -221,6 +230,7 @@
Loading
221 230
     */
222 231
    public static <A, B, C, D, E> Answer<Void> toAnswer(final VoidAnswer5<A, B, C, D, E> answer) {
223 232
        return new Answer<Void>() {
233 +
            @Override
224 234
            @SuppressWarnings("unchecked")
225 235
            public Void answer(InvocationOnMock invocation) throws Throwable {
226 236
                answer.answer(
@@ -250,6 +260,7 @@
Loading
250 260
    public static <T, A, B, C, D, E, F> Answer<T> toAnswer(
251 261
            final Answer6<T, A, B, C, D, E, F> answer) {
252 262
        return new Answer<T>() {
263 +
            @Override
253 264
            @SuppressWarnings("unchecked")
254 265
            public T answer(InvocationOnMock invocation) throws Throwable {
255 266
                return answer.answer(
@@ -278,6 +289,7 @@
Loading
278 289
    public static <A, B, C, D, E, F> Answer<Void> toAnswer(
279 290
            final VoidAnswer6<A, B, C, D, E, F> answer) {
280 291
        return new Answer<Void>() {
292 +
            @Override
281 293
            @SuppressWarnings("unchecked")
282 294
            public Void answer(InvocationOnMock invocation) throws Throwable {
283 295
                answer.answer(

@@ -43,6 +43,7 @@
Loading
43 43
        return unused.size();
44 44
    }
45 45
46 +
    @Override
46 47
    public String toString() {
47 48
        return unused.toString();
48 49
    }
@@ -52,7 +53,7 @@
Loading
52 53
            return;
53 54
        }
54 55
55 -
        List<Invocation> invocations = new LinkedList<Invocation>();
56 +
        List<Invocation> invocations = new LinkedList<>();
56 57
        for (Stubbing stubbing : unused) {
57 58
            invocations.add(stubbing.getInvocation());
58 59
        }

@@ -21,7 +21,7 @@
Loading
21 21
 */
22 22
public class UnnecessaryStubbingsReporter implements MockCreationListener {
23 23
24 -
    private List<Object> mocks = new LinkedList<Object>();
24 +
    private final List<Object> mocks = new LinkedList<Object>();
25 25
26 26
    public void validateUnusedStubs(Class<?> testClass, RunNotifier notifier) {
27 27
        Collection<Invocation> unused =

@@ -33,6 +33,7 @@
Loading
33 33
                    public Object target;
34 34
                    private MockitoTestListener mockitoTestListener;
35 35
36 +
                    @Override
36 37
                    protected Statement withBefores(
37 38
                            FrameworkMethod method, final Object target, Statement statement) {
38 39
                        this.target = target;
@@ -101,14 +102,17 @@
Loading
101 102
                };
102 103
    }
103 104
105 +
    @Override
104 106
    public void run(final RunNotifier notifier) {
105 107
        runner.run(notifier);
106 108
    }
107 109
110 +
    @Override
108 111
    public Description getDescription() {
109 112
        return runner.getDescription();
110 113
    }
111 114
115 +
    @Override
112 116
    public void filter(Filter filter) throws NoTestsRemainException {
113 117
        runner.filter(filter);
114 118
    }

@@ -20,7 +20,7 @@
Loading
20 20
     * @param mocks full list of mocks
21 21
     */
22 22
    public List<Invocation> find(List<?> mocks) {
23 -
        List<Invocation> unused = new LinkedList<Invocation>();
23 +
        List<Invocation> unused = new LinkedList<>();
24 24
        for (Object mock : mocks) {
25 25
            List<Stubbing> fromSingleMock =
26 26
                    MockUtil.getInvocationContainer(mock).getStubbingsDescending();

@@ -31,7 +31,7 @@
Loading
31 31
            out += line(i.toString());
32 32
            out += line(" invoked: " + i.getLocation());
33 33
            if (i.stubInfo() != null) {
34 -
                out += line(" stubbed: " + i.stubInfo().stubbedAt().toString());
34 +
                out += line(" stubbed: " + i.stubInfo().stubbedAt());
35 35
            }
36 36
        }
37 37

@@ -40,11 +40,13 @@
Loading
40 40
                    "ReturnsElementsOf does not accept null as constructor argument.\n"
41 41
                            + "Please pass a collection instance");
42 42
        }
43 -
        this.elements = new LinkedList<Object>(elements);
43 +
        this.elements = new LinkedList<>(elements);
44 44
    }
45 45
46 +
    @Override
46 47
    public Object answer(InvocationOnMock invocation) throws Throwable {
47 -
        if (elements.size() == 1) return elements.get(0);
48 -
        else return elements.poll();
48 +
        if (elements.size() == 1) {
49 +
            return elements.get(0);
50 +
        } else return elements.poll();
49 51
    }
50 52
}

@@ -7,7 +7,15 @@
Loading
7 7
import static org.mockito.internal.creation.bytebuddy.MockMethodInterceptor.ForWriteReplace;
8 8
import static org.mockito.internal.util.StringUtil.join;
9 9
10 -
import java.io.*;
10 +
import java.io.ByteArrayInputStream;
11 +
import java.io.ByteArrayOutputStream;
12 +
import java.io.IOException;
13 +
import java.io.InputStream;
14 +
import java.io.ObjectInputStream;
15 +
import java.io.ObjectOutputStream;
16 +
import java.io.ObjectStreamClass;
17 +
import java.io.ObjectStreamException;
18 +
import java.io.Serializable;
11 19
import java.lang.reflect.Field;
12 20
import java.util.Set;
13 21
import java.util.concurrent.locks.Lock;

@@ -4,8 +4,6 @@
Loading
4 4
 */
5 5
package org.mockito.internal.matchers.text;
6 6
7 -
import static java.lang.String.valueOf;
8 -
9 7
import java.lang.reflect.Array;
10 8
import java.util.Iterator;
11 9
import java.util.Map;
@@ -58,6 +56,7 @@
Loading
58 56
                    new Iterator<Object>() {
59 57
                        private int currentIndex = 0;
60 58
59 +
                        @Override
61 60
                        public boolean hasNext() {
62 61
                            return currentIndex < Array.getLength(value);
63 62
                        }
@@ -89,7 +88,7 @@
Loading
89 88
                result.append(", ");
90 89
            }
91 90
        }
92 -
        return "{" + result.toString() + "}";
91 +
        return "{" + result + "}";
93 92
    }
94 93
95 94
    /**
@@ -149,8 +148,8 @@
Loading
149 148
150 149
    private static String descriptionOf(Object value) {
151 150
        try {
152 -
            return valueOf(value);
153 -
        } catch (Exception e) {
151 +
            return String.valueOf(value);
152 +
        } catch (RuntimeException e) {
154 153
            return value.getClass().getName() + "@" + Integer.toHexString(value.hashCode());
155 154
        }
156 155
    }

@@ -77,6 +77,7 @@
Loading
77 77
     *
78 78
     * @throws MockitoAssertionError if the delegate verification mode does not succeed before the timeout
79 79
     */
80 +
    @Override
80 81
    public void verify(VerificationData data) {
81 82
        AssertionError error = null;
82 83
@@ -90,8 +91,6 @@
Loading
90 91
                } else {
91 92
                    error = null;
92 93
                }
93 -
            } catch (MockitoAssertionError e) {
94 -
                error = handleVerifyException(e);
95 94
            } catch (AssertionError e) {
96 95
                error = handleVerifyException(e);
97 96
            }

@@ -21,9 +21,8 @@
Loading
21 21
    }
22 22
23 23
    public void find(FindingsListener findingsListener) {
24 -
        List<Invocation> unusedStubs = new LinkedList<Invocation>(this.baseUnusedStubs);
25 -
        List<InvocationMatcher> allInvocations =
26 -
                new LinkedList<InvocationMatcher>(this.baseAllInvocations);
24 +
        List<Invocation> unusedStubs = new LinkedList<>(this.baseUnusedStubs);
25 +
        List<InvocationMatcher> allInvocations = new LinkedList<>(this.baseAllInvocations);
27 26
28 27
        Iterator<Invocation> unusedIterator = unusedStubs.iterator();
29 28
        while (unusedIterator.hasNext()) {

@@ -4,14 +4,18 @@
Loading
4 4
 */
5 5
package org.mockito.internal.configuration.plugins;
6 6
7 -
import org.mockito.plugins.*;
8 -
9 7
import java.util.List;
8 +
import org.mockito.plugins.AnnotationEngine;
9 +
import org.mockito.plugins.InstantiatorProvider2;
10 +
import org.mockito.plugins.MemberAccessor;
11 +
import org.mockito.plugins.MockMaker;
12 +
import org.mockito.plugins.MockResolver;
13 +
import org.mockito.plugins.MockitoLogger;
14 +
import org.mockito.plugins.MockitoPlugins;
15 +
import org.mockito.plugins.StackTraceCleanerProvider;
10 16
11 -
/**
12 -
 * Access to Mockito behavior that can be reconfigured by plugins
13 -
 */
14 -
public class Plugins {
17 +
/** Access to Mockito behavior that can be reconfigured by plugins */
18 +
public final class Plugins {
15 19
16 20
    private static final PluginRegistry registry = new PluginRegistry();
17 21
@@ -88,4 +92,6 @@
Loading
88 92
    public static MockitoPlugins getPlugins() {
89 93
        return new DefaultMockitoPlugins();
90 94
    }
95 +
96 +
    private Plugins() {}
91 97
}

@@ -12,7 +12,7 @@
Loading
12 12
public class InstanceOf implements ArgumentMatcher<Object>, Serializable {
13 13
14 14
    private final Class<?> clazz;
15 -
    private String description;
15 +
    private final String description;
16 16
17 17
    public InstanceOf(Class<?> clazz) {
18 18
        this(clazz, "isA(" + clazz.getCanonicalName() + ")");
@@ -23,12 +23,14 @@
Loading
23 23
        this.description = describedAs;
24 24
    }
25 25
26 +
    @Override
26 27
    public boolean matches(Object actual) {
27 28
        return (actual != null)
28 29
                && (Primitives.isAssignableFromWrapper(actual.getClass(), clazz)
29 30
                        || clazz.isAssignableFrom(actual.getClass()));
30 31
    }
31 32
33 +
    @Override
32 34
    public String toString() {
33 35
        return description;
34 36
    }

@@ -14,10 +14,12 @@
Loading
14 14
15 15
    private NotNull() {}
16 16
17 +
    @Override
17 18
    public boolean matches(Object actual) {
18 19
        return actual != null;
19 20
    }
20 21
22 +
    @Override
21 23
    public String toString() {
22 24
        return "notNull()";
23 25
    }

@@ -23,7 +23,7 @@
Loading
23 23
        List<LocalizedMatcher> lastMatchers = argumentMatcherStorage.pullLocalizedMatchers();
24 24
        validateMatchers(invocation, lastMatchers);
25 25
26 -
        List<ArgumentMatcher> matchers = new LinkedList<ArgumentMatcher>();
26 +
        List<ArgumentMatcher> matchers = new LinkedList<>();
27 27
        for (LocalizedMatcher m : lastMatchers) {
28 28
            matchers.add(m.getMatcher());
29 29
        }

@@ -35,6 +35,7 @@
Loading
35 35
                filter(
36 36
                        stubbings,
37 37
                        new Filter<Stubbing>() {
38 +
                            @Override
38 39
                            public boolean isOut(Stubbing s) {
39 40
                                return !UnusedStubbingReporting.shouldBeReported(s);
40 41
                            }
@@ -58,7 +59,7 @@
Loading
58 59
59 60
        // 1st pass, collect all the locations of the stubbings that were used
60 61
        // note that those are _not_ locations where the stubbings was used
61 -
        Set<String> locationsOfUsedStubbings = new HashSet<String>();
62 +
        Set<String> locationsOfUsedStubbings = new HashSet<>();
62 63
        for (Stubbing s : stubbings) {
63 64
            if (!UnusedStubbingReporting.shouldBeReported(s)) {
64 65
                String location = s.getInvocation().getLocation().toString();
@@ -71,7 +72,7 @@
Loading
71 72
        // Also, using map to deduplicate reported unused stubbings
72 73
        // if unused stubbing appear in the setup method / constructor we don't want to report it
73 74
        // per each test case
74 -
        Map<String, Invocation> out = new LinkedHashMap<String, Invocation>();
75 +
        Map<String, Invocation> out = new LinkedHashMap<>();
75 76
        for (Stubbing s : stubbings) {
76 77
            String location = s.getInvocation().getLocation().toString();
77 78
            if (!locationsOfUsedStubbings.contains(location)) {

@@ -12,7 +12,8 @@
Loading
12 12
 * Compares invocations based on the sequence number
13 13
 */
14 14
public class InvocationComparator implements Comparator<Invocation> {
15 +
    @Override
15 16
    public int compare(Invocation o1, Invocation o2) {
16 -
        return Integer.valueOf(o1.getSequenceNumber()).compareTo(o2.getSequenceNumber());
17 +
        return Integer.compare(o1.getSequenceNumber(), o2.getSequenceNumber());
17 18
    }
18 19
}

@@ -16,6 +16,7 @@
Loading
16 16
        this.invocationContainer = invocationContainer;
17 17
    }
18 18
19 +
    @Override
19 20
    public OngoingStubbing<T> thenAnswer(Answer<?> answer) {
20 21
        invocationContainer.addConsecutiveAnswer(answer);
21 22
        return this;

@@ -21,7 +21,6 @@
Loading
21 21
import java.util.Map;
22 22
import java.util.Queue;
23 23
import java.util.Set;
24 -
25 24
import org.mockito.exceptions.base.MockitoException;
26 25
import org.mockito.internal.util.Checks;
27 26
@@ -70,11 +69,8 @@
Loading
70 69
71 70
    // public static MockitoLogger logger = new ConsoleMockitoLogger();
72 71
73 -
    /**
74 -
     * Represents actual type variables resolved for current class.
75 -
     */
76 -
    protected Map<TypeVariable<?>, Type> contextualActualTypeParameters =
77 -
            new HashMap<TypeVariable<?>, Type>();
72 +
    /** Represents actual type variables resolved for current class. */
73 +
    protected Map<TypeVariable<?>, Type> contextualActualTypeParameters = new HashMap<>();
78 74
79 75
    /**
80 76
     * Registers the type variables for the given type and all of its superclasses and superinterfaces.
@@ -245,8 +241,7 @@
Loading
245 241
     */
246 242
    public Map<TypeVariable<?>, Type> actualTypeArguments() {
247 243
        TypeVariable<?>[] typeParameters = rawType().getTypeParameters();
248 -
        LinkedHashMap<TypeVariable<?>, Type> actualTypeArguments =
249 -
                new LinkedHashMap<TypeVariable<?>, Type>();
244 +
        LinkedHashMap<TypeVariable<?>, Type> actualTypeArguments = new LinkedHashMap<>();
250 245
251 246
        for (TypeVariable<?> typeParameter : typeParameters) {
252 247
@@ -503,9 +498,10 @@
Loading
503 498
         * @return Returns an array with the extracted raw types of {@link #extraInterfaces()}.
504 499
         * @see #extractRawTypeOf(java.lang.reflect.Type)
505 500
         */
501 +
        @Override
506 502
        public Class<?>[] rawExtraInterfaces() {
507 503
            List<Type> extraInterfaces = extraInterfaces();
508 -
            List<Class<?>> rawExtraInterfaces = new ArrayList<Class<?>>();
504 +
            List<Class<?>> rawExtraInterfaces = new ArrayList<>();
509 505
            for (Type extraInterface : extraInterfaces) {
510 506
                Class<?> rawInterface = extractRawTypeOf(extraInterface);
511 507
                // avoid interface collision with actual raw type (with typevariables, resolution ca
@@ -634,6 +630,7 @@
Loading
634 630
        /**
635 631
         * @return either a class or an interface (parameterized or not), if no bounds declared Object is returned.
636 632
         */
633 +
        @Override
637 634
        public Type firstBound() {
638 635
            return typeVariable.getBounds()[0]; //
639 636
        }
@@ -645,6 +642,7 @@
Loading
645 642
         * @return other bounds for this type, these bounds can only be only interfaces as the JLS says,
646 643
         * empty array if no other bound declared.
647 644
         */
645 +
        @Override
648 646
        public Type[] interfaceBounds() {
649 647
            Type[] interfaceBounds = new Type[typeVariable.getBounds().length - 1];
650 648
            System.arraycopy(
@@ -658,8 +656,12 @@
Loading
658 656
659 657
        @Override
660 658
        public boolean equals(Object o) {
661 -
            if (this == o) return true;
662 -
            if (o == null || getClass() != o.getClass()) return false;
659 +
            if (this == o) {
660 +
                return true;
661 +
            }
662 +
            if (o == null || getClass() != o.getClass()) {
663 +
                return false;
664 +
            }
663 665
664 666
            return typeVariable.equals(((TypeVarBoundedType) o).typeVariable);
665 667
        }
@@ -698,9 +700,8 @@
Loading
698 700
            this.wildcard = wildcard;
699 701
        }
700 702
701 -
        /**
702 -
         * @return The first bound, either a type or a reference to a TypeVariable
703 -
         */
703 +
        /** @return The first bound, either a type or a reference to a TypeVariable */
704 +
        @Override
704 705
        public Type firstBound() {
705 706
            Type[] lowerBounds = wildcard.getLowerBounds();
706 707
            Type[] upperBounds = wildcard.getUpperBounds();
@@ -708,17 +709,20 @@
Loading
708 709
            return lowerBounds.length != 0 ? lowerBounds[0] : upperBounds[0];
709 710
        }
710 711
711 -
        /**
712 -
         * @return An empty array as, wildcard don't support multiple bounds.
713 -
         */
712 +
        /** @return An empty array as, wildcard don't support multiple bounds. */
713 +
        @Override
714 714
        public Type[] interfaceBounds() {
715 715
            return new Type[0];
716 716
        }
717 717
718 718
        @Override
719 719
        public boolean equals(Object o) {
720 -
            if (this == o) return true;
721 -
            if (o == null || getClass() != o.getClass()) return false;
720 +
            if (this == o) {
721 +
                return true;
722 +
            }
723 +
            if (o == null || getClass() != o.getClass()) {
724 +
                return false;
725 +
            }
722 726
723 727
            return wildcard.equals(((TypeVarBoundedType) o).typeVariable);
724 728
        }

@@ -23,6 +23,7 @@
Loading
23 23
    }
24 24
25 25
    private static class RemoveIgnoredForVerification implements Filter<Invocation> {
26 +
        @Override
26 27
        public boolean isOut(Invocation invocation) {
27 28
            return invocation.isIgnoredForVerification();
28 29
        }

@@ -12,20 +12,16 @@
Loading
12 12
import org.mockito.internal.matchers.ArrayEquals;
13 13
import org.mockito.internal.matchers.Equals;
14 14
15 -
/**
16 -
 * by Szczepan Faber, created at: 3/31/12
17 -
 */
18 -
public class ArgumentsProcessor {
15 +
/** by Szczepan Faber, created at: 3/31/12 */
16 +
public final class ArgumentsProcessor {
19 17
    // drops hidden synthetic parameters (last continuation parameter from Kotlin suspending
20 18
    // functions)
21 19
    // and expands varargs
22 20
    public static Object[] expandArgs(MockitoMethod method, Object[] args) {
23 21
        int nParams = method.getParameterTypes().length;
24 -
        if (args != null && args.length > nParams)
25 -
            args =
26 -
                    Arrays.copyOf(
27 -
                            args,
28 -
                            nParams); // drop extra args (currently -- Kotlin continuation synthetic
22 +
        if (args != null && args.length > nParams) {
23 +
            args = Arrays.copyOf(args, nParams);
24 +
        } // drop extra args (currently -- Kotlin continuation synthetic
29 25
        // arg)
30 26
        return expandVarArgs(method.isVarArgs(), args);
31 27
    }
@@ -35,7 +31,7 @@
Loading
35 31
    private static Object[] expandVarArgs(final boolean isVarArgs, final Object[] args) {
36 32
        if (!isVarArgs
37 33
                || isNullOrEmpty(args)
38 -
                || args[args.length - 1] != null && !args[args.length - 1].getClass().isArray()) {
34 +
                || (args[args.length - 1] != null && !args[args.length - 1].getClass().isArray())) {
39 35
            return args == null ? new Object[0] : args;
40 36
        }
41 37
@@ -59,7 +55,7 @@
Loading
59 55
    }
60 56
61 57
    public static List<ArgumentMatcher> argumentsToMatchers(Object[] arguments) {
62 -
        List<ArgumentMatcher> matchers = new ArrayList<ArgumentMatcher>(arguments.length);
58 +
        List<ArgumentMatcher> matchers = new ArrayList<>(arguments.length);
63 59
        for (Object arg : arguments) {
64 60
            if (arg != null && arg.getClass().isArray()) {
65 61
                matchers.add(new ArrayEquals(arg));
@@ -69,4 +65,6 @@
Loading
69 65
        }
70 66
        return matchers;
71 67
    }
68 +
69 +
    private ArgumentsProcessor() {}
72 70
}

@@ -58,11 +58,11 @@
Loading
58 58
     * @return An object of either {@code preferredPluginType} or {@code alternatePluginType}
59 59
     */
60 60
    @SuppressWarnings("unchecked")
61 -
    <PreferredType, AlternateType> Object loadPlugin(
62 -
            final Class<PreferredType> preferredPluginType,
61 +
    <PreferredT, AlternateType> Object loadPlugin(
62 +
            final Class<PreferredT> preferredPluginType,
63 63
            final Class<AlternateType> alternatePluginType) {
64 64
        try {
65 -
            PreferredType preferredPlugin = initializer.loadImpl(preferredPluginType);
65 +
            PreferredT preferredPlugin = initializer.loadImpl(preferredPluginType);
66 66
            if (preferredPlugin != null) {
67 67
                return preferredPlugin;
68 68
            } else if (alternatePluginType != null) {

@@ -19,6 +19,7 @@
Loading
19 19
20 20
public class Only implements VerificationMode {
21 21
22 +
    @Override
22 23
    @SuppressWarnings("unchecked")
23 24
    public void verify(VerificationData data) {
24 25
        MatchableInvocation target = data.getTarget();

@@ -18,10 +18,12 @@
Loading
18 18
        this.m2 = m2;
19 19
    }
20 20
21 +
    @Override
21 22
    public boolean matches(Object actual) {
22 23
        return m1.matches(actual) || m2.matches(actual);
23 24
    }
24 25
26 +
    @Override
25 27
    public String toString() {
26 28
        return "or(" + m1 + ", " + m2 + ")";
27 29
    }

@@ -57,6 +57,8 @@
Loading
57 57
        return DISPATCHERS.get(identifier).isConstructorMock(type);
58 58
    }
59 59
60 +
    public abstract boolean isConstructorMock(Class<?> type);
61 +
60 62
    @SuppressWarnings("unused")
61 63
    public static Object handleConstruction(
62 64
            String identifier,
@@ -85,6 +87,4 @@
Loading
85 87
    public abstract boolean isMockedStatic(Class<?> type);
86 88
87 89
    public abstract boolean isOverridden(Object instance, Method origin);
88 -
89 -
    public abstract boolean isConstructorMock(Class<?> type);
90 90
}

@@ -42,6 +42,7 @@
Loading
42 42
     *
43 43
     * @see org.mockito.plugins.AnnotationEngine#process(Class, Object)
44 44
     */
45 +
    @Override
45 46
    public AutoCloseable process(Class<?> clazz, Object testInstance) {
46 47
        List<AutoCloseable> closeables = new ArrayList<>();
47 48
        closeables.addAll(processIndependentAnnotations(testInstance.getClass(), testInstance));
@@ -104,7 +105,7 @@
Loading
104 105
     */
105 106
    private AutoCloseable injectCloseableMocks(final Object testClassInstance) {
106 107
        Class<?> clazz = testClassInstance.getClass();
107 -
        Set<Field> mockDependentFields = new HashSet<Field>();
108 +
        Set<Field> mockDependentFields = new HashSet<>();
108 109
        Set<Object> mocks = newMockSafeHashSet();
109 110
110 111
        while (clazz != Object.class) {

@@ -94,6 +94,7 @@
Loading
94 94
        return this;
95 95
    }
96 96
97 +
    @Override
97 98
    public Object answer(InvocationOnMock invocation) throws Throwable {
98 99
        return implementation.answer(invocation);
99 100
    }

@@ -6,7 +6,6 @@
Loading
6 6
7 7
import java.lang.ref.ReferenceQueue;
8 8
import java.util.Set;
9 -
import java.util.concurrent.Callable;
10 9
import java.util.concurrent.locks.ReadWriteLock;
11 10
import java.util.concurrent.locks.ReentrantReadWriteLock;
12 11
@@ -16,7 +15,7 @@
Loading
16 15
class TypeCachingBytecodeGenerator extends ReferenceQueue<ClassLoader>
17 16
        implements BytecodeGenerator {
18 17
19 -
    private final Object BOOTSTRAP_LOCK = new Object();
18 +
    private static final Object BOOTSTRAP_LOCK = new Object();
20 19
21 20
    private final BytecodeGenerator bytecodeGenerator;
22 21
@@ -27,7 +26,7 @@
Loading
27 26
    public TypeCachingBytecodeGenerator(BytecodeGenerator bytecodeGenerator, boolean weak) {
28 27
        this.bytecodeGenerator = bytecodeGenerator;
29 28
        typeCache =
30 -
                new TypeCache.WithInlineExpunction<MockitoMockKey>(
29 +
                new TypeCache.WithInlineExpunction<>(
31 30
                        weak ? TypeCache.Sort.WEAK : TypeCache.Sort.SOFT);
32 31
    }
33 32
@@ -45,12 +44,7 @@
Loading
45 44
                                    params.interfaces,
46 45
                                    params.serializableMode,
47 46
                                    params.stripAnnotations),
48 -
                            new Callable<Class<?>>() {
49 -
                                @Override
50 -
                                public Class<?> call() throws Exception {
51 -
                                    return bytecodeGenerator.mockClass(params);
52 -
                                }
53 -
                            },
47 +
                            () -> bytecodeGenerator.mockClass(params),
54 48
                            BOOTSTRAP_LOCK);
55 49
        } catch (IllegalArgumentException exception) {
56 50
            Throwable cause = exception.getCause();
@@ -102,9 +96,15 @@
Loading
102 96
103 97
        @Override
104 98
        public boolean equals(Object object) {
105 -
            if (this == object) return true;
106 -
            if (object == null || getClass() != object.getClass()) return false;
107 -
            if (!super.equals(object)) return false;
99 +
            if (this == object) {
100 +
                return true;
101 +
            }
102 +
            if (object == null || getClass() != object.getClass()) {
103 +
                return false;
104 +
            }
105 +
            if (!super.equals(object)) {
106 +
                return false;
107 +
            }
108 108
            MockitoMockKey that = (MockitoMockKey) object;
109 109
            return stripAnnotations == that.stripAnnotations
110 110
                    && serializableMode.equals(that.serializableMode);

@@ -39,8 +39,6 @@
Loading
39 39
        try {
40 40
            verification.verify(data);
41 41
42 -
        } catch (MockitoAssertionError e) {
43 -
            throw new MockitoAssertionError(e, description);
44 42
        } catch (AssertionError e) {
45 43
            throw new MockitoAssertionError(e, description);
46 44
        }

@@ -14,7 +14,7 @@
Loading
14 14
import org.mockito.mock.MockCreationSettings;
15 15
import org.mockito.stubbing.Stubbing;
16 16
17 -
public class StubbingLookupNotifier {
17 +
public final class StubbingLookupNotifier {
18 18
19 19
    public static void notifyStubbedAnswerLookup(
20 20
            Invocation invocation,
@@ -69,4 +69,6 @@
Loading
69 69
            return mockSettings;
70 70
        }
71 71
    }
72 +
73 +
    private StubbingLookupNotifier() {}
72 74
}

@@ -27,6 +27,7 @@
Loading
27 27
        this.resetBuilder();
28 28
    }
29 29
30 +
    @Override
30 31
    public Statement apply(final Statement base, final Description description) {
31 32
        return new Statement() {
32 33
            @Override
@@ -60,10 +61,12 @@
Loading
60 61
        }
61 62
    }
62 63
64 +
    @Override
63 65
    public VerificationCollector assertLazily() {
64 66
        mockingProgress()
65 67
                .setVerificationStrategy(
66 68
                        new VerificationStrategy() {
69 +
                            @Override
67 70
                            public VerificationMode maybeVerifyLazily(VerificationMode mode) {
68 71
                                return new VerificationWrapper(mode);
69 72
                            }
@@ -94,6 +97,7 @@
Loading
94 97
            this.delegate = delegate;
95 98
        }
96 99
100 +
        @Override
97 101
        public void verify(VerificationData data) {
98 102
            try {
99 103
                this.delegate.verify(data);
@@ -102,6 +106,7 @@
Loading
102 106
            }
103 107
        }
104 108
109 +
        @Override
105 110
        public VerificationMode description(String description) {
106 111
            throw new IllegalStateException("Should not fail in this mode");
107 112
        }

@@ -34,6 +34,7 @@
Loading
34 34
        this.currentStrictness = strictness;
35 35
    }
36 36
37 +
    @Override
37 38
    public void onStubbingLookup(StubbingLookupEvent event) {
38 39
        Strictness actualStrictness =
39 40
                determineStrictness(
@@ -64,7 +65,7 @@
Loading
64 65
65 66
    private static List<Invocation> potentialArgMismatches(
66 67
            Invocation invocation, Collection<Stubbing> stubbings) {
67 -
        List<Invocation> matchingStubbings = new LinkedList<Invocation>();
68 +
        List<Invocation> matchingStubbings = new LinkedList<>();
68 69
        for (Stubbing s : stubbings) {
69 70
            if (UnusedStubbingReporting.shouldBeReported(s)
70 71
                    && s.getInvocation()

@@ -24,7 +24,7 @@
Loading
24 24
    public Instantiator getInstantiator(final MockCreationSettings<?> settings) {
25 25
        return new Instantiator() {
26 26
            @Override
27 -
            public <T> T newInstance(Class<T> cls) throws InstantiationException {
27 +
            public <T> T newInstance(Class<T> cls) {
28 28
                try {
29 29
                    return provider.getInstantiator(settings).newInstance(cls);
30 30
                } catch (org.mockito.internal.creation.instance.InstantiationException e) {

@@ -28,10 +28,17 @@
Loading
28 28
import org.mockito.quality.Strictness;
29 29
import org.mockito.session.MockitoSessionBuilder;
30 30
import org.mockito.session.MockitoSessionLogger;
31 -
import org.mockito.stubbing.*;
32 -
import org.mockito.verification.*;
33 31
34 32
import java.util.function.Function;
33 +
import org.mockito.stubbing.Answer;
34 +
import org.mockito.stubbing.LenientStubber;
35 +
import org.mockito.stubbing.OngoingStubbing;
36 +
import org.mockito.stubbing.Stubber;
37 +
import org.mockito.verification.After;
38 +
import org.mockito.verification.Timeout;
39 +
import org.mockito.verification.VerificationAfterDelay;
40 +
import org.mockito.verification.VerificationMode;
41 +
import org.mockito.verification.VerificationWithTimeout;
35 42
36 43
/**
37 44
 * <p align="left"><img src="logo.png" srcset="logo@2x.png 2x" alt="Mockito logo"/></p>

@@ -18,6 +18,7 @@
Loading
18 18
        this.delta = delta;
19 19
    }
20 20
21 +
    @Override
21 22
    public boolean matches(Number actual) {
22 23
        if (wanted == null ^ actual == null) {
23 24
            return false;
@@ -31,6 +32,7 @@
Loading
31 32
                && actual.doubleValue() <= wanted.doubleValue() + delta.doubleValue();
32 33
    }
33 34
35 +
    @Override
34 36
    public String toString() {
35 37
        return "eq(" + wanted + ", " + delta + ")";
36 38
    }

@@ -30,7 +30,9 @@
Loading
30 30
     * {@link ClassCastException}.
31 31
     */
32 32
    private static boolean isCompatible(ArgumentMatcher<?> argumentMatcher, Object argument) {
33 -
        if (argument == null) return true;
33 +
        if (argument == null) {
34 +
            return true;
35 +
        }
34 36
35 37
        Class<?> expectedArgumentType = getArgumentType(argumentMatcher);
36 38

@@ -47,7 +47,7 @@
Loading
47 47
    }
48 48
49 49
    public static List<InvocationMatcher> createFrom(List<Invocation> invocations) {
50 -
        LinkedList<InvocationMatcher> out = new LinkedList<InvocationMatcher>();
50 +
        LinkedList<InvocationMatcher> out = new LinkedList<>();
51 51
        for (Invocation i : invocations) {
52 52
            out.add(new InvocationMatcher(i));
53 53
        }

@@ -63,7 +63,7 @@
Loading
63 63
64 64
    private static List<Invocation> getFirstMatchingChunk(
65 65
            MatchableInvocation wanted, List<Invocation> unverified) {
66 -
        List<Invocation> firstChunk = new LinkedList<Invocation>();
66 +
        List<Invocation> firstChunk = new LinkedList<>();
67 67
        for (Invocation invocation : unverified) {
68 68
            if (wanted.matches(invocation)) {
69 69
                firstChunk.add(invocation);
@@ -139,7 +139,7 @@
Loading
139 139
140 140
    private static List<Invocation> removeVerifiedInOrder(
141 141
            List<Invocation> invocations, InOrderContext orderingContext) {
142 -
        List<Invocation> unverified = new LinkedList<Invocation>();
142 +
        List<Invocation> unverified = new LinkedList<>();
143 143
        for (Invocation i : invocations) {
144 144
            if (orderingContext.isVerified(i)) {
145 145
                unverified.clear();
@@ -151,7 +151,7 @@
Loading
151 151
    }
152 152
153 153
    public static List<Location> getAllLocations(List<Invocation> invocations) {
154 -
        List<Location> locations = new LinkedList<Location>();
154 +
        List<Location> locations = new LinkedList<>();
155 155
        for (Invocation invocation : invocations) {
156 156
            locations.add(invocation.getLocation());
157 157
        }
@@ -165,6 +165,7 @@
Loading
165 165
            this.wanted = wanted;
166 166
        }
167 167
168 +
        @Override
168 169
        public boolean isOut(Invocation invocation) {
169 170
            return !wanted.matches(invocation);
170 171
        }
@@ -177,6 +178,7 @@
Loading
177 178
            this.orderingContext = orderingContext;
178 179
        }
179 180
181 +
        @Override
180 182
        public boolean isOut(Invocation invocation) {
181 183
            return !orderingContext.isVerified(invocation);
182 184
        }

@@ -11,7 +11,7 @@
Loading
11 11
/**
12 12
 * Helps determining the actual strictness given that it can be configured in multiple ways (at mock, at stubbing, in rule)
13 13
 */
14 -
public class StrictnessSelector {
14 +
public final class StrictnessSelector {
15 15
16 16
    /**
17 17
     * Determines the actual strictness in the following importance order:
@@ -37,4 +37,6 @@
Loading
37 37
38 38
        return testLevelStrictness;
39 39
    }
40 +
41 +
    private StrictnessSelector() {}
40 42
}

@@ -16,7 +16,7 @@
Loading
16 16
 */
17 17
class DoAnswerStyleStubbing implements Serializable {
18 18
19 -
    private final List<Answer<?>> answers = new ArrayList<Answer<?>>();
19 +
    private final List<Answer<?>> answers = new ArrayList<>();
20 20
    private Strictness stubbingStrictness;
21 21
22 22
    void setAnswers(List<Answer<?>> answers, Strictness stubbingStrictness) {

@@ -4,13 +4,13 @@
Loading
4 4
 */
5 5
package org.mockito;
6 6
7 +
import static org.mockito.internal.util.StringUtil.join;
8 +
7 9
import org.mockito.exceptions.base.MockitoException;
8 10
import org.mockito.internal.configuration.GlobalConfiguration;
9 11
import org.mockito.junit.MockitoJUnitRunner;
10 12
import org.mockito.plugins.AnnotationEngine;
11 13
12 -
import static org.mockito.internal.util.StringUtil.*;
13 -
14 14
/**
15 15
 * MockitoAnnotations.openMocks(this); initializes fields annotated with Mockito annotations.
16 16
 * See also {@link MockitoSession} which not only initializes mocks
@@ -61,7 +61,7 @@
Loading
61 61
 * If static method mocks are used, it is required to close the initialization. Additionally, if using third-party
62 62
 * mock-makers, other life-cycles might be handled by the open-release routine.
63 63
 */
64 -
public class MockitoAnnotations {
64 +
public final class MockitoAnnotations {
65 65
66 66
    /**
67 67
     * Initializes objects annotated with Mockito annotations for given testClass:
@@ -107,4 +107,6 @@
Loading
107 107
                    e);
108 108
        }
109 109
    }
110 +
111 +
    private MockitoAnnotations() {}
110 112
}

@@ -12,6 +12,7 @@
Loading
12 12
 */
13 13
public class DefaultStackTraceCleanerProvider implements StackTraceCleanerProvider {
14 14
15 +
    @Override
15 16
    public StackTraceCleaner getStackTraceCleaner(StackTraceCleaner defaultCleaner) {
16 17
        return defaultCleaner;
17 18
    }

@@ -28,6 +28,7 @@
Loading
28 28
        return createInvocation(target, settings, method, superMethod, args);
29 29
    }
30 30
31 +
    @Override
31 32
    public Invocation createInvocation(
32 33
            Object target,
33 34
            MockCreationSettings settings,

@@ -22,6 +22,7 @@
Loading
22 22
        this.value = value;
23 23
    }
24 24
25 +
    @Override
25 26
    public Object answer(InvocationOnMock invocation) throws Throwable {
26 27
        return value;
27 28
    }

@@ -18,10 +18,12 @@
Loading
18 18
        this.excludeFields = excludeFields;
19 19
    }
20 20
21 +
    @Override
21 22
    public boolean matches(Object actual) {
22 23
        return EqualsBuilder.reflectionEquals(wanted, actual, excludeFields);
23 24
    }
24 25
26 +
    @Override
25 27
    public String toString() {
26 28
        return "refEq(" + wanted + ")";
27 29
    }

@@ -30,6 +30,7 @@
Loading
30 30
        this.printStream = printStream;
31 31
    }
32 32
33 +
    @Override
33 34
    public void reportInvocation(MethodInvocationReport methodInvocationReport) {
34 35
        printHeader();
35 36
        printStubInfo(methodInvocationReport);
@@ -73,13 +74,13 @@
Loading
73 74
    }
74 75
75 76
    private void printInvocation(DescribedInvocation invocation) {
76 -
        printStream.println(invocation.toString());
77 +
        printStream.println(invocation);
77 78
        //        printStream.println("Handling method call on a mock/spy.");
78 -
        printlnIndented("invoked: " + invocation.getLocation().toString());
79 +
        printlnIndented("invoked: " + invocation.getLocation());
79 80
    }
80 81
81 82
    private void printFooter() {
82 -
        printStream.println("");
83 +
        printStream.println();
83 84
    }
84 85
85 86
    private void printlnIndented(String message) {

@@ -27,6 +27,7 @@
Loading
27 27
        this.testClass = testClass;
28 28
    }
29 29
30 +
    @Override
30 31
    public void run(RunNotifier notifier) {
31 32
        // TODO need to be able to opt in for full stack trace instead of just relying on the stack
32 33
        // trace filter
@@ -53,10 +54,12 @@
Loading
53 54
        }
54 55
    }
55 56
57 +
    @Override
56 58
    public Description getDescription() {
57 59
        return runner.getDescription();
58 60
    }
59 61
62 +
    @Override
60 63
    public void filter(Filter filter) throws NoTestsRemainException {
61 64
        filterRequested = true;
62 65
        runner.filter(filter);

@@ -17,10 +17,12 @@
Loading
17 17
        this.matcher = matcher;
18 18
    }
19 19
20 +
    @Override
20 21
    public boolean matches(Object actual) {
21 22
        return !matcher.matches(actual);
22 23
    }
23 24
25 +
    @Override
24 26
    public String toString() {
25 27
        return "not(" + matcher + ")";
26 28
    }

@@ -42,7 +42,7 @@
Loading
42 42
43 43
        this.wanted = printSettings.print(wanted);
44 44
45 -
        List<String> actuals = new ArrayList<String>();
45 +
        List<String> actuals = new ArrayList<>();
46 46
        for (Invocation actual : allActualInvocations) {
47 47
            actuals.add(printSettings.print(actual));
48 48
        }

@@ -25,6 +25,7 @@
Loading
25 25
     */
26 26
    OngoingInjector nop =
27 27
            new OngoingInjector() {
28 +
                @Override
28 29
                public Object thenInject() {
29 30
                    return null;
30 31
                }

@@ -16,10 +16,12 @@
Loading
16 16
        this.substring = substring;
17 17
    }
18 18
19 +
    @Override
19 20
    public boolean matches(String actual) {
20 21
        return actual != null && actual.contains(substring);
21 22
    }
22 23
24 +
    @Override
23 25
    public String toString() {
24 26
        return "contains(\"" + substring + "\")";
25 27
    }

@@ -4,17 +4,24 @@
Loading
4 4
 */
5 5
package org.mockito.internal.util.io;
6 6
7 -
import java.io.*;
7 +
import java.io.BufferedReader;
8 +
import java.io.Closeable;
9 +
import java.io.File;
10 +
import java.io.FileWriter;
11 +
import java.io.IOException;
12 +
import java.io.InputStream;
13 +
import java.io.InputStreamReader;
14 +
import java.io.PrintWriter;
8 15
import java.util.Collection;
9 16
import java.util.LinkedList;
10 17
import java.util.List;
11 -
12 18
import org.mockito.exceptions.base.MockitoException;
13 19
14 20
/**
15 -
 * IO utils. A bit of reinventing the wheel but we don't want extra dependencies at this stage and we want to be java.
21 +
 * IO utils. A bit of reinventing the wheel but we don't want extra dependencies at this stage and
22 +
 * we want to be java.
16 23
 */
17 -
public class IOUtil {
24 +
public final class IOUtil {
18 25
19 26
    /**
20 27
     * Writes text to file
@@ -32,7 +39,7 @@
Loading
32 39
    }
33 40
34 41
    public static Collection<String> readLines(InputStream is) {
35 -
        List<String> out = new LinkedList<String>();
42 +
        List<String> out = new LinkedList<>();
36 43
        BufferedReader r = new BufferedReader(new InputStreamReader(is));
37 44
        String line;
38 45
        try {
@@ -72,4 +79,6 @@
Loading
72 79
            }
73 80
        }
74 81
    }
82 +
83 +
    private IOUtil() {}
75 84
}

@@ -31,7 +31,7 @@
Loading
31 31
        this.strictness = strictness;
32 32
    }
33 33
34 -
    private final List<Answer<?>> answers = new LinkedList<Answer<?>>();
34 +
    private final List<Answer<?>> answers = new LinkedList<>();
35 35
36 36
    @Override
37 37
    public <T> T when(T mock) {

@@ -17,6 +17,7 @@
Loading
17 17
    private final ObjenesisStd objenesis =
18 18
            new ObjenesisStd(new GlobalConfiguration().enableClassCache());
19 19
20 +
    @Override
20 21
    public <T> T newInstance(Class<T> cls) {
21 22
        return objenesis.newInstance(cls);
22 23
    }

@@ -4,7 +4,35 @@
Loading
4 4
 */
5 5
package org.mockito.internal;
6 6
7 -
import org.mockito.*;
7 +
import static org.mockito.internal.exceptions.Reporter.missingMethodInvocation;
8 +
import static org.mockito.internal.exceptions.Reporter.mocksHaveToBePassedToVerifyNoMoreInteractions;
9 +
import static org.mockito.internal.exceptions.Reporter.mocksHaveToBePassedWhenCreatingInOrder;
10 +
import static org.mockito.internal.exceptions.Reporter.notAMockPassedToVerify;
11 +
import static org.mockito.internal.exceptions.Reporter.notAMockPassedToVerifyNoMoreInteractions;
12 +
import static org.mockito.internal.exceptions.Reporter.notAMockPassedWhenCreatingInOrder;
13 +
import static org.mockito.internal.exceptions.Reporter.nullPassedToVerify;
14 +
import static org.mockito.internal.exceptions.Reporter.nullPassedToVerifyNoMoreInteractions;
15 +
import static org.mockito.internal.exceptions.Reporter.nullPassedWhenCreatingInOrder;
16 +
import static org.mockito.internal.exceptions.Reporter.stubPassedToVerify;
17 +
import static org.mockito.internal.progress.ThreadSafeMockingProgress.mockingProgress;
18 +
import static org.mockito.internal.util.MockUtil.createConstructionMock;
19 +
import static org.mockito.internal.util.MockUtil.createMock;
20 +
import static org.mockito.internal.util.MockUtil.createStaticMock;
21 +
import static org.mockito.internal.util.MockUtil.getInvocationContainer;
22 +
import static org.mockito.internal.util.MockUtil.getMockHandler;
23 +
import static org.mockito.internal.util.MockUtil.isMock;
24 +
import static org.mockito.internal.util.MockUtil.resetMock;
25 +
import static org.mockito.internal.util.MockUtil.typeMockabilityOf;
26 +
import static org.mockito.internal.verification.VerificationModeFactory.noInteractions;
27 +
import static org.mockito.internal.verification.VerificationModeFactory.noMoreInteractions;
28 +
29 +
import java.util.Arrays;
30 +
import java.util.List;
31 +
import org.mockito.InOrder;
32 +
import org.mockito.MockSettings;
33 +
import org.mockito.MockedConstruction;
34 +
import org.mockito.MockedStatic;
35 +
import org.mockito.MockingDetails;
8 36
import org.mockito.exceptions.misusing.NotAMockException;
9 37
import org.mockito.internal.creation.MockSettingsImpl;
10 38
import org.mockito.internal.invocation.finder.VerifiableInvocationsFinder;
@@ -36,12 +64,6 @@
Loading
36 64
import java.util.List;
37 65
import java.util.function.Function;
38 66
39 -
import static org.mockito.internal.exceptions.Reporter.*;
40 -
import static org.mockito.internal.progress.ThreadSafeMockingProgress.mockingProgress;
41 -
import static org.mockito.internal.util.MockUtil.*;
42 -
import static org.mockito.internal.verification.VerificationModeFactory.noInteractions;
43 -
import static org.mockito.internal.verification.VerificationModeFactory.noMoreInteractions;
44 -
45 67
@SuppressWarnings("unchecked")
46 68
public class MockitoCore {
47 69
@@ -50,14 +72,14 @@
Loading
50 72
    }
51 73
52 74
    public <T> T mock(Class<T> typeToMock, MockSettings settings) {
53 -
        if (!MockSettingsImpl.class.isInstance(settings)) {
75 +
        if (!(settings instanceof MockSettingsImpl)) {
54 76
            throw new IllegalArgumentException(
55 77
                    "Unexpected implementation of '"
56 78
                            + settings.getClass().getCanonicalName()
57 79
                            + "'\n"
58 80
                            + "At the moment, you cannot provide your own implementations of that class.");
59 81
        }
60 -
        MockSettingsImpl impl = MockSettingsImpl.class.cast(settings);
82 +
        MockSettingsImpl impl = (MockSettingsImpl) settings;
61 83
        MockCreationSettings<T> creationSettings = impl.build(typeToMock);
62 84
        T mock = createMock(creationSettings);
63 85
        mockingProgress().mockingStarted(mock, creationSettings);

@@ -29,8 +29,7 @@
Loading
29 29
public class InvocationContainerImpl implements InvocationContainer, Serializable {
30 30
31 31
    private static final long serialVersionUID = -5334301962749537177L;
32 -
    private final LinkedList<StubbedInvocationMatcher> stubbed =
33 -
            new LinkedList<StubbedInvocationMatcher>();
32 +
    private final LinkedList<StubbedInvocationMatcher> stubbed = new LinkedList<>();
34 33
    private final DoAnswerStyleStubbing doAnswerStyleStubbing;
35 34
    private final RegisteredInvocations registeredInvocations;
36 35
    private final Strictness mockStrictness;
@@ -57,13 +56,7 @@
Loading
57 56
        addAnswer(answer, false, stubbingStrictness);
58 57
    }
59 58
60 -
    public void addConsecutiveAnswer(Answer answer) {
61 -
        addAnswer(answer, true, null);
62 -
    }
63 -
64 -
    /**
65 -
     * Adds new stubbed answer and returns the invocation matcher the answer was added to.
66 -
     */
59 +
    /** Adds new stubbed answer and returns the invocation matcher the answer was added to. */
67 60
    public StubbedInvocationMatcher addAnswer(
68 61
            Answer answer, boolean isConsecutive, Strictness stubbingStrictness) {
69 62
        Invocation invocation = invocationForStubbing.getInvocation();
@@ -86,6 +79,10 @@
Loading
86 79
        }
87 80
    }
88 81
82 +
    public void addConsecutiveAnswer(Answer answer) {
83 +
        addAnswer(answer, true, null);
84 +
    }
85 +
89 86
    Object answerTo(Invocation invocation) throws Throwable {
90 87
        return findAnswerFor(invocation).answer(invocation);
91 88
    }
@@ -157,7 +154,7 @@
Loading
157 154
     * Stubbings in ascending order, most recent last
158 155
     */
159 156
    public Collection<Stubbing> getStubbingsAscending() {
160 -
        List<Stubbing> result = new LinkedList<Stubbing>(stubbed);
157 +
        List<Stubbing> result = new LinkedList<>(stubbed);
161 158
        Collections.reverse(result);
162 159
        return result;
163 160
    }

@@ -4,10 +4,8 @@
Loading
4 4
 */
5 5
package org.mockito.internal.util;
6 6
7 -
/**
8 -
 * Pre-made preconditions
9 -
 */
10 -
public class Checks {
7 +
/** Pre-made preconditions */
8 +
public final class Checks {
11 9
12 10
    public static <T> T checkNotNull(T value, String checkedValue) {
13 11
        return checkNotNull(value, checkedValue, null);
@@ -31,4 +29,6 @@
Loading
31 29
        }
32 30
        return iterable;
33 31
    }
32 +
33 +
    private Checks() {}
34 34
}

@@ -157,7 +157,7 @@
Loading
157 157
        if (outerClassInstance == null) {
158 158
            return constructorArgs;
159 159
        }
160 -
        List<Object> resultArgs = new ArrayList<Object>(constructorArgs.length + 1);
160 +
        List<Object> resultArgs = new ArrayList<>(constructorArgs.length + 1);
161 161
        resultArgs.add(outerClassInstance);
162 162
        resultArgs.addAll(asList(constructorArgs));
163 163
        return resultArgs.toArray(new Object[constructorArgs.length + 1]);
@@ -228,13 +228,13 @@
Loading
228 228
    }
229 229
230 230
    @Override
231 -
    public <T> MockCreationSettings<T> build(Class<T> typeToMock) {
232 -
        return validatedSettings(typeToMock, (CreationSettings<T>) this);
231 +
    public <T2> MockCreationSettings<T2> build(Class<T2> typeToMock) {
232 +
        return validatedSettings(typeToMock, (CreationSettings<T2>) this);
233 233
    }
234 234
235 235
    @Override
236 -
    public <T> MockCreationSettings<T> buildStatic(Class<T> classToMock) {
237 -
        return validatedStaticSettings(classToMock, (CreationSettings<T>) this);
236 +
    public <T2> MockCreationSettings<T2> buildStatic(Class<T2> classToMock) {
237 +
        return validatedStaticSettings(classToMock, (CreationSettings<T2>) this);
238 238
    }
239 239
240 240
    @Override
@@ -289,7 +289,7 @@
Loading
289 289
    }
290 290
291 291
    private static Set<Class<?>> prepareExtraInterfaces(CreationSettings settings) {
292 -
        Set<Class<?>> interfaces = new HashSet<Class<?>>(settings.getExtraInterfaces());
292 +
        Set<Class<?>> interfaces = new HashSet<>(settings.getExtraInterfaces());
293 293
        if (settings.isSerializable()) {
294 294
            interfaces.add(Serializable.class);
295 295
        }

@@ -73,10 +73,11 @@
Loading
73 73
            this.location = location;
74 74
        }
75 75
76 +
        @Override
76 77
        public Object answer(InvocationOnMock currentInvocation) throws Throwable {
77 78
            if (isToStringMethod(currentInvocation.getMethod())) {
78 79
                return "SmartNull returned by this unstubbed method call on a mock:\n"
79 -
                        + unstubbedInvocation.toString();
80 +
                        + unstubbedInvocation;
80 81
            }
81 82
82 83
            throw smartNullPointerException(unstubbedInvocation.toString(), location);

@@ -6,13 +6,20 @@
Loading
6 6
7 7
import java.util.HashMap;
8 8
import java.util.Map;
9 -
10 9
import org.mockito.internal.creation.instance.InstantiatorProvider2Adapter;
11 -
import org.mockito.plugins.*;
10 +
import org.mockito.plugins.AnnotationEngine;
11 +
import org.mockito.plugins.InstantiatorProvider;
12 +
import org.mockito.plugins.InstantiatorProvider2;
13 +
import org.mockito.plugins.MemberAccessor;
14 +
import org.mockito.plugins.MockMaker;
15 +
import org.mockito.plugins.MockitoLogger;
16 +
import org.mockito.plugins.MockitoPlugins;
17 +
import org.mockito.plugins.PluginSwitch;
18 +
import org.mockito.plugins.StackTraceCleanerProvider;
12 19
13 20
class DefaultMockitoPlugins implements MockitoPlugins {
14 21
15 -
    private static final Map<String, String> DEFAULT_PLUGINS = new HashMap<String, String>();
22 +
    private static final Map<String, String> DEFAULT_PLUGINS = new HashMap<>();
16 23
    static final String INLINE_ALIAS = "mock-maker-inline";
17 24
    static final String MODULE_ALIAS = "member-accessor-module";
18 25

@@ -53,10 +53,12 @@
Loading
53 53
        return new Timeout(wrappedVerification.copyWithVerificationMode(newVerificationMode));
54 54
    }
55 55
56 +
    @Override
56 57
    public VerificationMode atMost(int maxNumberOfInvocations) {
57 58
        throw atMostAndNeverShouldNotBeUsedWithTimeout();
58 59
    }
59 60
61 +
    @Override
60 62
    public VerificationMode never() {
61 63
        throw atMostAndNeverShouldNotBeUsedWithTimeout();
62 64
    }

@@ -8,7 +8,9 @@
Loading
8 8
9 9
public class NoOpTestListener implements MockitoTestListener {
10 10
11 +
    @Override
11 12
    public void testFinished(TestFinishedEvent event) {}
12 13
14 +
    @Override
13 15
    public void onMockCreated(Object mock, MockCreationSettings settings) {}
14 16
}

@@ -22,14 +22,17 @@
Loading
22 22
        this.wanted = wanted;
23 23
    }
24 24
25 +
    @Override
25 26
    public List<Invocation> getAllInvocations() {
26 27
        return allInvocations;
27 28
    }
28 29
30 +
    @Override
29 31
    public InOrderContext getOrderingContext() {
30 32
        return inOrder;
31 33
    }
32 34
35 +
    @Override
33 36
    public MatchableInvocation getWanted() {
34 37
        return wanted;
35 38
    }

@@ -44,31 +44,41 @@
Loading
44 44
        this.throwable = throwable;
45 45
    }
46 46
47 +
    @Override
47 48
    public DescribedInvocation getInvocation() {
48 49
        return invocation;
49 50
    }
50 51
52 +
    @Override
51 53
    public Object getReturnedValue() {
52 54
        return returnedValue;
53 55
    }
54 56
57 +
    @Override
55 58
    public Throwable getThrowable() {
56 59
        return throwable;
57 60
    }
58 61
62 +
    @Override
59 63
    public boolean threwException() {
60 64
        return throwable != null;
61 65
    }
62 66
67 +
    @Override
63 68
    public String getLocationOfStubbing() {
64 69
        return (invocation.stubInfo() == null)
65 70
                ? null
66 71
                : invocation.stubInfo().stubbedAt().toString();
67 72
    }
68 73
74 +
    @Override
69 75
    public boolean equals(Object o) {
70 -
        if (this == o) return true;
71 -
        if (o == null || getClass() != o.getClass()) return false;
76 +
        if (this == o) {
77 +
            return true;
78 +
        }
79 +
        if (o == null || getClass() != o.getClass()) {
80 +
            return false;
81 +
        }
72 82
73 83
        NotifiedMethodInvocationReport that = (NotifiedMethodInvocationReport) o;
74 84
@@ -77,6 +87,7 @@
Loading
77 87
                && areEqual(throwable, that.throwable);
78 88
    }
79 89
90 +
    @Override
80 91
    public int hashCode() {
81 92
        int result = invocation != null ? invocation.hashCode() : 0;
82 93
        result = 31 * result + (returnedValue != null ? returnedValue.hashCode() : 0);

@@ -20,30 +20,37 @@
Loading
20 20
        this.parameterTypes = SuspendMethod.trimSuspendParameterTypes(method.getParameterTypes());
21 21
    }
22 22
23 +
    @Override
23 24
    public Class<?>[] getExceptionTypes() {
24 25
        return method.getExceptionTypes();
25 26
    }
26 27
28 +
    @Override
27 29
    public Method getJavaMethod() {
28 30
        return method;
29 31
    }
30 32
33 +
    @Override
31 34
    public String getName() {
32 35
        return method.getName();
33 36
    }
34 37
38 +
    @Override
35 39
    public Class<?>[] getParameterTypes() {
36 40
        return parameterTypes;
37 41
    }
38 42
43 +
    @Override
39 44
    public Class<?> getReturnType() {
40 45
        return method.getReturnType();
41 46
    }
42 47
48 +
    @Override
43 49
    public boolean isVarArgs() {
44 50
        return method.isVarArgs();
45 51
    }
46 52
53 +
    @Override
47 54
    public boolean isAbstract() {
48 55
        return (method.getModifiers() & Modifier.ABSTRACT) != 0;
49 56
    }

@@ -7,10 +7,8 @@
Loading
7 7
import java.lang.reflect.ParameterizedType;
8 8
import java.lang.reflect.Type;
9 9
10 -
/**
11 -
 * Attempts to extract generic type of given target base class or target interface
12 -
 */
13 -
public class GenericTypeExtractor {
10 +
/** Attempts to extract generic type of given target base class or target interface */
11 +
public final class GenericTypeExtractor {
14 12
15 13
    /**
16 14
     * Extract generic type of root class either from the target base class or from target base interface.
@@ -86,4 +84,6 @@
Loading
86 84
        }
87 85
        return Object.class;
88 86
    }
87 +
88 +
    private GenericTypeExtractor() {}
89 89
}

@@ -25,7 +25,8 @@
Loading
25 25
        }
26 26
    }
27 27
28 +
    @Override
28 29
    public String toString() {
29 -
        return hint.toString() + "\n";
30 +
        return hint + "\n";
30 31
    }
31 32
}

@@ -31,14 +31,15 @@
Loading
31 31
 */
32 32
public class HashCodeAndEqualsSafeSet implements Set<Object> {
33 33
34 -
    private final HashSet<HashCodeAndEqualsMockWrapper> backingHashSet =
35 -
            new HashSet<HashCodeAndEqualsMockWrapper>();
34 +
    private final HashSet<HashCodeAndEqualsMockWrapper> backingHashSet = new HashSet<>();
36 35
36 +
    @Override
37 37
    public Iterator<Object> iterator() {
38 38
        return new Iterator<Object>() {
39 39
            private final Iterator<HashCodeAndEqualsMockWrapper> iterator =
40 40
                    backingHashSet.iterator();
41 41
42 +
            @Override
42 43
            public boolean hasNext() {
43 44
                return iterator.hasNext();
44 45
            }
@@ -53,26 +54,32 @@
Loading
53 54
        };
54 55
    }
55 56
57 +
    @Override
56 58
    public int size() {
57 59
        return backingHashSet.size();
58 60
    }
59 61
62 +
    @Override
60 63
    public boolean isEmpty() {
61 64
        return backingHashSet.isEmpty();
62 65
    }
63 66
67 +
    @Override
64 68
    public boolean contains(Object mock) {
65 69
        return backingHashSet.contains(HashCodeAndEqualsMockWrapper.of(mock));
66 70
    }
67 71
72 +
    @Override
68 73
    public boolean add(Object mock) {
69 74
        return backingHashSet.add(HashCodeAndEqualsMockWrapper.of(mock));
70 75
    }
71 76
77 +
    @Override
72 78
    public boolean remove(Object mock) {
73 79
        return backingHashSet.remove(HashCodeAndEqualsMockWrapper.of(mock));
74 80
    }
75 81
82 +
    @Override
76 83
    public void clear() {
77 84
        backingHashSet.clear();
78 85
    }
@@ -100,6 +107,15 @@
Loading
100 107
        return unwrapTo(new Object[size()]);
101 108
    }
102 109
110 +
    @SuppressWarnings("unchecked")
111 +
    public <T> T[] toArray(T[] typedArray) {
112 +
        T[] array =
113 +
                typedArray.length >= size()
114 +
                        ? typedArray
115 +
                        : (T[]) newInstance(typedArray.getClass().getComponentType(), size());
116 +
        return unwrapTo(array);
117 +
    }
118 +
103 119
    @SuppressWarnings("unchecked")
104 120
    private <T> T[] unwrapTo(T[] array) {
105 121
        Iterator<Object> iterator = iterator();
@@ -111,34 +127,28 @@
Loading
111 127
        return array;
112 128
    }
113 129
114 -
    @SuppressWarnings("unchecked")
115 -
    public <T> T[] toArray(T[] typedArray) {
116 -
        T[] array =
117 -
                typedArray.length >= size()
118 -
                        ? typedArray
119 -
                        : (T[]) newInstance(typedArray.getClass().getComponentType(), size());
120 -
        return unwrapTo(array);
121 -
    }
122 -
123 130
    public boolean removeAll(Collection<?> mocks) {
124 131
        return backingHashSet.removeAll(asWrappedMocks(mocks));
125 132
    }
126 133
134 +
    @Override
127 135
    public boolean containsAll(Collection<?> mocks) {
128 136
        return backingHashSet.containsAll(asWrappedMocks(mocks));
129 137
    }
130 138
139 +
    @Override
131 140
    public boolean addAll(Collection<?> mocks) {
132 141
        return backingHashSet.addAll(asWrappedMocks(mocks));
133 142
    }
134 143
144 +
    @Override
135 145
    public boolean retainAll(Collection<?> mocks) {
136 146
        return backingHashSet.retainAll(asWrappedMocks(mocks));
137 147
    }
138 148
139 149
    private HashSet<HashCodeAndEqualsMockWrapper> asWrappedMocks(Collection<?> mocks) {
140 150
        Checks.checkNotNull(mocks, "Passed collection should notify() be null");
141 -
        HashSet<HashCodeAndEqualsMockWrapper> hashSet = new HashSet<HashCodeAndEqualsMockWrapper>();
151 +
        HashSet<HashCodeAndEqualsMockWrapper> hashSet = new HashSet<>();
142 152
        for (Object mock : mocks) {
143 153
            assert !(mock instanceof HashCodeAndEqualsMockWrapper) : "WRONG";
144 154
            hashSet.add(HashCodeAndEqualsMockWrapper.of(mock));

@@ -25,10 +25,12 @@
Loading
25 25
        return sessionStore.createStatement(base, description.getDisplayName(), this.testInstance);
26 26
    }
27 27
28 +
    @Override
28 29
    public MockitoTestRule silent() {
29 30
        return strictness(Strictness.LENIENT);
30 31
    }
31 32
33 +
    @Override
32 34
    public MockitoTestRule strictness(Strictness strictness) {
33 35
        sessionStore.setStrictness(strictness);
34 36
        return this;

@@ -12,10 +12,12 @@
Loading
12 12
13 13
    final IdentitySet verified = new IdentitySet();
14 14
15 +
    @Override
15 16
    public boolean isVerified(Invocation invocation) {
16 17
        return verified.contains(invocation);
17 18
    }
18 19
20 +
    @Override
19 21
    public void markVerified(Invocation i) {
20 22
        verified.add(i);
21 23
    }

@@ -7,7 +7,7 @@
Loading
7 7
import java.lang.reflect.Array;
8 8
9 9
// stolen from hamcrest because I didn't want to have more dependency than Matcher class
10 -
public class Equality {
10 +
public final class Equality {
11 11
12 12
    public static boolean areEqual(Object o1, Object o2) {
13 13
        if (o1 == o2) {
@@ -31,7 +31,9 @@
Loading
31 31
32 32
    static boolean areArrayElementsEqual(Object o1, Object o2) {
33 33
        for (int i = 0; i < Array.getLength(o1); i++) {
34 -
            if (!areEqual(Array.get(o1, i), Array.get(o2, i))) return false;
34 +
            if (!areEqual(Array.get(o1, i), Array.get(o2, i))) {
35 +
                return false;
36 +
            }
35 37
        }
36 38
        return true;
37 39
    }
@@ -39,4 +41,6 @@
Loading
39 41
    static boolean isArray(Object o) {
40 42
        return o.getClass().isArray();
41 43
    }
44 +
45 +
    private Equality() {}
42 46
}

@@ -129,8 +129,12 @@
Loading
129 129
130 130
    @Override
131 131
    public boolean equals(Object o) {
132 -
        if (this == o) return true;
133 -
        if (o == null || getClass() != o.getClass()) return false;
132 +
        if (this == o) {
133 +
            return true;
134 +
        }
135 +
        if (o == null || getClass() != o.getClass()) {
136 +
            return false;
137 +
        }
134 138
135 139
        InstanceField that = (InstanceField) o;
136 140
        return field.equals(that.field) && instance.equals(that.instance);

@@ -19,16 +19,18 @@
Loading
19 19
public class CapturingMatcher<T>
20 20
        implements ArgumentMatcher<T>, CapturesArguments, VarargMatcher, Serializable {
21 21
22 -
    private final List<Object> arguments = new ArrayList<Object>();
22 +
    private final List<Object> arguments = new ArrayList<>();
23 23
24 24
    private final ReadWriteLock lock = new ReentrantReadWriteLock();
25 25
    private final Lock readLock = lock.readLock();
26 26
    private final Lock writeLock = lock.writeLock();
27 27
28 +
    @Override
28 29
    public boolean matches(Object argument) {
29 30
        return true;
30 31
    }
31 32
33 +
    @Override
32 34
    public String toString() {
33 35
        return "<Capturing argument>";
34 36
    }
@@ -55,6 +57,7 @@
Loading
55 57
        }
56 58
    }
57 59
60 +
    @Override
58 61
    public void captureFrom(Object argument) {
59 62
        writeLock.lock();
60 63
        try {

@@ -34,8 +34,7 @@
Loading
34 34
public class IndependentAnnotationEngine
35 35
        implements AnnotationEngine, org.mockito.configuration.AnnotationEngine {
36 36
    private final Map<Class<? extends Annotation>, FieldAnnotationProcessor<?>>
37 -
            annotationProcessorMap =
38 -
                    new HashMap<Class<? extends Annotation>, FieldAnnotationProcessor<?>>();
37 +
            annotationProcessorMap = new HashMap<>();
39 38
40 39
    public IndependentAnnotationEngine() {
41 40
        registerAnnotationProcessor(Mock.class, new MockAnnotationProcessor());
@@ -52,6 +51,7 @@
Loading
52 51
                    annotationProcessorMap.get(annotation.annotationType());
53 52
        }
54 53
        return new FieldAnnotationProcessor<A>() {
54 +
            @Override
55 55
            public Object process(A annotation, Field field) {
56 56
                return null;
57 57
            }

@@ -37,6 +37,7 @@
Loading
37 37
public class CallsRealMethods implements Answer<Object>, ValidableAnswer, Serializable {
38 38
    private static final long serialVersionUID = 9057165148930624087L;
39 39
40 +
    @Override
40 41
    public Object answer(InvocationOnMock invocation) throws Throwable {
41 42
        if (Modifier.isAbstract(invocation.getMethod().getModifiers())) {
42 43
            return RETURNS_DEFAULTS.answer(invocation);

@@ -11,7 +11,6 @@
Loading
11 11
import java.lang.reflect.Field;
12 12
import java.lang.reflect.Method;
13 13
import java.util.*;
14 -
15 14
import org.mockito.exceptions.base.MockitoAssertionError;