@Test
  public void shouldRestoreItems() throws Exception {
    Date now = new Date();
    List<ImapStore.ImapMessage> messages = new ArrayList<ImapStore.ImapMessage>();
    ContentValues values = new ContentValues();
    values.put(SmsConsts.TYPE, SmsConsts.MESSAGE_TYPE_INBOX);
    values.put(SmsConsts.DATE, now.getTime());

    ImapStore.ImapMessage mockMessage = mock(ImapStore.ImapMessage.class);
    when(mockMessage.getFolder()).thenReturn(folder);
    when(converter.getDataType(mockMessage)).thenReturn(DataType.SMS);
    when(converter.messageToContentValues(mockMessage)).thenReturn(values);

    messages.add(mockMessage);

    when(folder.getMessages(anyInt(), anyBoolean(), any(Date.class))).thenReturn(messages);
    when(resolver.insert(Consts.SMS_PROVIDER, values)).thenReturn(Uri.parse("content://sms/123"));
    task.doInBackground(config);

    verify(resolver).insert(Consts.SMS_PROVIDER, values);
    verify(resolver).delete(Uri.parse("content://sms/conversations/-1"), null, null);

    assertThat(DataType.SMS.getMaxSyncedDate(context)).isEqualTo(now.getTime());
    assertThat(task.getSmsIds()).containsExactly("123");

    verify(store).closeFolders();
  }
Ejemplo n.º 2
0
 @Test
 public void testMessageToContentValuesWithCalllogFromUnknownPerson() throws Exception {
   PersonRecord record = new PersonRecord(-1, null, null, null);
   when(personLookup.lookupPerson("+12121")).thenReturn(record);
   final ContentValues values = messageConverter.messageToContentValues(createCallLogMessage());
   assertThat(values.containsKey(CallLog.Calls.CACHED_NAME)).isFalse();
   assertThat(values.containsKey(CallLog.Calls.CACHED_NUMBER_TYPE)).isFalse();
 }
Ejemplo n.º 3
0
 @Test
 public void testMessageToContentValuesWithCalllog() throws Exception {
   PersonRecord record = new PersonRecord(1, "The name", "*****@*****.**", "+1234");
   when(personLookup.lookupPerson("+12121")).thenReturn(record);
   final ContentValues values = messageConverter.messageToContentValues(createCallLogMessage());
   assertThat(values.getAsString(CallLog.Calls.NUMBER)).isEqualTo("+12121");
   assertThat(values.getAsString(CallLog.Calls.TYPE)).isEqualTo("3");
   assertThat(values.getAsString(CallLog.Calls.DATE)).isEqualTo("1419163218194");
   assertThat(values.getAsLong(CallLog.Calls.DURATION)).isEqualTo(44L);
   assertThat(values.getAsInteger(CallLog.Calls.NEW)).isEqualTo(0);
   assertThat(values.getAsString(CallLog.Calls.CACHED_NAME)).isEqualTo("The name");
   assertThat(values.getAsInteger(CallLog.Calls.CACHED_NUMBER_TYPE)).isEqualTo(-2);
 }
Ejemplo n.º 4
0
 @Test
 public void testMessageToContentValuesWithSMS() throws Exception {
   final ContentValues values = messageConverter.messageToContentValues(createSMSMessage());
   assertThat(values.getAsString(SmsConsts.ADDRESS)).isEqualTo("+121332");
   assertThat(values.getAsString(SmsConsts.TYPE)).isEqualTo("2");
   assertThat(values.getAsString(SmsConsts.PROTOCOL)).isNull();
   assertThat(values.getAsString(SmsConsts.SERVICE_CENTER)).isNull();
   assertThat(values.getAsString(SmsConsts.DATE)).isEqualTo("1420759456762");
   assertThat(values.getAsString(SmsConsts.STATUS)).isEqualTo("-1");
   assertThat(values.getAsString(SmsConsts.THREAD_ID)).isNull();
   assertThat(values.getAsString(SmsConsts.READ)).isEqualTo("1");
   assertThat(values.getAsString(SmsConsts.BODY)).isEqualTo("DasßAsß");
 }
Ejemplo n.º 5
0
  @Test
  public void testMessageToContentValuesWithUnknownMessageTypeGetParsedAsSMS() throws Exception {
    final String message =
        "Subject: Call with +12121\n"
            + "From: +12121 <*****@*****.**>\n"
            + "To: [email protected]\n"
            + "MIME-Version: 1.0\n"
            + "Content-Type: text/plain;\n"
            + " charset=utf-8\n"
            + "References: <*****@*****.**>\n"
            + "Message-ID: <*****@*****.**>\n"
            + "X-smssync-datatype: INVALID\n"
            + "Content-Transfer-Encoding: quoted-printable\n"
            + "\n"
            + "Some Text";

    final MimeMessage mimeMessage =
        new MimeMessage(new ByteArrayInputStream(message.getBytes()), true);
    final ContentValues values = messageConverter.messageToContentValues(mimeMessage);
    assertThat(values.getAsString(SmsConsts.ADDRESS)).isNull();
  }
Ejemplo n.º 6
0
 @Test(expected = MessagingException.class)
 public void testMessageToContentValuesWithNullMessageThrowsMessagingException() throws Exception {
   messageConverter.messageToContentValues(null);
 }