mirror of
https://github.com/signalapp/Signal-Android.git
synced 2025-12-27 14:40:22 +00:00
Migrate most of MmsSmsTable.
This commit is contained in:
@@ -18,6 +18,7 @@ import org.thoughtcrime.securesms.testing.TestDatabaseUtil
|
||||
class MmsSmsDatabaseTest {
|
||||
|
||||
private lateinit var mmsSmsTable: MmsSmsTable
|
||||
private lateinit var messageTable: MessageTable
|
||||
private lateinit var db: SQLiteDatabase
|
||||
|
||||
@Before
|
||||
@@ -28,6 +29,7 @@ class MmsSmsDatabaseTest {
|
||||
|
||||
db = sqlCipher.writableDatabase
|
||||
mmsSmsTable = MmsSmsTable(ApplicationProvider.getApplicationContext(), sqlCipher)
|
||||
messageTable = MessageTable(ApplicationProvider.getApplicationContext(), sqlCipher)
|
||||
}
|
||||
|
||||
@After
|
||||
@@ -38,7 +40,7 @@ class MmsSmsDatabaseTest {
|
||||
@Test
|
||||
fun `getConversationSnippet when single normal SMS, return SMS message id and transport as false`() {
|
||||
TestSms.insert(db)
|
||||
mmsSmsTable.getConversationSnippetCursor(1).use { cursor ->
|
||||
messageTable.getConversationSnippetCursor(1).use { cursor ->
|
||||
cursor.moveToFirst()
|
||||
assertEquals(1, CursorUtil.requireLong(cursor, MessageTable.ID))
|
||||
}
|
||||
@@ -47,7 +49,7 @@ class MmsSmsDatabaseTest {
|
||||
@Test
|
||||
fun `getConversationSnippet when single normal MMS, return MMS message id and transport as true`() {
|
||||
TestMms.insert(db)
|
||||
mmsSmsTable.getConversationSnippetCursor(1).use { cursor ->
|
||||
messageTable.getConversationSnippetCursor(1).use { cursor ->
|
||||
cursor.moveToFirst()
|
||||
assertEquals(1, CursorUtil.requireLong(cursor, MessageTable.ID))
|
||||
}
|
||||
@@ -58,13 +60,13 @@ class MmsSmsDatabaseTest {
|
||||
val timestamp = System.currentTimeMillis()
|
||||
|
||||
TestMms.insert(db, receivedTimestampMillis = timestamp + 2)
|
||||
mmsSmsTable.getConversationSnippetCursor(1).use { cursor ->
|
||||
messageTable.getConversationSnippetCursor(1).use { cursor ->
|
||||
cursor.moveToFirst()
|
||||
assertEquals(1, CursorUtil.requireLong(cursor, MessageTable.ID))
|
||||
}
|
||||
|
||||
TestSms.insert(db, receivedTimestampMillis = timestamp + 3, type = MessageTypes.BASE_SENDING_TYPE or MessageTypes.SECURE_MESSAGE_BIT or MessageTypes.PUSH_MESSAGE_BIT or MessageTypes.GROUP_V2_LEAVE_BITS)
|
||||
mmsSmsTable.getConversationSnippetCursor(1).use { cursor ->
|
||||
messageTable.getConversationSnippetCursor(1).use { cursor ->
|
||||
cursor.moveToFirst()
|
||||
assertEquals(1, CursorUtil.requireLong(cursor, MessageTable.ID))
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package org.thoughtcrime.securesms.jobmanager.migrations;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.thoughtcrime.securesms.database.MessageTable;
|
||||
import org.thoughtcrime.securesms.database.MmsSmsTable;
|
||||
import org.thoughtcrime.securesms.jobmanager.Data;
|
||||
import org.thoughtcrime.securesms.jobmanager.JobMigration;
|
||||
@@ -17,7 +18,7 @@ import static org.mockito.Mockito.when;
|
||||
|
||||
public class SendReadReceiptsJobMigrationTest {
|
||||
|
||||
private final MmsSmsTable mockDatabase = mock(MmsSmsTable.class);
|
||||
private final MessageTable mockDatabase = mock(MessageTable.class);
|
||||
private final SendReadReceiptsJobMigration testSubject = new SendReadReceiptsJobMigration(mockDatabase);
|
||||
|
||||
@Test
|
||||
@@ -30,7 +31,7 @@ public class SendReadReceiptsJobMigrationTest {
|
||||
.putString("recipient", RecipientId.from(2).serialize())
|
||||
.putLongArray("message_ids", new long[]{1, 2, 3, 4, 5})
|
||||
.putLong("timestamp", 292837649).build());
|
||||
when(mockDatabase.getThreadForMessageId(anyLong())).thenReturn(1234L);
|
||||
when(mockDatabase.getThreadIdForMessage(anyLong())).thenReturn(1234L);
|
||||
|
||||
// WHEN
|
||||
JobMigration.JobData result = testSubject.migrate(jobData);
|
||||
@@ -52,7 +53,7 @@ public class SendReadReceiptsJobMigrationTest {
|
||||
.putString("recipient", RecipientId.from(2).serialize())
|
||||
.putLongArray("message_ids", new long[]{})
|
||||
.putLong("timestamp", 292837649).build());
|
||||
when(mockDatabase.getThreadForMessageId(anyLong())).thenReturn(-1L);
|
||||
when(mockDatabase.getThreadIdForMessage(anyLong())).thenReturn(-1L);
|
||||
|
||||
// WHEN
|
||||
JobMigration.JobData result = testSubject.migrate(jobData);
|
||||
|
||||
@@ -10,11 +10,10 @@ import org.mockito.Mock;
|
||||
import org.mockito.MockedStatic;
|
||||
import org.mockito.junit.MockitoJUnit;
|
||||
import org.mockito.junit.MockitoRule;
|
||||
import org.thoughtcrime.securesms.database.MmsSmsTable;
|
||||
import org.thoughtcrime.securesms.database.MessageTable;
|
||||
import org.thoughtcrime.securesms.database.RecipientTable;
|
||||
import org.thoughtcrime.securesms.database.SignalDatabase;
|
||||
import org.thoughtcrime.securesms.database.ThreadTable;
|
||||
import org.thoughtcrime.securesms.util.FeatureFlags;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
@@ -29,22 +28,19 @@ public class RecipientUtilTest {
|
||||
@Rule
|
||||
public MockitoRule rule = MockitoJUnit.rule();
|
||||
|
||||
private Context context = mock(Context.class);
|
||||
private Context context = mock(Context.class);
|
||||
private Recipient recipient = mock(Recipient.class);
|
||||
private ThreadTable mockThreadTable = mock(ThreadTable.class);
|
||||
private MmsSmsTable mockMmsSmsDatabase = mock(MmsSmsTable.class);
|
||||
private MessageTable mockMessageTable = mock(MessageTable.class);
|
||||
private RecipientTable mockRecipientTable = mock(RecipientTable.class);
|
||||
|
||||
@Mock
|
||||
private MockedStatic<SignalDatabase> signalDatabaseMockedStatic;
|
||||
|
||||
@Mock
|
||||
private MockedStatic<FeatureFlags> featureFlagsMockedStatic;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
signalDatabaseMockedStatic.when(SignalDatabase::threads).thenReturn(mockThreadTable);
|
||||
signalDatabaseMockedStatic.when(SignalDatabase::mmsSms).thenReturn(mockMmsSmsDatabase);
|
||||
signalDatabaseMockedStatic.when(SignalDatabase::messages).thenReturn(mockMessageTable);
|
||||
signalDatabaseMockedStatic.when(SignalDatabase::recipients).thenReturn(mockRecipientTable);
|
||||
|
||||
when(recipient.getId()).thenReturn(RecipientId.from(5));
|
||||
@@ -73,7 +69,7 @@ public class RecipientUtilTest {
|
||||
public void givenIHaveSentASecureMessageInThisThread_whenIsThreadMessageRequestAccepted_thenIExpectTrue() {
|
||||
// GIVEN
|
||||
when(mockThreadTable.getRecipientForThreadId(anyLong())).thenReturn(recipient);
|
||||
when(mockMmsSmsDatabase.getOutgoingSecureConversationCount(1L)).thenReturn(5);
|
||||
when(mockMessageTable.getOutgoingSecureMessageCount(1L)).thenReturn(5);
|
||||
|
||||
// WHEN
|
||||
boolean result = RecipientUtil.isMessageRequestAccepted(context, 1L);
|
||||
@@ -87,7 +83,7 @@ public class RecipientUtilTest {
|
||||
// GIVEN
|
||||
when(recipient.isProfileSharing()).thenReturn(true);
|
||||
when(mockThreadTable.getRecipientForThreadId(anyLong())).thenReturn(recipient);
|
||||
when(mockMmsSmsDatabase.getOutgoingSecureConversationCount(1L)).thenReturn(0);
|
||||
when(mockMessageTable.getOutgoingSecureMessageCount(1L)).thenReturn(0);
|
||||
|
||||
// WHEN
|
||||
boolean result = RecipientUtil.isMessageRequestAccepted(context, 1L);
|
||||
@@ -101,7 +97,7 @@ public class RecipientUtilTest {
|
||||
// GIVEN
|
||||
when(recipient.isSystemContact()).thenReturn(true);
|
||||
when(mockThreadTable.getRecipientForThreadId(anyLong())).thenReturn(recipient);
|
||||
when(mockMmsSmsDatabase.getOutgoingSecureConversationCount(1L)).thenReturn(0);
|
||||
when(mockMessageTable.getOutgoingSecureMessageCount(1L)).thenReturn(0);
|
||||
|
||||
// WHEN
|
||||
boolean result = RecipientUtil.isMessageRequestAccepted(context, 1L);
|
||||
@@ -115,8 +111,8 @@ public class RecipientUtilTest {
|
||||
public void givenIHaveReceivedASecureMessageIHaveNotSentASecureMessageAndRecipientIsNotSystemContactAndNotProfileSharing_whenIsThreadMessageRequestAccepted_thenIExpectFalse() {
|
||||
// GIVEN
|
||||
when(mockThreadTable.getRecipientForThreadId(anyLong())).thenReturn(recipient);
|
||||
when(mockMmsSmsDatabase.getOutgoingSecureConversationCount(1L)).thenReturn(0);
|
||||
when(mockMmsSmsDatabase.getSecureConversationCount(1L)).thenReturn(5);
|
||||
when(mockMessageTable.getOutgoingSecureMessageCount(1L)).thenReturn(0);
|
||||
when(mockMessageTable.getSecureMessageCount(1L)).thenReturn(5);
|
||||
|
||||
// WHEN
|
||||
boolean result = RecipientUtil.isMessageRequestAccepted(context, 1L);
|
||||
@@ -129,8 +125,8 @@ public class RecipientUtilTest {
|
||||
public void givenIHaveNotReceivedASecureMessageIHaveNotSentASecureMessageAndRecipientIsNotSystemContactAndNotProfileSharing_whenIsThreadMessageRequestAccepted_thenIExpectTrue() {
|
||||
// GIVEN
|
||||
when(mockThreadTable.getRecipientForThreadId(anyLong())).thenReturn(recipient);
|
||||
when(mockMmsSmsDatabase.getOutgoingSecureConversationCount(1L)).thenReturn(0);
|
||||
when(mockMmsSmsDatabase.getSecureConversationCount(1L)).thenReturn(0);
|
||||
when(mockMessageTable.getOutgoingSecureMessageCount(1L)).thenReturn(0);
|
||||
when(mockMessageTable.getSecureMessageCount(1L)).thenReturn(0);
|
||||
|
||||
// WHEN
|
||||
boolean result = RecipientUtil.isMessageRequestAccepted(context, 1L);
|
||||
@@ -151,7 +147,7 @@ public class RecipientUtilTest {
|
||||
@Test
|
||||
public void givenNonZeroOutgoingSecureMessageCount_whenIsRecipientMessageRequestAccepted_thenIExpectTrue() {
|
||||
// GIVEN
|
||||
when(mockMmsSmsDatabase.getOutgoingSecureConversationCount(anyLong())).thenReturn(1);
|
||||
when(mockMessageTable.getOutgoingSecureMessageCount(anyLong())).thenReturn(1);
|
||||
|
||||
// WHEN
|
||||
boolean result = RecipientUtil.isMessageRequestAccepted(context, recipient);
|
||||
@@ -189,7 +185,7 @@ public class RecipientUtilTest {
|
||||
public void givenNoSecureMessagesSentSomeSecureMessagesReceivedNotSharingAndNotSystemContact_whenIsRecipientMessageRequestAccepted_thenIExpectFalse() {
|
||||
// GIVEN
|
||||
when(recipient.isRegistered()).thenReturn(true);
|
||||
when(mockMmsSmsDatabase.getSecureConversationCount(anyLong())).thenReturn(5);
|
||||
when(mockMessageTable.getSecureMessageCount(anyLong())).thenReturn(5);
|
||||
|
||||
// WHEN
|
||||
boolean result = RecipientUtil.isMessageRequestAccepted(context, recipient);
|
||||
@@ -201,7 +197,7 @@ public class RecipientUtilTest {
|
||||
@Test
|
||||
public void givenNoSecureMessagesSentNoSecureMessagesReceivedNotSharingAndNotSystemContact_whenIsRecipientMessageRequestAccepted_thenIExpectTrue() {
|
||||
// GIVEN
|
||||
when(mockMmsSmsDatabase.getSecureConversationCount(anyLong())).thenReturn(0);
|
||||
when(mockMessageTable.getSecureMessageCount(anyLong())).thenReturn(0);
|
||||
|
||||
// WHEN
|
||||
boolean result = RecipientUtil.isMessageRequestAccepted(context, recipient);
|
||||
@@ -214,7 +210,7 @@ public class RecipientUtilTest {
|
||||
@Test
|
||||
public void givenNoSecureMessagesSent_whenIShareProfileIfFirstSecureMessage_thenIShareProfile() {
|
||||
// GIVEN
|
||||
when(mockMmsSmsDatabase.getOutgoingSecureConversationCount(anyLong())).thenReturn(0);
|
||||
when(mockMessageTable.getOutgoingSecureMessageCount(anyLong())).thenReturn(0);
|
||||
|
||||
// WHEN
|
||||
RecipientUtil.shareProfileIfFirstSecureMessage(recipient);
|
||||
@@ -227,7 +223,7 @@ public class RecipientUtilTest {
|
||||
@Test
|
||||
public void givenSecureMessagesSent_whenIShareProfileIfFirstSecureMessage_thenIShareProfile() {
|
||||
// GIVEN
|
||||
when(mockMmsSmsDatabase.getOutgoingSecureConversationCount(anyLong())).thenReturn(5);
|
||||
when(mockMessageTable.getOutgoingSecureMessageCount(anyLong())).thenReturn(5);
|
||||
|
||||
// WHEN
|
||||
RecipientUtil.shareProfileIfFirstSecureMessage(recipient);
|
||||
|
||||
Reference in New Issue
Block a user