66import java .lang .reflect .Modifier ;
77import java .util .ArrayList ;
88import java .util .Arrays ;
9- import java .util .Collections ;
109import java .util .HashMap ;
11- import java .util .List ;
10+ import java .util .concurrent . CopyOnWriteArrayList ;
1211import java .util .function .Consumer ;
1312import java .util .function .Predicate ;
1413import java .util .stream .Collectors ;
2120
2221public final class Mocks {
2322
24- private static final List <WeakReference <Object >> MOCKS = Collections . synchronizedList ( new ArrayList <>() );
23+ private static final CopyOnWriteArrayList <WeakReference <Object >> MOCKS = new CopyOnWriteArrayList <>();
2524 private static final Predicate <WeakReference <?>> IS_REFERENCE_CLEARED = reference -> reference .get () == null ;
2625 private static final Consumer <WeakReference <Object >> CLEAR_INVOCATIONS_ON_REFERENCED_MOCK = reference -> Mockito .clearInvocations (reference .get ());
27- private static final Predicate <WeakReference <Object >> CLEAR_INVOCATIONS_ON_REFERENCED_MOCK_IF_REFERNCE_NOT_CLEARED = reference -> {
26+ private static final Predicate <WeakReference <Object >> CLEAR_INVOCATIONS_ON_REFERENCED_MOCK_IF_REFERENCE_NOT_CLEARED = reference -> {
2827 if (IS_REFERENCE_CLEARED .test (reference )) return true ;
2928 CLEAR_INVOCATIONS_ON_REFERENCED_MOCK .accept (reference );
3029 return false ;
@@ -37,7 +36,7 @@ public final class Mocks {
3736 // 2) Garbage collected references are removed
3837 // 3) Mock is garbage collected
3938 // 4) Mock invocations are cleared -> throws NullPointerException
40- Lib199Subsystem .registerPeriodic (() -> MOCKS .removeIf (CLEAR_INVOCATIONS_ON_REFERENCED_MOCK_IF_REFERNCE_NOT_CLEARED ));
39+ Lib199Subsystem .registerAsyncPeriodic (() -> MOCKS .removeIf (CLEAR_INVOCATIONS_ON_REFERENCED_MOCK_IF_REFERENCE_NOT_CLEARED ));
4140 }
4241
4342 /**
@@ -61,7 +60,7 @@ public static <T, U> T createMock(Class<T> classToMock, U implClass, Class<?>...
6160 * @param <U> the class type which will be used to provide method implementations
6261 * @param classToMock the class type which will be mocked
6362 * @param implClass the object to which to try to forward method calls
64- * @param forwardUnknownCalls whether methods which are not overriden will call their real methods
63+ * @param forwardUnknownCalls whether methods which are not overridden will call their real methods
6564 * @param interfaces a list of interfaces which the mocked object should extend
6665 * @return an instance of <code>T</code> in which some or all of the classes methods are replaced with a mocked implementation from <code>U</code>
6766 * @see #createMock(Class, Object, Class...)
@@ -77,7 +76,7 @@ public static <T, U> T createMock(Class<T> classToMock, U implClass, boolean for
7776 * @param <U> the class type which will be used to provide method implementations
7877 * @param classToMock the class type which will be mocked
7978 * @param implClass the object to which to try to forward method calls
80- * @param defaultAnswer The answer to use when no overriden implementation is found
79+ * @param defaultAnswer The answer to use when no overridden implementation is found
8180 * @param interfaces a list of interfaces which the mocked object should extend
8281 * @return an instance of <code>T</code> in which some or all of the classes methods are replaced with a mocked implementation from <code>U</code>
8382 * @see #createMock(Class, Object, Class...)
0 commit comments