Search in sources :

Example 1 with SendReadReceiptJob

use of org.thoughtcrime.securesms.jobs.SendReadReceiptJob in project Signal-Android by WhisperSystems.

the class SendReadReceiptsJobMigrationTest method givenSendReadReceiptJobDataWithoutThreadIdAndThreadIdFound_whenIMigrate_thenIInsertThreadId.

@Test
public void givenSendReadReceiptJobDataWithoutThreadIdAndThreadIdFound_whenIMigrate_thenIInsertThreadId() {
    // GIVEN
    SendReadReceiptJob job = new SendReadReceiptJob(1, RecipientId.from(2), new ArrayList<>(), new ArrayList<>());
    JobMigration.JobData jobData = new JobMigration.JobData(job.getFactoryKey(), "asdf", new Data.Builder().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
    JobMigration.JobData result = testSubject.migrate(jobData);
    // THEN
    assertEquals(1234L, result.getData().getLong("thread"));
    assertEquals(RecipientId.from(2).serialize(), result.getData().getString("recipient"));
    assertTrue(result.getData().hasLongArray("message_ids"));
    assertTrue(result.getData().hasLong("timestamp"));
}
Also used : SendReadReceiptJob(org.thoughtcrime.securesms.jobs.SendReadReceiptJob) JobMigration(org.thoughtcrime.securesms.jobmanager.JobMigration) Data(org.thoughtcrime.securesms.jobmanager.Data) Test(org.junit.Test)

Example 2 with SendReadReceiptJob

use of org.thoughtcrime.securesms.jobs.SendReadReceiptJob in project Signal-Android by WhisperSystems.

the class SendReadReceiptsJobMigrationTest method givenSendReadReceiptJobDataWithThreadId_whenIMigrate_thenIDoNotReplace.

@Test
public void givenSendReadReceiptJobDataWithThreadId_whenIMigrate_thenIDoNotReplace() {
    // GIVEN
    SendReadReceiptJob job = new SendReadReceiptJob(1, RecipientId.from(2), new ArrayList<>(), new ArrayList<>());
    JobMigration.JobData jobData = new JobMigration.JobData(job.getFactoryKey(), "asdf", job.serialize());
    // WHEN
    JobMigration.JobData result = testSubject.migrate(jobData);
    // THEN
    assertEquals(jobData, result);
}
Also used : SendReadReceiptJob(org.thoughtcrime.securesms.jobs.SendReadReceiptJob) JobMigration(org.thoughtcrime.securesms.jobmanager.JobMigration) Test(org.junit.Test)

Example 3 with SendReadReceiptJob

use of org.thoughtcrime.securesms.jobs.SendReadReceiptJob in project Signal-Android by signalapp.

the class SendReadReceiptsJobMigrationTest method givenSendReadReceiptJobDataWithoutThreadIdAndThreadIdNotFound_whenIMigrate_thenIGetAFailingJob.

@Test
public void givenSendReadReceiptJobDataWithoutThreadIdAndThreadIdNotFound_whenIMigrate_thenIGetAFailingJob() {
    // GIVEN
    SendReadReceiptJob job = new SendReadReceiptJob(1, RecipientId.from(2), new ArrayList<>(), new ArrayList<>());
    JobMigration.JobData jobData = new JobMigration.JobData(job.getFactoryKey(), "asdf", new Data.Builder().putString("recipient", RecipientId.from(2).serialize()).putLongArray("message_ids", new long[] {}).putLong("timestamp", 292837649).build());
    when(mockDatabase.getThreadForMessageId(anyLong())).thenReturn(-1L);
    // WHEN
    JobMigration.JobData result = testSubject.migrate(jobData);
    // THEN
    assertEquals("FailingJob", result.getFactoryKey());
}
Also used : SendReadReceiptJob(org.thoughtcrime.securesms.jobs.SendReadReceiptJob) JobMigration(org.thoughtcrime.securesms.jobmanager.JobMigration) Data(org.thoughtcrime.securesms.jobmanager.Data) Test(org.junit.Test)

Example 4 with SendReadReceiptJob

use of org.thoughtcrime.securesms.jobs.SendReadReceiptJob in project Signal-Android by signalapp.

the class SendReadReceiptsJobMigrationTest method givenSendReadReceiptJobDataWithThreadId_whenIMigrate_thenIDoNotReplace.

@Test
public void givenSendReadReceiptJobDataWithThreadId_whenIMigrate_thenIDoNotReplace() {
    // GIVEN
    SendReadReceiptJob job = new SendReadReceiptJob(1, RecipientId.from(2), new ArrayList<>(), new ArrayList<>());
    JobMigration.JobData jobData = new JobMigration.JobData(job.getFactoryKey(), "asdf", job.serialize());
    // WHEN
    JobMigration.JobData result = testSubject.migrate(jobData);
    // THEN
    assertEquals(jobData, result);
}
Also used : SendReadReceiptJob(org.thoughtcrime.securesms.jobs.SendReadReceiptJob) JobMigration(org.thoughtcrime.securesms.jobmanager.JobMigration) Test(org.junit.Test)

Example 5 with SendReadReceiptJob

use of org.thoughtcrime.securesms.jobs.SendReadReceiptJob in project Signal-Android by WhisperSystems.

the class SendReadReceiptsJobMigrationTest method givenSendReadReceiptJobDataWithoutThreadIdAndThreadIdNotFound_whenIMigrate_thenIGetAFailingJob.

@Test
public void givenSendReadReceiptJobDataWithoutThreadIdAndThreadIdNotFound_whenIMigrate_thenIGetAFailingJob() {
    // GIVEN
    SendReadReceiptJob job = new SendReadReceiptJob(1, RecipientId.from(2), new ArrayList<>(), new ArrayList<>());
    JobMigration.JobData jobData = new JobMigration.JobData(job.getFactoryKey(), "asdf", new Data.Builder().putString("recipient", RecipientId.from(2).serialize()).putLongArray("message_ids", new long[] {}).putLong("timestamp", 292837649).build());
    when(mockDatabase.getThreadForMessageId(anyLong())).thenReturn(-1L);
    // WHEN
    JobMigration.JobData result = testSubject.migrate(jobData);
    // THEN
    assertEquals("FailingJob", result.getFactoryKey());
}
Also used : SendReadReceiptJob(org.thoughtcrime.securesms.jobs.SendReadReceiptJob) JobMigration(org.thoughtcrime.securesms.jobmanager.JobMigration) Data(org.thoughtcrime.securesms.jobmanager.Data) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)6 JobMigration (org.thoughtcrime.securesms.jobmanager.JobMigration)6 SendReadReceiptJob (org.thoughtcrime.securesms.jobs.SendReadReceiptJob)6 Data (org.thoughtcrime.securesms.jobmanager.Data)4