0
0
mirror of https://github.com/thunderbird/thunderbird-android.git synced 2024-09-20 04:02:14 +02:00

Upgrade to Mockito 2

This commit is contained in:
cketti 2018-04-16 04:28:44 +02:00
parent 0c6209447c
commit 53961b0f73
15 changed files with 185 additions and 142 deletions

View File

@ -7,7 +7,7 @@ koinVersion=0.9.1
robolectricVersion=3.7.1
junitVersion=4.12
mockitoVersion=1.10.19
mockitoVersion=2.18.0
okioVersion=1.11.0
truthVersion=0.35

View File

@ -48,6 +48,7 @@ import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.mockito.ArgumentMatchers.nullable;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anySetOf;
import static org.mockito.Matchers.anyString;
@ -798,7 +799,7 @@ public class ImapFolderTest {
ImapFolder folder = createFolder("Folder");
prepareImapFolderForOpen(OPEN_MODE_RO);
folder.open(OPEN_MODE_RO);
when(imapConnection.readResponse(any(ImapResponseCallback.class))).thenReturn(createImapResponse("x OK"));
when(imapConnection.readResponse(nullable(ImapResponseCallback.class))).thenReturn(createImapResponse("x OK"));
List<ImapMessage> messages = createImapMessages("1");
FetchProfile fetchProfile = createFetchProfile(Item.FLAGS);
@ -812,7 +813,7 @@ public class ImapFolderTest {
ImapFolder folder = createFolder("Folder");
prepareImapFolderForOpen(OPEN_MODE_RO);
folder.open(OPEN_MODE_RO);
when(imapConnection.readResponse(any(ImapResponseCallback.class))).thenReturn(createImapResponse("x OK"));
when(imapConnection.readResponse(nullable(ImapResponseCallback.class))).thenReturn(createImapResponse("x OK"));
List<ImapMessage> messages = createImapMessages("1");
FetchProfile fetchProfile = createFetchProfile(Item.ENVELOPE);
@ -828,7 +829,7 @@ public class ImapFolderTest {
ImapFolder folder = createFolder("Folder");
prepareImapFolderForOpen(OPEN_MODE_RO);
folder.open(OPEN_MODE_RO);
when(imapConnection.readResponse(any(ImapResponseCallback.class))).thenReturn(createImapResponse("x OK"));
when(imapConnection.readResponse(nullable(ImapResponseCallback.class))).thenReturn(createImapResponse("x OK"));
List<ImapMessage> messages = createImapMessages("1");
FetchProfile fetchProfile = createFetchProfile(Item.STRUCTURE);
@ -843,7 +844,7 @@ public class ImapFolderTest {
prepareImapFolderForOpen(OPEN_MODE_RO);
folder.open(OPEN_MODE_RO);
String bodyStructure = "(\"TEXT\" \"PLAIN\" (\"CHARSET\" \"US-ASCII\") NIL NIL \"7BIT\" 2279 48)";
when(imapConnection.readResponse(any(ImapResponseCallback.class)))
when(imapConnection.readResponse(nullable(ImapResponseCallback.class)))
.thenReturn(createImapResponse("* 1 FETCH (BODYSTRUCTURE "+bodyStructure+" UID 1)"))
.thenReturn(createImapResponse("x OK"));
List<ImapMessage> messages = createImapMessages("1");
@ -859,7 +860,7 @@ public class ImapFolderTest {
ImapFolder folder = createFolder("Folder");
prepareImapFolderForOpen(OPEN_MODE_RO);
folder.open(OPEN_MODE_RO);
when(imapConnection.readResponse(any(ImapResponseCallback.class))).thenReturn(createImapResponse("x OK"));
when(imapConnection.readResponse(nullable(ImapResponseCallback.class))).thenReturn(createImapResponse("x OK"));
List<ImapMessage> messages = createImapMessages("1");
FetchProfile fetchProfile = createFetchProfile(Item.BODY_SANE);
when(storeConfig.getMaximumAutoDownloadMessageSize()).thenReturn(4096);
@ -874,7 +875,7 @@ public class ImapFolderTest {
ImapFolder folder = createFolder("Folder");
prepareImapFolderForOpen(OPEN_MODE_RO);
folder.open(OPEN_MODE_RO);
when(imapConnection.readResponse(any(ImapResponseCallback.class))).thenReturn(createImapResponse("x OK"));
when(imapConnection.readResponse(nullable(ImapResponseCallback.class))).thenReturn(createImapResponse("x OK"));
List<ImapMessage> messages = createImapMessages("1");
FetchProfile fetchProfile = createFetchProfile(Item.BODY_SANE);
when(storeConfig.getMaximumAutoDownloadMessageSize()).thenReturn(0);
@ -889,7 +890,7 @@ public class ImapFolderTest {
ImapFolder folder = createFolder("Folder");
prepareImapFolderForOpen(OPEN_MODE_RO);
folder.open(OPEN_MODE_RO);
when(imapConnection.readResponse(any(ImapResponseCallback.class))).thenReturn(createImapResponse("x OK"));
when(imapConnection.readResponse(nullable(ImapResponseCallback.class))).thenReturn(createImapResponse("x OK"));
List<ImapMessage> messages = createImapMessages("1");
FetchProfile fetchProfile = createFetchProfile(Item.BODY);
@ -905,7 +906,7 @@ public class ImapFolderTest {
folder.open(OPEN_MODE_RO);
List<ImapMessage> messages = createImapMessages("1");
FetchProfile fetchProfile = createFetchProfile(Item.FLAGS);
when(imapConnection.readResponse(any(ImapResponseCallback.class)))
when(imapConnection.readResponse(nullable(ImapResponseCallback.class)))
.thenReturn(createImapResponse("* 1 FETCH (FLAGS (\\Seen) UID 1)"))
.thenReturn(createImapResponse("x OK"));
@ -923,7 +924,7 @@ public class ImapFolderTest {
folder.open(OPEN_MODE_RO);
ImapMessage message = createImapMessage("1");
Part part = createPart("TEXT");
when(imapConnection.readResponse(any(ImapResponseCallback.class))).thenReturn(createImapResponse("x OK"));
when(imapConnection.readResponse(nullable(ImapResponseCallback.class))).thenReturn(createImapResponse("x OK"));
folder.fetchPart(message, part, null, null);
@ -937,7 +938,7 @@ public class ImapFolderTest {
folder.open(OPEN_MODE_RO);
ImapMessage message = createImapMessage("1");
Part part = createPart("1.1");
when(imapConnection.readResponse(any(ImapResponseCallback.class))).thenReturn(createImapResponse("x OK"));
when(imapConnection.readResponse(nullable(ImapResponseCallback.class))).thenReturn(createImapResponse("x OK"));
folder.fetchPart(message, part, null, null);
@ -1147,7 +1148,7 @@ public class ImapFolderTest {
}
private void setupSingleFetchResponseToCallback() throws IOException {
when(imapConnection.readResponse(any(ImapResponseCallback.class)))
when(imapConnection.readResponse(nullable(ImapResponseCallback.class)))
.thenAnswer(new Answer<ImapResponse>() {
@Override
public ImapResponse answer(InvocationOnMock invocation) throws Throwable {

View File

@ -40,6 +40,7 @@ import static java.util.Collections.singletonList;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.nullable;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyBoolean;
import static org.mockito.Matchers.anyInt;
@ -90,6 +91,8 @@ public class WebDavFolderTest {
when(mockStore.getUrl()).thenReturn(storeUrl);
when(mockStore.getHttpClient()).thenReturn(mockHttpClient);
when(mockStore.getStoreConfig()).thenReturn(mockStoreConfig);
when(mockStore.getMessageEnvelopeXml(any(String[].class))).thenReturn("mockEnvelopeXml");
when(mockStore.getMessageFlagsXml(any(String[].class))).thenReturn("mockFlagsXml");
folder = new WebDavFolder(mockStore, folderName);
setupTempDirectory();
@ -127,6 +130,10 @@ public class WebDavFolderTest {
return webDavMessage;
}
private WebDavMessage createWebDavMessage(int uid) {
return createWebDavMessage(String.valueOf(uid));
}
private void setupGetUrlsRequestResponse(String uid, String url) throws MessagingException {
String getUrlsXml = "<xml>GetUrls</xml>";
when(mockStore.getMessageUrlsXml(new String[]{uid})).thenReturn(getUrlsXml);
@ -146,7 +153,7 @@ public class WebDavFolderTest {
List<WebDavMessage> messages = new ArrayList<>();
for (int i = 0; i < 5; i++) {
WebDavMessage mockMessage = mock(WebDavMessage.class);
WebDavMessage mockMessage = createWebDavMessage(i);
messages.add(mockMessage);
}
@ -163,7 +170,7 @@ public class WebDavFolderTest {
List<WebDavMessage> messages = new ArrayList<>();
for (int i = 0; i < 15; i++) {
WebDavMessage mockMessage = mock(WebDavMessage.class);
WebDavMessage mockMessage = createWebDavMessage(i);
messages.add(mockMessage);
}
FetchProfile profile = new FetchProfile();
@ -179,7 +186,7 @@ public class WebDavFolderTest {
List<WebDavMessage> messages = new ArrayList<>();
for (int i = 0; i < 5; i++) {
WebDavMessage mockMessage = mock(WebDavMessage.class);
WebDavMessage mockMessage = createWebDavMessage(i);
messages.add(mockMessage);
}
FetchProfile profile = new FetchProfile();
@ -195,7 +202,7 @@ public class WebDavFolderTest {
List<WebDavMessage> messages = new ArrayList<>();
for (int i = 0; i < 25; i++) {
WebDavMessage mockMessage = mock(WebDavMessage.class);
WebDavMessage mockMessage = createWebDavMessage(i);
messages.add(mockMessage);
}
@ -210,7 +217,7 @@ public class WebDavFolderTest {
setupStoreForMessageFetching();
List<WebDavMessage> messages = setup25MessagesToFetch();
when(mockHttpClient.executeOverride(any(HttpUriRequest.class), any(HttpContext.class))).thenAnswer(
when(mockHttpClient.executeOverride(any(HttpUriRequest.class), nullable(HttpContext.class))).thenAnswer(
new Answer<HttpResponse>() {
@Override
public HttpResponse answer(InvocationOnMock invocation) throws Throwable {
@ -242,7 +249,7 @@ public class WebDavFolderTest {
anyMapOf(String.class, String.class)))
.thenReturn(mockDataSet);
List<WebDavMessage> messages = setup25MessagesToFetch();
when(mockHttpClient.executeOverride(any(HttpUriRequest.class), any(HttpContext.class))).thenAnswer(
when(mockHttpClient.executeOverride(any(HttpUriRequest.class), nullable(HttpContext.class))).thenAnswer(
new Answer<HttpResponse>() {
@Override
public HttpResponse answer(InvocationOnMock invocation) throws Throwable {
@ -290,7 +297,7 @@ public class WebDavFolderTest {
setupStoreForMessageFetching();
List<WebDavMessage> messages = setup25MessagesToFetch();
when(mockHttpClient.executeOverride(any(HttpUriRequest.class), any(HttpContext.class))).thenAnswer(
when(mockHttpClient.executeOverride(any(HttpUriRequest.class), nullable(HttpContext.class))).thenAnswer(
new Answer<HttpResponse>() {
@Override
public HttpResponse answer(InvocationOnMock invocation) throws Throwable {
@ -314,7 +321,7 @@ public class WebDavFolderTest {
setupStoreForMessageFetching();
List<WebDavMessage> messages = setup25MessagesToFetch();
when(mockHttpClient.executeOverride(any(HttpUriRequest.class), any(HttpContext.class))).thenAnswer(
when(mockHttpClient.executeOverride(any(HttpUriRequest.class), nullable(HttpContext.class))).thenAnswer(
new Answer<HttpResponse>() {
@Override
public HttpResponse answer(InvocationOnMock invocation) throws Throwable {

View File

@ -31,7 +31,7 @@ import org.mockito.InOrder;
import static junit.framework.Assert.assertTrue;
import static junit.framework.Assert.fail;
import static org.junit.Assert.assertEquals;
import static org.mockito.Matchers.anyInt;
import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.inOrder;
@ -55,7 +55,7 @@ public class SmtpTransportTest {
public void before() throws AuthenticationFailedException {
socketFactory = TestTrustedSocketFactory.newInstance();
oAuth2TokenProvider = mock(OAuth2TokenProvider.class);
when(oAuth2TokenProvider.getToken(eq(USERNAME), anyInt()))
when(oAuth2TokenProvider.getToken(eq(USERNAME), anyLong()))
.thenReturn("oldToken").thenReturn("newToken");
}
@ -298,7 +298,7 @@ public class SmtpTransportTest {
}
InOrder inOrder = inOrder(oAuth2TokenProvider);
inOrder.verify(oAuth2TokenProvider).getToken(eq(USERNAME), anyInt());
inOrder.verify(oAuth2TokenProvider).getToken(eq(USERNAME), anyLong());
inOrder.verify(oAuth2TokenProvider).invalidateToken(USERNAME);
server.verifyConnectionClosed();
server.verifyInteractionCompleted();
@ -323,9 +323,9 @@ public class SmtpTransportTest {
transport.open();
InOrder inOrder = inOrder(oAuth2TokenProvider);
inOrder.verify(oAuth2TokenProvider).getToken(eq(USERNAME), anyInt());
inOrder.verify(oAuth2TokenProvider).getToken(eq(USERNAME), anyLong());
inOrder.verify(oAuth2TokenProvider).invalidateToken(USERNAME);
inOrder.verify(oAuth2TokenProvider).getToken(eq(USERNAME), anyInt());
inOrder.verify(oAuth2TokenProvider).getToken(eq(USERNAME), anyLong());
server.verifyConnectionStillOpen();
server.verifyInteractionCompleted();
}
@ -349,9 +349,9 @@ public class SmtpTransportTest {
transport.open();
InOrder inOrder = inOrder(oAuth2TokenProvider);
inOrder.verify(oAuth2TokenProvider).getToken(eq(USERNAME), anyInt());
inOrder.verify(oAuth2TokenProvider).getToken(eq(USERNAME), anyLong());
inOrder.verify(oAuth2TokenProvider).invalidateToken(USERNAME);
inOrder.verify(oAuth2TokenProvider).getToken(eq(USERNAME), anyInt());
inOrder.verify(oAuth2TokenProvider).getToken(eq(USERNAME), anyLong());
server.verifyConnectionStillOpen();
server.verifyInteractionCompleted();
}
@ -375,9 +375,9 @@ public class SmtpTransportTest {
transport.open();
InOrder inOrder = inOrder(oAuth2TokenProvider);
inOrder.verify(oAuth2TokenProvider).getToken(eq(USERNAME), anyInt());
inOrder.verify(oAuth2TokenProvider).getToken(eq(USERNAME), anyLong());
inOrder.verify(oAuth2TokenProvider).invalidateToken(USERNAME);
inOrder.verify(oAuth2TokenProvider).getToken(eq(USERNAME), anyInt());
inOrder.verify(oAuth2TokenProvider).getToken(eq(USERNAME), anyLong());
server.verifyConnectionStillOpen();
server.verifyInteractionCompleted();
}
@ -427,7 +427,8 @@ public class SmtpTransportTest {
server.output("250 AUTH XOAUTH2");
server.expect("QUIT");
server.output("221 BYE");
when(oAuth2TokenProvider.getToken(anyString(), anyInt())).thenThrow(new AuthenticationFailedException("Failed to fetch token"));
when(oAuth2TokenProvider.getToken(anyString(), anyLong()))
.thenThrow(new AuthenticationFailedException("Failed to fetch token"));
SmtpTransport transport = startServerAndCreateSmtpTransport(server, AuthType.XOAUTH2, ConnectionSecurity.NONE);
try {
@ -592,7 +593,7 @@ public class SmtpTransportTest {
}
InOrder inOrder = inOrder(oAuth2TokenProvider);
inOrder.verify(oAuth2TokenProvider).getToken(eq(USERNAME), anyInt());
inOrder.verify(oAuth2TokenProvider).getToken(eq(USERNAME), anyLong());
inOrder.verify(oAuth2TokenProvider).invalidateToken(USERNAME);
server.verifyConnectionClosed();
server.verifyInteractionCompleted();

View File

@ -21,6 +21,7 @@ import org.robolectric.RuntimeEnvironment;
import static android.provider.ContactsContract.CommonDataKinds.Email.TYPE_HOME;
import static org.junit.Assert.assertEquals;
import static org.mockito.AdditionalMatchers.aryEq;
import static org.mockito.ArgumentMatchers.nullable;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.eq;
import static org.mockito.Matchers.isNull;
@ -158,9 +159,9 @@ public class RecipientLoaderTest extends RobolectricTest {
when(contentResolver
.query(eq(Uri.parse("content://" + CRYPTO_PROVIDER + ".provider.exported/autocrypt_status")),
aryEq(PROJECTION_CRYPTO_ADDRESSES), any(String.class),
aryEq(PROJECTION_CRYPTO_ADDRESSES), nullable(String.class),
aryEq(new String[] { queriedAddress }),
any(String.class))).thenReturn(cursor);
nullable(String.class))).thenReturn(cursor);
}
private void setupCryptoProviderStatus(Address address, String uidStatus, String autocryptStatus) {
@ -169,9 +170,9 @@ public class RecipientLoaderTest extends RobolectricTest {
when(contentResolver
.query(eq(Uri.parse("content://" + CRYPTO_PROVIDER + ".provider.exported/autocrypt_status")),
aryEq(PROJECTION_CRYPTO_STATUS), any(String.class),
aryEq(PROJECTION_CRYPTO_STATUS), nullable(String.class),
aryEq(new String[] { address.getAddress() }),
any(String.class))).thenReturn(cursorCryptoStatus);
nullable(String.class))).thenReturn(cursorCryptoStatus);
}
private void setupContactProvider(String queriedAddress, String[]... contacts) {
@ -182,9 +183,9 @@ public class RecipientLoaderTest extends RobolectricTest {
when(contentResolver
.query(eq(Email.CONTENT_URI),
aryEq(PROJECTION),
any(String.class),
nullable(String.class),
aryEq(new String[] { queriedAddress, queriedAddress }),
any(String.class))).thenReturn(cursor);
nullable(String.class))).thenReturn(cursor);
}
private void setupNicknameContactProvider(String[]... contactsWithNickname) {
@ -195,9 +196,9 @@ public class RecipientLoaderTest extends RobolectricTest {
when(contentResolver
.query(eq(ContactsContract.Data.CONTENT_URI),
aryEq(PROJECTION_NICKNAME),
any(String.class),
any(String[].class),
any(String.class))).thenReturn(cursor);
nullable(String.class),
nullable(String[].class),
nullable(String.class))).thenReturn(cursor);
}
private void setupContactProviderForId(String id, String[]... contacts) {
@ -208,9 +209,9 @@ public class RecipientLoaderTest extends RobolectricTest {
when(contentResolver
.query(eq(Email.CONTENT_URI),
aryEq(PROJECTION),
any(String.class),
nullable(String.class),
aryEq(new String[] { id }),
any(String.class))).thenReturn(cursor);
nullable(String.class))).thenReturn(cursor);
}
@Test
@ -300,7 +301,7 @@ public class RecipientLoaderTest extends RobolectricTest {
aryEq(PROJECTION),
isNull(String.class),
isNull(String[].class),
any(String.class))).thenReturn(cursor);
nullable(String.class))).thenReturn(cursor);
}
}

View File

@ -107,7 +107,8 @@ public class RecipientPresenterTest extends K9RobolectricTest {
recipientPresenter.initFromReplyToMessage(message, false);
runBackgroundTask();
verify(recipientMvpView).addRecipients(eq(RecipientType.TO), any(Recipient[].class));
Recipient toRecipient = new Recipient(TO_ADDRESSES.to[0]);
verify(recipientMvpView).addRecipients(eq(RecipientType.TO), eq(toRecipient));
}
@Test

View File

@ -43,6 +43,7 @@ import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.ArgumentMatchers;
import org.mockito.Captor;
import org.mockito.InOrder;
import org.mockito.Matchers;
@ -55,6 +56,9 @@ import org.robolectric.shadows.ShadowLog;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.anyList;
import static org.mockito.ArgumentMatchers.isNull;
import static org.mockito.ArgumentMatchers.nullable;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Matchers.anySet;
@ -374,7 +378,7 @@ public class MessagingControllerTest extends K9RobolectricTest {
controller.searchLocalMessagesSynchronous(search, listener);
verify(localStore).searchForMessages(any(MessageRetrievalListener.class), eq(search));
verify(localStore).searchForMessages(nullable(MessageRetrievalListener.class), eq(search));
}
@Test
@ -384,7 +388,7 @@ public class MessagingControllerTest extends K9RobolectricTest {
LocalMessage localMessage = mock(LocalMessage.class);
when(localMessage.getFolder()).thenReturn(localFolder);
when(search.getAccountUuids()).thenReturn(new String[]{"allAccounts"});
when(localStore.searchForMessages(any(MessageRetrievalListener.class), eq(search)))
when(localStore.searchForMessages(nullable(MessageRetrievalListener.class), eq(search)))
.thenThrow(new MessagingException("Test"));
controller.searchLocalMessagesSynchronous(search, listener);
@ -410,7 +414,7 @@ public class MessagingControllerTest extends K9RobolectricTest {
when(remoteNewMessage2.getUid()).thenReturn("newMessageUid2");
when(localNewMessage2.getUid()).thenReturn("newMessageUid2");
when(remoteFolder.search(anyString(), anySet(), anySet())).thenReturn(remoteMessages);
when(localFolder.extractNewMessages(Matchers.<List<Message>>any())).thenReturn(newRemoteMessages);
when(localFolder.extractNewMessages(ArgumentMatchers.<Message>anyList())).thenReturn(newRemoteMessages);
when(localFolder.getMessage("newMessageUid1")).thenReturn(localNewMessage1);
when(localFolder.getMessage("newMessageUid2")).thenAnswer(
new Answer<LocalMessage>() {
@ -431,9 +435,9 @@ public class MessagingControllerTest extends K9RobolectricTest {
return null;
}
}).when(remoteFolder).fetch(
Matchers.<List<Message>>eq(Collections.singletonList(remoteNewMessage2)),
eq(Collections.singletonList(remoteNewMessage2)),
any(FetchProfile.class),
Matchers.<MessageRetrievalListener>eq(null));
isNull(MessageRetrievalListener.class));
reqFlags = Collections.singleton(Flag.ANSWERED);
forbiddenFlags = Collections.singleton(Flag.DELETED);
@ -715,7 +719,7 @@ public class MessagingControllerTest extends K9RobolectricTest {
LocalMessage localCopyOfRemoteDeletedMessage = mock(LocalMessage.class);
when(account.syncRemoteDeletions()).thenReturn(true);
when(localFolder.getAllMessagesAndEffectiveDates()).thenReturn(Collections.singletonMap(MESSAGE_UID1, 0L));
when(localFolder.getMessagesByUids(any(List.class)))
when(localFolder.getMessagesByUids(ArgumentMatchers.<String>anyList()))
.thenReturn(Collections.singletonList(localCopyOfRemoteDeletedMessage));
controller.synchronizeMailboxSynchronousLegacy(account, FOLDER_NAME, listener);
@ -751,7 +755,8 @@ public class MessagingControllerTest extends K9RobolectricTest {
when(account.getEarliestPollDate()).thenReturn(dateOfEarliestPoll);
when(localMessage.olderThan(dateOfEarliestPoll)).thenReturn(true);
when(localFolder.getAllMessagesAndEffectiveDates()).thenReturn(Collections.singletonMap(MESSAGE_UID1, 0L));
when(localFolder.getMessagesByUids(any(List.class))).thenReturn(Collections.singletonList(localMessage));
when(localFolder.getMessagesByUids(ArgumentMatchers.<String>anyList()))
.thenReturn(Collections.singletonList(localMessage));
controller.synchronizeMailboxSynchronousLegacy(account, FOLDER_NAME, listener);
@ -782,8 +787,8 @@ public class MessagingControllerTest extends K9RobolectricTest {
controller.synchronizeMailboxSynchronousLegacy(account, FOLDER_NAME, listener);
verify(remoteFolder, atLeastOnce()).fetch(any(List.class), fetchProfileCaptor.capture(),
any(MessageRetrievalListener.class));
verify(remoteFolder, atLeastOnce()).fetch(anyList(), fetchProfileCaptor.capture(),
nullable(MessageRetrievalListener.class));
assertTrue(fetchProfileCaptor.getAllValues().get(0).contains(FetchProfile.Item.FLAGS));
assertTrue(fetchProfileCaptor.getAllValues().get(0).contains(FetchProfile.Item.ENVELOPE));
assertEquals(2, fetchProfileCaptor.getAllValues().get(0).size());
@ -799,8 +804,8 @@ public class MessagingControllerTest extends K9RobolectricTest {
controller.synchronizeMailboxSynchronousLegacy(account, FOLDER_NAME, listener);
verify(remoteFolder, atLeastOnce()).fetch(any(List.class), fetchProfileCaptor.capture(),
any(MessageRetrievalListener.class));
verify(remoteFolder, atLeastOnce()).fetch(anyList(), fetchProfileCaptor.capture(),
nullable(MessageRetrievalListener.class));
assertEquals(1, fetchProfileCaptor.getAllValues().get(0).size());
assertTrue(fetchProfileCaptor.getAllValues().get(0).contains(FetchProfile.Item.ENVELOPE));
}
@ -817,8 +822,8 @@ public class MessagingControllerTest extends K9RobolectricTest {
controller.synchronizeMailboxSynchronousLegacy(account, FOLDER_NAME, listener);
verify(remoteFolder, atLeast(2)).fetch(any(List.class), fetchProfileCaptor.capture(),
any(MessageRetrievalListener.class));
verify(remoteFolder, atLeast(2)).fetch(anyList(), fetchProfileCaptor.capture(),
nullable(MessageRetrievalListener.class));
assertEquals(1, fetchProfileCaptor.getAllValues().get(1).size());
assertTrue(fetchProfileCaptor.getAllValues().get(1).contains(FetchProfile.Item.BODY));
}
@ -836,8 +841,8 @@ public class MessagingControllerTest extends K9RobolectricTest {
controller.synchronizeMailboxSynchronousLegacy(account, FOLDER_NAME, listener);
//TODO: Don't bother fetching messages of a size we don't have
verify(remoteFolder, atLeast(4)).fetch(any(List.class), fetchProfileCaptor.capture(),
any(MessageRetrievalListener.class));
verify(remoteFolder, atLeast(4)).fetch(anyList(), fetchProfileCaptor.capture(),
nullable(MessageRetrievalListener.class));
assertEquals(1, fetchProfileCaptor.getAllValues().get(2).size());
assertEquals(FetchProfile.Item.STRUCTURE, fetchProfileCaptor.getAllValues().get(2).get(0));
assertEquals(1, fetchProfileCaptor.getAllValues().get(3).size());
@ -887,19 +892,19 @@ public class MessagingControllerTest extends K9RobolectricTest {
}
return null;
}
}).when(remoteFolder).fetch(any(List.class), any(FetchProfile.class), any(MessageRetrievalListener.class));
}).when(remoteFolder).fetch(anyList(), any(FetchProfile.class), nullable(MessageRetrievalListener.class));
}
private Message buildSmallNewMessage() {
Message message = mock(Message.class);
when(message.olderThan(any(Date.class))).thenReturn(false);
when(message.olderThan(nullable(Date.class))).thenReturn(false);
when(message.getSize()).thenReturn((long) MAXIMUM_SMALL_MESSAGE_SIZE);
return message;
}
private Message buildLargeNewMessage() {
Message message = mock(Message.class);
when(message.olderThan(any(Date.class))).thenReturn(false);
when(message.olderThan(nullable(Date.class))).thenReturn(false);
when(message.getSize()).thenReturn((long) (MAXIMUM_SMALL_MESSAGE_SIZE + 1));
return message;
}
@ -915,8 +920,8 @@ public class MessagingControllerTest extends K9RobolectricTest {
when(remoteMessage.getUid()).thenReturn(messageUid);
when(localMessage.getUid()).thenReturn(messageUid);
when(remoteFolder.getMessages(anyInt(), anyInt(), any(Date.class), any(MessageRetrievalListener.class)))
.thenReturn(Collections.singletonList(remoteMessage));
when(remoteFolder.getMessages(anyInt(), anyInt(), nullable(Date.class),
nullable(MessageRetrievalListener.class))).thenReturn(Collections.singletonList(remoteMessage));
return localMessage;
}
@ -924,8 +929,8 @@ public class MessagingControllerTest extends K9RobolectricTest {
String messageUid = "UID";
Message remoteMessage = mock(Message.class);
when(remoteMessage.getUid()).thenReturn(messageUid);
when(remoteFolder.getMessages(anyInt(), anyInt(), any(Date.class), any(MessageRetrievalListener.class)))
.thenReturn(Collections.singletonList(remoteMessage));
when(remoteFolder.getMessages(anyInt(), anyInt(), nullable(Date.class),
nullable(MessageRetrievalListener.class))).thenReturn(Collections.singletonList(remoteMessage));
}
private void configureAccount() throws MessagingException {

View File

@ -38,6 +38,7 @@ import org.robolectric.shadows.ShadowLog;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.nullable;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Mockito.atLeast;
@ -253,7 +254,7 @@ public class ImapSyncTest extends RobolectricTest {
imapSync.sync(account, FOLDER_NAME, listener, remoteFolder);
verify(remoteFolder, atLeastOnce()).fetch(any(List.class), fetchProfileCaptor.capture(),
any(MessageRetrievalListener.class));
nullable(MessageRetrievalListener.class));
assertTrue(fetchProfileCaptor.getAllValues().get(0).contains(FetchProfile.Item.FLAGS));
assertTrue(fetchProfileCaptor.getAllValues().get(0).contains(FetchProfile.Item.ENVELOPE));
assertEquals(2, fetchProfileCaptor.getAllValues().get(0).size());
@ -270,7 +271,7 @@ public class ImapSyncTest extends RobolectricTest {
imapSync.sync(account, FOLDER_NAME, listener, remoteFolder);
verify(remoteFolder, atLeast(2)).fetch(any(List.class), fetchProfileCaptor.capture(),
any(MessageRetrievalListener.class));
nullable(MessageRetrievalListener.class));
assertEquals(1, fetchProfileCaptor.getAllValues().get(1).size());
assertTrue(fetchProfileCaptor.getAllValues().get(1).contains(FetchProfile.Item.BODY));
}
@ -287,7 +288,7 @@ public class ImapSyncTest extends RobolectricTest {
//TODO: Don't bother fetching messages of a size we don't have
verify(remoteFolder, atLeast(4)).fetch(any(List.class), fetchProfileCaptor.capture(),
any(MessageRetrievalListener.class));
nullable(MessageRetrievalListener.class));
assertEquals(1, fetchProfileCaptor.getAllValues().get(2).size());
assertEquals(FetchProfile.Item.STRUCTURE, fetchProfileCaptor.getAllValues().get(2).get(0));
assertEquals(1, fetchProfileCaptor.getAllValues().get(3).size());
@ -309,19 +310,19 @@ public class ImapSyncTest extends RobolectricTest {
}
return null;
}
}).when(remoteFolder).fetch(any(List.class), any(FetchProfile.class), any(MessageRetrievalListener.class));
}).when(remoteFolder).fetch(any(List.class), any(FetchProfile.class), nullable(MessageRetrievalListener.class));
}
private Message buildSmallNewMessage() {
Message message = mock(Message.class);
when(message.olderThan(any(Date.class))).thenReturn(false);
when(message.olderThan(nullable(Date.class))).thenReturn(false);
when(message.getSize()).thenReturn((long) MAXIMUM_SMALL_MESSAGE_SIZE);
return message;
}
private Message buildLargeNewMessage() {
Message message = mock(Message.class);
when(message.olderThan(any(Date.class))).thenReturn(false);
when(message.olderThan(nullable(Date.class))).thenReturn(false);
when(message.getSize()).thenReturn((long) (MAXIMUM_SMALL_MESSAGE_SIZE + 1));
return message;
}
@ -337,8 +338,8 @@ public class ImapSyncTest extends RobolectricTest {
when(remoteMessage.getUid()).thenReturn(messageUid);
when(localMessage.getUid()).thenReturn(messageUid);
when(remoteFolder.getMessages(anyInt(), anyInt(), any(Date.class), any(MessageRetrievalListener.class)))
.thenReturn(Collections.singletonList(remoteMessage));
when(remoteFolder.getMessages(anyInt(), anyInt(), nullable(Date.class),
nullable(MessageRetrievalListener.class))).thenReturn(Collections.singletonList(remoteMessage));
return localMessage;
}
@ -346,16 +347,16 @@ public class ImapSyncTest extends RobolectricTest {
String messageUid = "UID";
Message remoteMessage = mock(Message.class);
when(remoteMessage.getUid()).thenReturn(messageUid);
when(remoteFolder.getMessages(anyInt(), anyInt(), any(Date.class), any(MessageRetrievalListener.class)))
.thenReturn(Collections.singletonList(remoteMessage));
when(remoteFolder.getMessages(anyInt(), anyInt(), nullable(Date.class),
nullable(MessageRetrievalListener.class))).thenReturn(Collections.singletonList(remoteMessage));
}
private void setUpMessagingController() throws MessagingException {
when(controller.getAccountStats(account)).thenReturn(accountStats);
when(controller.getListeners(any(MessagingListener.class))).thenAnswer(new Answer<Set<MessagingListener>>() {
when(controller.getListeners(nullable(MessagingListener.class))).thenAnswer(new Answer<Set<MessagingListener>>() {
@Override
public Set<MessagingListener> answer(InvocationOnMock invocation) throws Throwable {
MessagingListener listener = invocation.getArgumentAt(0, MessagingListener.class);
MessagingListener listener = invocation.getArgument(0);
Set<MessagingListener> set = new HashSet<>(1);
set.add(listener);
return set;

View File

@ -53,6 +53,7 @@ import org.robolectric.RuntimeEnvironment;
import static com.fsck.k9.autocrypt.AutocryptOperationsHelper.assertMessageHasAutocryptHeader;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.nullable;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Matchers.eq;
@ -164,7 +165,7 @@ public class PgpMessageBuilderTest extends K9RobolectricTest {
Intent returnIntent = new Intent();
returnIntent.putExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_SUCCESS);
when(openPgpApi.executeApi(any(Intent.class), any(OpenPgpDataSource.class), any(OutputStream.class)))
when(openPgpApi.executeApi(any(Intent.class), any(OpenPgpDataSource.class), nullable(OutputStream.class)))
.thenReturn(returnIntent);
Callback mockCallback = mock(Callback.class);
@ -184,8 +185,8 @@ public class PgpMessageBuilderTest extends K9RobolectricTest {
Intent returnIntent = new Intent();
returnIntent.putExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_SUCCESS);
returnIntent.putExtra(OpenPgpApi.RESULT_DETACHED_SIGNATURE, new byte[] { 1, 2, 3 });
when(openPgpApi.executeApi(capturedApiIntent.capture(), any(OpenPgpDataSource.class), any(OutputStream.class)))
.thenReturn(returnIntent);
when(openPgpApi.executeApi(capturedApiIntent.capture(), any(OpenPgpDataSource.class),
nullable(OutputStream.class))).thenReturn(returnIntent);
Callback mockCallback = mock(Callback.class);
pgpMessageBuilder.buildAsync(mockCallback);
@ -236,7 +237,7 @@ public class PgpMessageBuilderTest extends K9RobolectricTest {
when(returnIntent.getParcelableExtra(eq(OpenPgpApi.RESULT_INTENT)))
.thenReturn(mockPendingIntent);
when(openPgpApi.executeApi(any(Intent.class), any(OpenPgpDataSource.class), any(OutputStream.class)))
when(openPgpApi.executeApi(any(Intent.class), any(OpenPgpDataSource.class), nullable(OutputStream.class)))
.thenReturn(returnIntent);
Callback mockCallback = mock(Callback.class);
@ -264,7 +265,7 @@ public class PgpMessageBuilderTest extends K9RobolectricTest {
when(returnIntent.getParcelableExtra(eq(OpenPgpApi.RESULT_INTENT)))
.thenReturn(mockPendingIntent);
when(openPgpApi.executeApi(any(Intent.class), any(OpenPgpDataSource.class), any(OutputStream.class)))
when(openPgpApi.executeApi(any(Intent.class), any(OpenPgpDataSource.class), nullable(OutputStream.class)))
.thenReturn(returnIntent);
Callback mockCallback = mock(Callback.class);
@ -285,12 +286,13 @@ public class PgpMessageBuilderTest extends K9RobolectricTest {
returnIntent.putExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_SUCCESS);
Intent mockReturnIntent = mock(Intent.class);
when(openPgpApi.executeApi(same(mockReturnIntent), any(OpenPgpDataSource.class), any(OutputStream.class)))
.thenReturn(returnIntent);
when(openPgpApi.executeApi(same(mockReturnIntent), any(OpenPgpDataSource.class),
nullable(OutputStream.class))).thenReturn(returnIntent);
Callback mockCallback = mock(Callback.class);
pgpMessageBuilder.onActivityResult(returnedRequestCode, Activity.RESULT_OK, mockReturnIntent, mockCallback);
verify(openPgpApi).executeApi(same(mockReturnIntent), any(OpenPgpDataSource.class), any(OutputStream.class));
verify(openPgpApi).executeApi(same(mockReturnIntent), any(OpenPgpDataSource.class),
nullable(OutputStream.class));
verify(returnIntent).getIntExtra(eq(OpenPgpApi.RESULT_CODE), anyInt());
}
}
@ -304,7 +306,7 @@ public class PgpMessageBuilderTest extends K9RobolectricTest {
Intent returnIntent = spy(new Intent());
returnIntent.putExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_SUCCESS);
when(openPgpApi.executeApi(any(Intent.class), any(OpenPgpDataSource.class), any(OutputStream.class)))
when(openPgpApi.executeApi(any(Intent.class), any(OpenPgpDataSource.class), nullable(OutputStream.class)))
.thenReturn(returnIntent);
Callback mockCallback = mock(Callback.class);
@ -326,7 +328,8 @@ public class PgpMessageBuilderTest extends K9RobolectricTest {
Intent returnIntent = new Intent();
returnIntent.putExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_SUCCESS);
when(openPgpApi.executeApi(any(Intent.class), any(OpenPgpDataSource.class), any(OutputStream.class))).thenReturn(returnIntent);
when(openPgpApi.executeApi(any(Intent.class), any(OpenPgpDataSource.class), nullable(OutputStream.class)))
.thenReturn(returnIntent);
pgpMessageBuilder.buildAsync(mock(Callback.class));
verify(autocryptOpenPgpApiInteractor).getKeyMaterialForUserId(same(openPgpApi), eq("alice@example.org"));
@ -347,7 +350,8 @@ public class PgpMessageBuilderTest extends K9RobolectricTest {
Intent returnIntent = new Intent();
returnIntent.putExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_SUCCESS);
when(openPgpApi.executeApi(any(Intent.class), any(OpenPgpDataSource.class), any(OutputStream.class))).thenReturn(returnIntent);
when(openPgpApi.executeApi(any(Intent.class), any(OpenPgpDataSource.class), nullable(OutputStream.class)))
.thenReturn(returnIntent);
pgpMessageBuilder.buildAsync(mock(Callback.class));
verify(autocryptOpenPgpApiInteractor).getKeyMaterialForUserId(same(openPgpApi), eq("alice@example.org"));
@ -367,7 +371,8 @@ public class PgpMessageBuilderTest extends K9RobolectricTest {
Intent returnIntent = new Intent();
returnIntent.putExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_SUCCESS);
when(openPgpApi.executeApi(any(Intent.class), any(OpenPgpDataSource.class), any(OutputStream.class))).thenReturn(returnIntent);
when(openPgpApi.executeApi(any(Intent.class), any(OpenPgpDataSource.class), nullable(OutputStream.class)))
.thenReturn(returnIntent);
pgpMessageBuilder.buildAsync(mock(Callback.class));
verify(autocryptOpenPgpApiInteractor).getKeyMaterialForKeyId(any(OpenPgpApi.class), any(Long.class), any(String.class));
@ -387,8 +392,8 @@ public class PgpMessageBuilderTest extends K9RobolectricTest {
Intent returnIntent = new Intent();
returnIntent.putExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_SUCCESS);
when(openPgpApi.executeApi(capturedApiIntent.capture(),
any(OpenPgpDataSource.class), any(OutputStream.class))).thenReturn(returnIntent);
when(openPgpApi.executeApi(capturedApiIntent.capture(), any(OpenPgpDataSource.class),
nullable(OutputStream.class))).thenReturn(returnIntent);
Callback mockCallback = mock(Callback.class);
pgpMessageBuilder.buildAsync(mockCallback);
@ -441,8 +446,8 @@ public class PgpMessageBuilderTest extends K9RobolectricTest {
Intent returnIntent = new Intent();
returnIntent.putExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_SUCCESS);
when(openPgpApi.executeApi(capturedApiIntent.capture(), any(OpenPgpDataSource.class), any(OutputStream.class)))
.thenReturn(returnIntent);
when(openPgpApi.executeApi(capturedApiIntent.capture(), any(OpenPgpDataSource.class),
nullable(OutputStream.class))).thenReturn(returnIntent);
Callback mockCallback = mock(Callback.class);
pgpMessageBuilder.buildAsync(mockCallback);
@ -480,8 +485,8 @@ public class PgpMessageBuilderTest extends K9RobolectricTest {
Intent returnIntent = new Intent();
returnIntent.putExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_SUCCESS);
when(openPgpApi.executeApi(capturedApiIntent.capture(), any(OpenPgpDataSource.class), any(OutputStream.class)))
.thenReturn(returnIntent);
when(openPgpApi.executeApi(capturedApiIntent.capture(), any(OpenPgpDataSource.class),
nullable(OutputStream.class))).thenReturn(returnIntent);
Callback mockCallback = mock(Callback.class);
pgpMessageBuilder.buildAsync(mockCallback);
@ -550,7 +555,7 @@ public class PgpMessageBuilderTest extends K9RobolectricTest {
new OpenPgpError(OpenPgpError.OPPORTUNISTIC_MISSING_KEYS, "Missing keys"));
when(openPgpApi.executeApi(any(Intent.class), any(OpenPgpDataSource.class), any(OutputStream.class)))
when(openPgpApi.executeApi(any(Intent.class), any(OpenPgpDataSource.class), nullable(OutputStream.class)))
.thenReturn(returnIntent);
Callback mockCallback = mock(Callback.class);
@ -577,7 +582,7 @@ public class PgpMessageBuilderTest extends K9RobolectricTest {
// no OpenPgpApi.EXTRA_DETACHED_SIGNATURE!
when(openPgpApi.executeApi(any(Intent.class), any(OpenPgpDataSource.class), any(OutputStream.class)))
when(openPgpApi.executeApi(any(Intent.class), any(OpenPgpDataSource.class), nullable(OutputStream.class)))
.thenReturn(returnIntentSigned);
Callback mockCallback = mock(Callback.class);
pgpMessageBuilder.buildAsync(mockCallback);

View File

@ -16,8 +16,6 @@ import org.junit.Before;
import org.junit.Test;
import org.robolectric.RuntimeEnvironment;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@ -30,6 +28,7 @@ public class AuthenticationErrorNotificationsTest extends RobolectricTest {
private static final String ACCOUNT_NAME = "TestAccount";
private Notification notification;
private NotificationManagerCompat notificationManager;
private NotificationCompat.Builder builder;
private NotificationController controller;
@ -40,8 +39,9 @@ public class AuthenticationErrorNotificationsTest extends RobolectricTest {
@Before
public void setUp() throws Exception {
notification = createFakeNotification();
notificationManager = createFakeNotificationManager();
builder = createFakeNotificationBuilder();
builder = createFakeNotificationBuilder(notification);
controller = createFakeNotificationController(notificationManager, builder);
account = createFakeAccount();
contentIntent = createFakeContentIntent();
@ -55,7 +55,7 @@ public class AuthenticationErrorNotificationsTest extends RobolectricTest {
authenticationErrorNotifications.showAuthenticationErrorNotification(account, INCOMING);
verify(notificationManager).notify(eq(notificationId), any(Notification.class));
verify(notificationManager).notify(notificationId, notification);
assertAuthenticationErrorNotificationContents();
}
@ -74,7 +74,7 @@ public class AuthenticationErrorNotificationsTest extends RobolectricTest {
authenticationErrorNotifications.showAuthenticationErrorNotification(account, OUTGOING);
verify(notificationManager).notify(eq(notificationId), any(Notification.class));
verify(notificationManager).notify(notificationId, notification);
assertAuthenticationErrorNotificationContents();
}
@ -96,12 +96,18 @@ public class AuthenticationErrorNotificationsTest extends RobolectricTest {
verify(builder).setVisibility(NotificationCompat.VISIBILITY_PUBLIC);
}
private Notification createFakeNotification() {
return mock(Notification.class);
}
private NotificationManagerCompat createFakeNotificationManager() {
return mock(NotificationManagerCompat.class);
}
private Builder createFakeNotificationBuilder() {
return MockHelper.mockBuilder(NotificationCompat.Builder.class);
private Builder createFakeNotificationBuilder(Notification notification) {
Builder builder = MockHelper.mockBuilder(Builder.class);
when(builder.build()).thenReturn(notification);
return builder;
}
private NotificationController createFakeNotificationController(NotificationManagerCompat notificationManager,

View File

@ -16,8 +16,6 @@ import org.junit.Before;
import org.junit.Test;
import org.robolectric.RuntimeEnvironment;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@ -30,6 +28,7 @@ public class CertificateErrorNotificationsTest extends RobolectricTest {
private static final String ACCOUNT_NAME = "TestAccount";
private Notification notification;
private NotificationManagerCompat notificationManager;
private NotificationCompat.Builder builder;
private NotificationController controller;
@ -40,8 +39,9 @@ public class CertificateErrorNotificationsTest extends RobolectricTest {
@Before
public void setUp() throws Exception {
notification = createFakeNotification();
notificationManager = createFakeNotificationManager();
builder = createFakeNotificationBuilder();
builder = createFakeNotificationBuilder(notification);
controller = createFakeNotificationController(notificationManager, builder);
account = createFakeAccount();
contentIntent = createFakeContentIntent();
@ -55,7 +55,7 @@ public class CertificateErrorNotificationsTest extends RobolectricTest {
certificateErrorNotifications.showCertificateErrorNotification(account, INCOMING);
verify(notificationManager).notify(eq(notificationId), any(Notification.class));
verify(notificationManager).notify(notificationId, notification);
assertCertificateErrorNotificationContents();
}
@ -74,7 +74,7 @@ public class CertificateErrorNotificationsTest extends RobolectricTest {
certificateErrorNotifications.showCertificateErrorNotification(account, OUTGOING);
verify(notificationManager).notify(eq(notificationId), any(Notification.class));
verify(notificationManager).notify(notificationId, notification);
assertCertificateErrorNotificationContents();
}
@ -96,12 +96,18 @@ public class CertificateErrorNotificationsTest extends RobolectricTest {
verify(builder).setVisibility(NotificationCompat.VISIBILITY_PUBLIC);
}
private Notification createFakeNotification() {
return mock(Notification.class);
}
private NotificationManagerCompat createFakeNotificationManager() {
return mock(NotificationManagerCompat.class);
}
private Builder createFakeNotificationBuilder() {
return MockHelper.mockBuilder(NotificationCompat.Builder.class);
private Builder createFakeNotificationBuilder(Notification notification) {
Builder builder = MockHelper.mockBuilder(Builder.class);
when(builder.build()).thenReturn(notification);
return builder;
}
private NotificationController createFakeNotificationController(NotificationManagerCompat notificationManager,

View File

@ -17,7 +17,6 @@ import org.robolectric.RuntimeEnvironment;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@ -28,6 +27,7 @@ public class SendFailedNotificationsTest extends RobolectricTest {
private static final String ACCOUNT_NAME = "TestAccount";
private Notification notification;
private NotificationManagerCompat notificationManager;
private Builder builder;
private Account account;
@ -38,8 +38,9 @@ public class SendFailedNotificationsTest extends RobolectricTest {
@Before
public void setUp() throws Exception {
notification = createFakeNotification();
notificationManager = createFakeNotificationManager();
builder = createFakeNotificationBuilder();
builder = createFakeNotificationBuilder(notification);
NotificationController controller = createFakeNotificationController(notificationManager, builder);
account = createFakeAccount();
contentIntent = createFakeContentIntent();
@ -55,7 +56,7 @@ public class SendFailedNotificationsTest extends RobolectricTest {
sendFailedNotifications.showSendFailedNotification(account, exception);
verify(notificationManager).notify(eq(notificationId), any(Notification.class));
verify(notificationManager).notify(notificationId, notification);
verify(builder).setSmallIcon(R.drawable.notification_icon_new_mail);
verify(builder).setTicker("Failed to send some messages");
verify(builder).setContentTitle("Failed to send some messages");
@ -71,12 +72,18 @@ public class SendFailedNotificationsTest extends RobolectricTest {
verify(notificationManager).cancel(notificationId);
}
private Notification createFakeNotification() {
return mock(Notification.class);
}
private NotificationManagerCompat createFakeNotificationManager() {
return mock(NotificationManagerCompat.class);
}
private Builder createFakeNotificationBuilder() {
return MockHelper.mockBuilder(Builder.class);
private Builder createFakeNotificationBuilder(Notification notification) {
Builder builder = MockHelper.mockBuilder(Builder.class);
when(builder.build()).thenReturn(notification);
return builder;
}
private NotificationController createFakeNotificationController(NotificationManagerCompat notificationManager,

View File

@ -16,10 +16,10 @@ import org.junit.Before;
import org.junit.Test;
import org.robolectric.RuntimeEnvironment;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@ -32,6 +32,7 @@ public class SyncNotificationsTest extends RobolectricTest {
private static final String FOLDER_NAME = "Inbox";
private Notification notification;
private NotificationManagerCompat notificationManager;
private Builder builder;
private Account account;
@ -41,8 +42,9 @@ public class SyncNotificationsTest extends RobolectricTest {
@Before
public void setUp() throws Exception {
notification = createFakeNotification();
notificationManager = createFakeNotificationManager();
builder = createFakeNotificationBuilder();
builder = createFakeNotificationBuilder(notification);
NotificationController controller = createFakeNotificationController(notificationManager, builder);
account = createFakeAccount();
contentIntent = createFakeContentIntent();
@ -57,7 +59,7 @@ public class SyncNotificationsTest extends RobolectricTest {
syncNotifications.showSendingNotification(account);
verify(notificationManager).notify(eq(notificationId), any(Notification.class));
verify(notificationManager).notify(notificationId, notification);
verify(builder).setSmallIcon(R.drawable.ic_notify_check_mail);
verify(builder).setTicker("Sending mail: " + ACCOUNT_NAME);
verify(builder).setContentTitle("Sending mail");
@ -82,7 +84,7 @@ public class SyncNotificationsTest extends RobolectricTest {
syncNotifications.showFetchingMailNotification(account, folder);
verify(notificationManager).notify(eq(notificationId), any(Notification.class));
verify(notificationManager).notify(notificationId, notification);
verify(builder).setSmallIcon(R.drawable.ic_notify_check_mail);
verify(builder).setTicker("Checking mail: " + ACCOUNT_NAME + ":" + FOLDER_NAME);
verify(builder).setContentTitle("Checking mail");
@ -100,12 +102,19 @@ public class SyncNotificationsTest extends RobolectricTest {
verify(notificationManager).cancel(notificationId);
}
private Notification createFakeNotification() {
return mock(Notification.class);
}
private NotificationManagerCompat createFakeNotificationManager() {
return mock(NotificationManagerCompat.class);
}
private Builder createFakeNotificationBuilder() {
return MockHelper.mockBuilder(Builder.class);
private Builder createFakeNotificationBuilder(Notification notification) {
Builder builder = MockHelper.mockBuilder(Builder.class);
when(builder.build()).thenReturn(notification);
return builder;
}
private NotificationController createFakeNotificationController(NotificationManagerCompat notificationManager,
@ -122,6 +131,7 @@ public class SyncNotificationsTest extends RobolectricTest {
Account account = mock(Account.class);
when(account.getAccountNumber()).thenReturn(ACCOUNT_NUMBER);
when(account.getDescription()).thenReturn(ACCOUNT_NAME);
when(account.getOutboxFolder()).thenReturn("OUTBOX");
return account;
}
@ -132,7 +142,7 @@ public class SyncNotificationsTest extends RobolectricTest {
private NotificationActionCreator createActionBuilder(PendingIntent contentIntent) {
NotificationActionCreator actionBuilder = mock(NotificationActionCreator.class);
when(actionBuilder.createViewFolderPendingIntent(any(Account.class), anyString(), anyInt()))
when(actionBuilder.createViewFolderPendingIntent(eq(account), anyString(), anyInt()))
.thenReturn(contentIntent);
return actionBuilder;
}

View File

@ -306,7 +306,7 @@ public class WearNotificationsTest extends RobolectricTest {
}
static class ActionMatcher extends ArgumentMatcher<WearableExtender> {
static class ActionMatcher implements ArgumentMatcher<WearableExtender> {
private int icon;
private String title;
private PendingIntent pendingIntent;
@ -318,13 +318,8 @@ public class WearNotificationsTest extends RobolectricTest {
}
@Override
public boolean matches(Object argument) {
if (!(argument instanceof WearableExtender)) {
return false;
}
WearableExtender wearableExtender = (WearableExtender) argument;
for (Action action : wearableExtender.getActions()) {
public boolean matches(WearableExtender argument) {
for (Action action : argument.getActions()) {
if (action.icon == icon && action.title.equals(title) && action.actionIntent == pendingIntent) {
return true;
}
@ -334,7 +329,7 @@ public class WearNotificationsTest extends RobolectricTest {
}
}
static class NumberOfActionsMatcher extends ArgumentMatcher<WearableExtender> {
static class NumberOfActionsMatcher implements ArgumentMatcher<WearableExtender> {
private final int expectedNumberOfActions;
public NumberOfActionsMatcher(int expectedNumberOfActions) {
@ -342,13 +337,8 @@ public class WearNotificationsTest extends RobolectricTest {
}
@Override
public boolean matches(Object argument) {
if (!(argument instanceof WearableExtender)) {
return false;
}
WearableExtender wearableExtender = (WearableExtender) argument;
return wearableExtender.getActions().size() == expectedNumberOfActions;
public boolean matches(WearableExtender argument) {
return argument.getActions().size() == expectedNumberOfActions;
}
}

View File

@ -38,6 +38,7 @@ import static com.fsck.k9.message.TestMessageConstructionUtils.multipart;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertSame;
import static junit.framework.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.nullable;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.same;
import static org.mockito.Mockito.mock;
@ -63,7 +64,8 @@ public class MessageCryptoHelperTest extends RobolectricTest {
autocryptOperations = mock(AutocryptOperations.class);
OpenPgpApiFactory openPgpApiFactory = mock(OpenPgpApiFactory.class);
when(openPgpApiFactory.createOpenPgpApi(any(Context.class), any(IOpenPgpService2.class))).thenReturn(openPgpApi);
when(openPgpApiFactory.createOpenPgpApi(any(Context.class), nullable(IOpenPgpService2.class)))
.thenReturn(openPgpApi);
messageCryptoHelper = new MessageCryptoHelper(RuntimeEnvironment.application, openPgpApiFactory,
autocryptOperations, "org.example.dummy");