@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(); }
@Test public void testRestoreTaskSerde() throws Exception { final RestoreTask task = new RestoreTask(null, "foo", new Interval("2010-01-01/P1D"), null); final String json = jsonMapper.writeValueAsString(task); Thread.sleep(100); // Just want to run the clock a bit to make sure the task id doesn't change final RestoreTask task2 = (RestoreTask) jsonMapper.readValue(json, Task.class); Assert.assertEquals("foo", task.getDataSource()); Assert.assertEquals(new Interval("2010-01-01/P1D"), task.getInterval()); Assert.assertEquals(task.getId(), task2.getId()); Assert.assertEquals(task.getGroupId(), task2.getGroupId()); Assert.assertEquals(task.getDataSource(), task2.getDataSource()); Assert.assertEquals(task.getInterval(), task2.getInterval()); }
@Test public void shouldVerifyStoreSettings() throws Exception { task.doInBackground(config); verify(store).checkSettings(); }
@Test public void shouldCloseFolders() throws Exception { task.doInBackground(config); verify(store).closeFolders(); }
@Test public void shouldAcquireAndReleaseLocksDuringRestore() throws Exception { task.doInBackground(config); verify(service).acquireLocks(); verify(service).releaseLocks(); }