mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-19 08:09:12 +01:00
Make thread related utility methods available for use in all modules.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
package org.thoughtcrime.securesms.testutil;
|
||||
|
||||
import org.thoughtcrime.securesms.util.Util;
|
||||
import org.signal.core.util.ThreadUtil;
|
||||
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.powermock.api.mockito.PowerMockito.doCallRealMethod;
|
||||
@@ -12,17 +12,17 @@ public final class MainThreadUtil {
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes {@link Util}'s Main thread assertions pass or fail during tests.
|
||||
* Makes {@link ThreadUtil}'s Main thread assertions pass or fail during tests.
|
||||
* <p>
|
||||
* Use with {@link org.powermock.modules.junit4.PowerMockRunner} or robolectric with powermock
|
||||
* rule and {@code @PrepareForTest(Util.class)}
|
||||
*/
|
||||
public static void setMainThread(boolean isMainThread) {
|
||||
mockStatic(Util.class);
|
||||
when(Util.isMainThread()).thenReturn(isMainThread);
|
||||
mockStatic(ThreadUtil.class);
|
||||
when(ThreadUtil.isMainThread()).thenReturn(isMainThread);
|
||||
try {
|
||||
doCallRealMethod().when(Util.class, "assertMainThread");
|
||||
doCallRealMethod().when(Util.class, "assertNotMainThread");
|
||||
doCallRealMethod().when(ThreadUtil.class, "assertMainThread");
|
||||
doCallRealMethod().when(ThreadUtil.class, "assertNotMainThread");
|
||||
} catch (Exception e) {
|
||||
throw new AssertionError();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user