Make thread related utility methods available for use in all modules.

This commit is contained in:
Cody Henthorne
2021-03-01 15:44:33 -05:00
parent 38caf1e2b7
commit dc9b8169c0
47 changed files with 228 additions and 224 deletions

View File

@@ -18,6 +18,7 @@ import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.rule.PowerMockRule;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config;
import org.signal.core.util.ThreadUtil;
import org.signal.storageservice.protos.groups.AccessControl;
import org.signal.storageservice.protos.groups.local.DecryptedGroup;
import org.signal.storageservice.protos.groups.local.DecryptedGroupChange;
@@ -47,7 +48,7 @@ import static org.thoughtcrime.securesms.util.StringUtil.isolateBidi;
@RunWith(RobolectricTestRunner.class)
@Config(manifest = Config.NONE, application = Application.class)
@PowerMockIgnore({ "org.mockito.*", "org.robolectric.*", "android.*", "androidx.*" })
@PrepareForTest(Util.class)
@PrepareForTest(ThreadUtil.class)
public final class GroupsV2UpdateMessageProducerTest {
private UUID you;

View File

@@ -5,7 +5,7 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import org.thoughtcrime.securesms.util.Util;
import org.signal.core.util.ThreadUtil;
import java.util.Arrays;
import java.util.Collections;
@@ -19,7 +19,7 @@ import static org.junit.Assert.assertTrue;
import static org.thoughtcrime.securesms.testutil.MainThreadUtil.setMainThread;
@RunWith(PowerMockRunner.class)
@PrepareForTest(Util.class)
@PrepareForTest(ThreadUtil.class)
public final class UpdateDescriptionTest {
@Before

View File

@@ -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();
}