mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-26 03:40:56 +01:00
Excise PowerMock and reenable like a bunch of ignored tests.
Co-authored-by: Rashad Sookram <rashad@signal.org>
This commit is contained in:
committed by
Cody Henthorne
parent
1f82ceecc6
commit
711148423d
@@ -6,36 +6,42 @@ import org.junit.Before
|
||||
import org.junit.Rule
|
||||
import org.junit.runner.RunWith
|
||||
import org.mockito.ArgumentMatchers
|
||||
import org.powermock.api.mockito.PowerMockito
|
||||
import org.powermock.core.classloader.annotations.PowerMockIgnore
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest
|
||||
import org.powermock.modules.junit4.rule.PowerMockRule
|
||||
import org.mockito.Mock
|
||||
import org.mockito.MockedConstruction
|
||||
import org.mockito.MockedStatic
|
||||
import org.mockito.Mockito.`when`
|
||||
import org.mockito.junit.MockitoJUnit
|
||||
import org.mockito.junit.MockitoRule
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.annotation.Config
|
||||
import org.thoughtcrime.securesms.crypto.AttachmentSecretProvider
|
||||
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies
|
||||
import org.thoughtcrime.securesms.keyvalue.ChatColorsValues
|
||||
import org.thoughtcrime.securesms.keyvalue.SignalStore
|
||||
import org.thoughtcrime.securesms.keyvalue.WallpaperValues
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(manifest = Config.NONE, application = Application::class)
|
||||
@PowerMockIgnore("org.mockito.*", "org.robolectric.*", "android.*", "androidx.*", "org.powermock.*")
|
||||
@PrepareForTest(ApplicationDependencies::class, AttachmentSecretProvider::class, SignalStore::class, WallpaperValues::class, ChatColorsValues::class)
|
||||
abstract class BaseRecipientTest {
|
||||
|
||||
@Rule
|
||||
@JvmField
|
||||
var rule = PowerMockRule()
|
||||
@JvmField val mockitoRule: MockitoRule = MockitoJUnit.rule()
|
||||
|
||||
@Mock
|
||||
private lateinit var applicationDependenciesStaticMock: MockedStatic<ApplicationDependencies>
|
||||
|
||||
@Mock
|
||||
private lateinit var attachmentSecretProviderStaticMock: MockedStatic<AttachmentSecretProvider>
|
||||
|
||||
@Mock
|
||||
private lateinit var signalStoreStaticMock: MockedStatic<SignalStore>
|
||||
|
||||
@Mock
|
||||
private lateinit var mockedSignalStoreConstruction: MockedConstruction<SignalStore>
|
||||
|
||||
@Before
|
||||
fun superSetUp() {
|
||||
val application = ApplicationProvider.getApplicationContext<Application>()
|
||||
|
||||
PowerMockito.mockStatic(ApplicationDependencies::class.java)
|
||||
PowerMockito.`when`(ApplicationDependencies.getApplication()).thenReturn(application)
|
||||
PowerMockito.mockStatic(AttachmentSecretProvider::class.java)
|
||||
PowerMockito.`when`(AttachmentSecretProvider.getInstance(ArgumentMatchers.any())).thenThrow(RuntimeException::class.java)
|
||||
PowerMockito.whenNew(SignalStore::class.java).withAnyArguments().thenReturn(null)
|
||||
PowerMockito.mockStatic(SignalStore::class.java)
|
||||
`when`(ApplicationDependencies.getApplication()).thenReturn(application)
|
||||
`when`(AttachmentSecretProvider.getInstance(ArgumentMatchers.any())).thenThrow(RuntimeException::class.java)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,10 +4,12 @@ import android.content.Context;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockedStatic;
|
||||
import org.mockito.junit.MockitoJUnit;
|
||||
import org.mockito.junit.MockitoRule;
|
||||
import org.thoughtcrime.securesms.database.MmsSmsDatabase;
|
||||
import org.thoughtcrime.securesms.database.RecipientDatabase;
|
||||
import org.thoughtcrime.securesms.database.SignalDatabase;
|
||||
@@ -16,30 +18,34 @@ import org.thoughtcrime.securesms.util.FeatureFlags;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Matchers.anyLong;
|
||||
import static org.mockito.ArgumentMatchers.anyLong;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.powermock.api.mockito.PowerMockito.mockStatic;
|
||||
import static org.powermock.api.mockito.PowerMockito.when;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest({SignalDatabase.class, FeatureFlags.class})
|
||||
public class RecipientUtilTest {
|
||||
|
||||
@Rule
|
||||
public MockitoRule rule = MockitoJUnit.rule();
|
||||
|
||||
private Context context = mock(Context.class);
|
||||
private Recipient recipient = mock(Recipient.class);
|
||||
private ThreadDatabase mockThreadDatabase = mock(ThreadDatabase.class);
|
||||
private MmsSmsDatabase mockMmsSmsDatabase = mock(MmsSmsDatabase.class);
|
||||
private RecipientDatabase mockRecipientDatabase = mock(RecipientDatabase.class);
|
||||
|
||||
@Mock
|
||||
private MockedStatic<SignalDatabase> signalDatabaseMockedStatic;
|
||||
|
||||
@Mock
|
||||
private MockedStatic<FeatureFlags> featureFlagsMockedStatic;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mockStatic(SignalDatabase.class);
|
||||
when(SignalDatabase.threads()).thenReturn(mockThreadDatabase);
|
||||
when(SignalDatabase.mmsSms()).thenReturn(mockMmsSmsDatabase);
|
||||
when(SignalDatabase.recipients()).thenReturn(mockRecipientDatabase);
|
||||
mockStatic(FeatureFlags.class);
|
||||
signalDatabaseMockedStatic.when(SignalDatabase::threads).thenReturn(mockThreadDatabase);
|
||||
signalDatabaseMockedStatic.when(SignalDatabase::mmsSms).thenReturn(mockMmsSmsDatabase);
|
||||
signalDatabaseMockedStatic.when(SignalDatabase::recipients).thenReturn(mockRecipientDatabase);
|
||||
|
||||
when(recipient.getId()).thenReturn(RecipientId.from(5));
|
||||
when(recipient.resolve()).thenReturn(recipient);
|
||||
|
||||
@@ -3,9 +3,9 @@ package org.thoughtcrime.securesms.recipients
|
||||
import android.graphics.Color
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Before
|
||||
import org.junit.Ignore
|
||||
import org.junit.Test
|
||||
import org.powermock.api.mockito.PowerMockito
|
||||
import org.mockito.Mockito.mock
|
||||
import org.mockito.Mockito.`when`
|
||||
import org.thoughtcrime.securesms.conversation.colors.ChatColors
|
||||
import org.thoughtcrime.securesms.conversation.colors.ChatColorsPalette
|
||||
import org.thoughtcrime.securesms.database.RecipientDatabaseTestUtils.createRecipient
|
||||
@@ -14,7 +14,6 @@ import org.thoughtcrime.securesms.keyvalue.SignalStore
|
||||
import org.thoughtcrime.securesms.keyvalue.WallpaperValues
|
||||
import org.thoughtcrime.securesms.wallpaper.ChatWallpaper
|
||||
|
||||
@Ignore("PowerMock failing")
|
||||
@Suppress("ClassName")
|
||||
class Recipient_getChatColorsTest : BaseRecipientTest() {
|
||||
|
||||
@@ -27,14 +26,14 @@ class Recipient_getChatColorsTest : BaseRecipientTest() {
|
||||
|
||||
@Before
|
||||
fun setUp() {
|
||||
wallpaperValues = PowerMockito.mock(WallpaperValues::class.java)
|
||||
chatColorsValues = PowerMockito.mock(ChatColorsValues::class.java)
|
||||
wallpaperValues = mock(WallpaperValues::class.java)
|
||||
chatColorsValues = mock(ChatColorsValues::class.java)
|
||||
|
||||
val globalWallpaper = createWallpaper(globalWallpaperChatColor)
|
||||
PowerMockito.`when`(wallpaperValues.wallpaper).thenReturn(globalWallpaper)
|
||||
PowerMockito.`when`(chatColorsValues.chatColors).thenReturn(globalChatColor)
|
||||
PowerMockito.`when`(SignalStore.wallpaper()).thenReturn(wallpaperValues)
|
||||
PowerMockito.`when`(SignalStore.chatColorsValues()).thenReturn(chatColorsValues)
|
||||
`when`(wallpaperValues.wallpaper).thenReturn(globalWallpaper)
|
||||
`when`(chatColorsValues.chatColors).thenReturn(globalChatColor)
|
||||
`when`(SignalStore.wallpaper()).thenReturn(wallpaperValues)
|
||||
`when`(SignalStore.chatColorsValues()).thenReturn(chatColorsValues)
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -94,7 +93,7 @@ class Recipient_getChatColorsTest : BaseRecipientTest() {
|
||||
@Test
|
||||
fun `Given recipient has auto chat color set and no wallpaper set and no global wallpaper set, when I getChatColors, then I expect the default chat color`() {
|
||||
// GIVEN
|
||||
PowerMockito.`when`(wallpaperValues.wallpaper).thenReturn(null)
|
||||
`when`(wallpaperValues.wallpaper).thenReturn(null)
|
||||
val auto = ChatColors.forColor(ChatColors.Id.Auto, Color.BLACK)
|
||||
val recipient = createRecipient(chatColors = auto)
|
||||
|
||||
@@ -109,7 +108,7 @@ class Recipient_getChatColorsTest : BaseRecipientTest() {
|
||||
fun `Given recipient has no chat color set and there is a custom global chat color, when I getChatColors, then I expect the global chat color`() {
|
||||
// GIVEN
|
||||
val expected = globalChatColor.withId(ChatColors.Id.Custom(12))
|
||||
PowerMockito.`when`(chatColorsValues.chatColors).thenReturn(expected)
|
||||
`when`(chatColorsValues.chatColors).thenReturn(expected)
|
||||
val recipient = createRecipient()
|
||||
|
||||
// WHEN
|
||||
@@ -134,7 +133,7 @@ class Recipient_getChatColorsTest : BaseRecipientTest() {
|
||||
@Test
|
||||
fun `Given recipient has no chat color set and there is an auto global chat color and the recipient has a wallpaper, when I getChatColors, then I expect the wallpaper chat color`() {
|
||||
// GIVEN
|
||||
PowerMockito.`when`(chatColorsValues.chatColors).thenReturn(globalChatColor.withId(ChatColors.Id.Auto))
|
||||
`when`(chatColorsValues.chatColors).thenReturn(globalChatColor.withId(ChatColors.Id.Auto))
|
||||
val color = ChatColors.forColor(ChatColors.Id.BuiltIn, Color.CYAN)
|
||||
val recipient = createRecipient(wallpaper = createWallpaper(color))
|
||||
|
||||
@@ -148,7 +147,7 @@ class Recipient_getChatColorsTest : BaseRecipientTest() {
|
||||
@Test
|
||||
fun `Given recipient has no chat color set and there is no global chat color and the recipient has a wallpaper, when I getChatColors, then I expect the wallpaper chat color`() {
|
||||
// GIVEN
|
||||
PowerMockito.`when`(chatColorsValues.chatColors).thenReturn(null)
|
||||
`when`(chatColorsValues.chatColors).thenReturn(null)
|
||||
val color = ChatColors.forColor(ChatColors.Id.BuiltIn, Color.CYAN)
|
||||
val recipient = createRecipient(wallpaper = createWallpaper(color))
|
||||
|
||||
@@ -162,7 +161,7 @@ class Recipient_getChatColorsTest : BaseRecipientTest() {
|
||||
@Test
|
||||
fun `Given recipient has no chat color set and there is an auto global chat color and the recipient has no wallpaper and global wallpaper set, when I getChatColors, then I expect the global wallpaper chat color`() {
|
||||
// GIVEN
|
||||
PowerMockito.`when`(chatColorsValues.chatColors).thenReturn(globalChatColor.withId(ChatColors.Id.Auto))
|
||||
`when`(chatColorsValues.chatColors).thenReturn(globalChatColor.withId(ChatColors.Id.Auto))
|
||||
val recipient = createRecipient()
|
||||
|
||||
// WHEN
|
||||
@@ -175,7 +174,7 @@ class Recipient_getChatColorsTest : BaseRecipientTest() {
|
||||
@Test
|
||||
fun `Given recipient has no chat color set and there is no global chat color and the recipient has no wallpaper and global wallpaper set, when I getChatColors, then I expect the global wallpaper chat color`() {
|
||||
// GIVEN
|
||||
PowerMockito.`when`(chatColorsValues.chatColors).thenReturn(null)
|
||||
`when`(chatColorsValues.chatColors).thenReturn(null)
|
||||
val recipient = createRecipient()
|
||||
|
||||
// WHEN
|
||||
@@ -188,8 +187,8 @@ class Recipient_getChatColorsTest : BaseRecipientTest() {
|
||||
@Test
|
||||
fun `Given no recipient colors and auto global colors and no wallpaper set, when I getChatColors, then I expect default blue`() {
|
||||
// GIVEN
|
||||
PowerMockito.`when`(wallpaperValues.wallpaper).thenReturn(null)
|
||||
PowerMockito.`when`(chatColorsValues.chatColors).thenReturn(globalChatColor.withId(ChatColors.Id.Auto))
|
||||
`when`(wallpaperValues.wallpaper).thenReturn(null)
|
||||
`when`(chatColorsValues.chatColors).thenReturn(globalChatColor.withId(ChatColors.Id.Auto))
|
||||
val recipient = createRecipient()
|
||||
|
||||
// WHEN
|
||||
@@ -202,8 +201,8 @@ class Recipient_getChatColorsTest : BaseRecipientTest() {
|
||||
@Test
|
||||
fun `Given no colors or wallpaper set, when I getChatColors, then I expect default blue`() {
|
||||
// GIVEN
|
||||
PowerMockito.`when`(wallpaperValues.wallpaper).thenReturn(null)
|
||||
PowerMockito.`when`(chatColorsValues.chatColors).thenReturn(null)
|
||||
`when`(wallpaperValues.wallpaper).thenReturn(null)
|
||||
`when`(chatColorsValues.chatColors).thenReturn(null)
|
||||
val recipient = createRecipient()
|
||||
|
||||
// WHEN
|
||||
@@ -215,7 +214,7 @@ class Recipient_getChatColorsTest : BaseRecipientTest() {
|
||||
|
||||
private fun createWallpaper(
|
||||
chatColors: ChatColors?
|
||||
): ChatWallpaper = PowerMockito.mock(ChatWallpaper::class.java).apply {
|
||||
PowerMockito.`when`(autoChatColors).thenReturn(chatColors)
|
||||
): ChatWallpaper = mock(ChatWallpaper::class.java).apply {
|
||||
`when`(autoChatColors).thenReturn(chatColors)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user