src_fm_fc_ms_ff stringlengths 43 86.8k | target stringlengths 20 276k |
|---|---|
ContactPictureLoader { @VisibleForTesting protected static String calcUnknownContactLetter(Address address) { String letter = null; String personal = address.getPersonal(); String str = (personal != null) ? personal : address.getAddress(); Matcher m = EXTRACT_LETTER_PATTERN.matcher(str); if (m.find()) { letter = m.grou... | @Test public void calcUnknownContactLetter_withNoNameUsesAddress() { Address address = new Address("<c@d.com>"); String result = ContactPictureLoader.calcUnknownContactLetter(address); assertEquals("C", result); }
@Test public void calcUnknownContactLetter_withAsciiName() { Address address = new Address("abcd <a@b.com>... |
RecipientPresenter implements PermissionPingCallback { public void initFromReplyToMessage(Message message, ReplyMode replyMode) { ReplyToAddresses replyToAddresses; switch (replyMode) { case ALL: replyToAddresses = replyToParser.getRecipientsToReplyAllTo(message, account); break; case LIST: replyToAddresses = replyToPa... | @Test public void testInitFromReplyToMessage() throws Exception { Message message = mock(Message.class); when(replyToParser.getRecipientsToReplyTo(message, account)).thenReturn(TO_ADDRESSES); recipientPresenter.initFromReplyToMessage(message, ReplyMode.NORMAL); runBackgroundTask(); verify(recipientMvpView).addRecipient... |
RecipientPresenter implements PermissionPingCallback { @Nullable public ComposeCryptoStatus getCurrentCachedCryptoStatus() { return cachedCryptoStatus; } RecipientPresenter(Context context, LoaderManager loaderManager,
RecipientMvpView recipientMvpView, Account account, ComposePgpInlineDecider composePgpInl... | @Test public void getCurrentCryptoStatus_withoutCryptoProvider() throws Exception { ComposeCryptoStatus status = recipientPresenter.getCurrentCachedCryptoStatus(); assertEquals(CryptoStatusDisplayType.UNCONFIGURED, status.getCryptoStatusDisplayType()); assertEquals(CryptoSpecialModeDisplayType.NONE, status.getCryptoSpe... |
RecipientPresenter implements PermissionPingCallback { void onToTokenAdded() { asyncUpdateCryptoStatus(); listener.onRecipientsChanged(); } RecipientPresenter(Context context, LoaderManager loaderManager,
RecipientMvpView recipientMvpView, Account account, ComposePgpInlineDecider composePgpInlineDecider,
... | @Test public void onToTokenAdded_notifiesListenerOfRecipientChange() { recipientPresenter.onToTokenAdded(); verify(listener).onRecipientsChanged(); } |
RecipientPresenter implements PermissionPingCallback { void onToTokenChanged() { asyncUpdateCryptoStatus(); listener.onRecipientsChanged(); } RecipientPresenter(Context context, LoaderManager loaderManager,
RecipientMvpView recipientMvpView, Account account, ComposePgpInlineDecider composePgpInlineDecider,
... | @Test public void onToTokenChanged_notifiesListenerOfRecipientChange() { recipientPresenter.onToTokenChanged(); verify(listener).onRecipientsChanged(); } |
RecipientPresenter implements PermissionPingCallback { void onToTokenRemoved() { asyncUpdateCryptoStatus(); listener.onRecipientsChanged(); } RecipientPresenter(Context context, LoaderManager loaderManager,
RecipientMvpView recipientMvpView, Account account, ComposePgpInlineDecider composePgpInlineDecider,
... | @Test public void onToTokenRemoved_notifiesListenerOfRecipientChange() { recipientPresenter.onToTokenRemoved(); verify(listener).onRecipientsChanged(); } |
RecipientPresenter implements PermissionPingCallback { void onCcTokenAdded() { asyncUpdateCryptoStatus(); listener.onRecipientsChanged(); } RecipientPresenter(Context context, LoaderManager loaderManager,
RecipientMvpView recipientMvpView, Account account, ComposePgpInlineDecider composePgpInlineDecider,
... | @Test public void onCcTokenAdded_notifiesListenerOfRecipientChange() { recipientPresenter.onCcTokenAdded(); verify(listener).onRecipientsChanged(); } |
RecipientPresenter implements PermissionPingCallback { void onCcTokenChanged() { asyncUpdateCryptoStatus(); listener.onRecipientsChanged(); } RecipientPresenter(Context context, LoaderManager loaderManager,
RecipientMvpView recipientMvpView, Account account, ComposePgpInlineDecider composePgpInlineDecider,
... | @Test public void onCcTokenChanged_notifiesListenerOfRecipientChange() { recipientPresenter.onCcTokenChanged(); verify(listener).onRecipientsChanged(); } |
RecipientPresenter implements PermissionPingCallback { void onCcTokenRemoved() { asyncUpdateCryptoStatus(); listener.onRecipientsChanged(); } RecipientPresenter(Context context, LoaderManager loaderManager,
RecipientMvpView recipientMvpView, Account account, ComposePgpInlineDecider composePgpInlineDecider,
... | @Test public void onCcTokenRemoved_notifiesListenerOfRecipientChange() { recipientPresenter.onCcTokenRemoved(); verify(listener).onRecipientsChanged(); } |
RecipientPresenter implements PermissionPingCallback { void onBccTokenAdded() { asyncUpdateCryptoStatus(); listener.onRecipientsChanged(); } RecipientPresenter(Context context, LoaderManager loaderManager,
RecipientMvpView recipientMvpView, Account account, ComposePgpInlineDecider composePgpInlineDecider,
... | @Test public void onBccTokenAdded_notifiesListenerOfRecipientChange() { recipientPresenter.onBccTokenAdded(); verify(listener).onRecipientsChanged(); } |
RecipientPresenter implements PermissionPingCallback { void onBccTokenChanged() { asyncUpdateCryptoStatus(); listener.onRecipientsChanged(); } RecipientPresenter(Context context, LoaderManager loaderManager,
RecipientMvpView recipientMvpView, Account account, ComposePgpInlineDecider composePgpInlineDecider,... | @Test public void onBccTokenChanged_notifiesListenerOfRecipientChange() { recipientPresenter.onBccTokenChanged(); verify(listener).onRecipientsChanged(); } |
RecipientPresenter implements PermissionPingCallback { void onBccTokenRemoved() { asyncUpdateCryptoStatus(); listener.onRecipientsChanged(); } RecipientPresenter(Context context, LoaderManager loaderManager,
RecipientMvpView recipientMvpView, Account account, ComposePgpInlineDecider composePgpInlineDecider,... | @Test public void onBccTokenRemoved_notifiesListenerOfRecipientChange() { recipientPresenter.onBccTokenRemoved(); verify(listener).onRecipientsChanged(); } |
FolderInfoHolder implements Comparable<FolderInfoHolder> { public static String getDisplayName(Context context, Account account, String id, String name) { final String displayName; if (id.equals(account.getSpamFolderId())) { displayName = String.format( context.getString(R.string.special_mailbox_name_spam_fmt), name); ... | @Test public void getDisplayName_forUnknownFolder_returnsName() { String result = FolderInfoHolder.getDisplayName(context, mockAccount, "FolderID", "Folder"); assertEquals("Folder", result); }
@Test public void getDisplayName_forSpamFolder_returnsNameSpam() { when(mockAccount.getSpamFolderId()).thenReturn("FolderID"); ... |
MessageReference { public String toIdentityString() { StringBuilder refString = new StringBuilder(); refString.append(IDENTITY_VERSION_1); refString.append(IDENTITY_SEPARATOR); refString.append(Base64.encode(accountUuid)); refString.append(IDENTITY_SEPARATOR); refString.append(Base64.encode(folderId)); refString.append... | @Test public void checkIdentityStringFromMessageReferenceWithoutFlag() { MessageReference messageReference = createMessageReference("o hai!", "folder", "10101010"); assertEquals("!:byBoYWkh:Zm9sZGVy:MTAxMDEwMTA=", messageReference.toIdentityString()); }
@Test public void checkIdentityStringFromMessageReferenceWithFlag(... |
MessageReference { @Nullable public static MessageReference parse(String identity) { if (identity == null || identity.length() < 1 || identity.charAt(0) != IDENTITY_VERSION_1) { return null; } StringTokenizer tokens = new StringTokenizer(identity.substring(2), IDENTITY_SEPARATOR, false); if (tokens.countTokens() < 3) {... | @Test public void parseIdentityStringContainingBadVersionNumber() { MessageReference messageReference = MessageReference.parse("@:byBoYWkh:Zm9sZGVy:MTAxMDEwMTA=:ANSWERED"); assertNull(messageReference); }
@Test public void parseNullIdentityString() { MessageReference messageReference = MessageReference.parse(null); ass... |
MessageReference { @Override public boolean equals(Object o) { if (!(o instanceof MessageReference)) { return false; } MessageReference other = (MessageReference) o; return equals(other.accountUuid, other.folderId, other.uid); } MessageReference(String accountUuid, String folderId, String uid, Flag flag); @Nullable sta... | @Test public void equalsWithAnObjectShouldReturnFalse() { MessageReference messageReference = new MessageReference("a", "b", "c", null); Object object = new Object(); assertFalse(messageReference.equals(object)); }
@SuppressWarnings("ObjectEqualsNull") @Test public void equalsWithNullShouldReturnFalse() { MessageRefere... |
BaseNotifications { protected NotificationCompat.Builder createAndInitializeNotificationBuilder(Account account) { return controller.createNotificationBuilder() .setSmallIcon(getNewMailNotificationIcon()) .setColor(account.getChipColor()) .setWhen(System.currentTimeMillis()) .setAutoCancel(true) .setCategory(Notificati... | @Test public void testCreateAndInitializeNotificationBuilder() throws Exception { Account account = createFakeAccount(); Builder builder = notifications.createAndInitializeNotificationBuilder(account); verify(builder).setSmallIcon(R.drawable.notification_icon_new_mail); verify(builder).setColor(ACCOUNT_COLOR); verify(b... |
BaseNotifications { protected boolean isDeleteActionEnabled() { NotificationQuickDelete deleteOption = QMail.getNotificationQuickDeleteBehaviour(); return deleteOption == NotificationQuickDelete.ALWAYS || deleteOption == NotificationQuickDelete.FOR_SINGLE_MSG; } protected BaseNotifications(NotificationController contr... | @Test public void testIsDeleteActionEnabled_NotificationQuickDelete_ALWAYS() throws Exception { QMail.setNotificationQuickDeleteBehaviour(NotificationQuickDelete.ALWAYS); boolean result = notifications.isDeleteActionEnabled(); assertTrue(result); }
@Test public void testIsDeleteActionEnabled_NotificationQuickDelete_FOR... |
BaseNotifications { protected NotificationCompat.Builder createBigTextStyleNotification(Account account, NotificationHolder holder, int notificationId) { String accountName = controller.getAccountName(account); NotificationContent content = holder.content; String groupKey = NotificationGroupKeys.getGroupKey(account); N... | @Test public void testCreateBigTextStyleNotification() throws Exception { Account account = createFakeAccount(); int notificationId = 23; NotificationHolder holder = createNotificationHolder(notificationId); Builder builder = notifications.createBigTextStyleNotification(account, holder, notificationId); verify(builder)... |
WearNotifications extends BaseNotifications { public Notification buildStackedNotification(Account account, NotificationHolder holder) { int notificationId = holder.notificationId; NotificationContent content = holder.content; NotificationCompat.Builder builder = createBigTextStyleNotification(account, holder, notifica... | @Test public void testBuildStackedNotification() throws Exception { disableOptionalActions(); int notificationIndex = 0; int notificationId = NotificationIds.getNewMailStackedNotificationId(account, notificationIndex); MessageReference messageReference = createMessageReference(1); NotificationContent content = createNo... |
WearNotifications extends BaseNotifications { public void addSummaryActions(Builder builder, NotificationData notificationData) { NotificationCompat.WearableExtender wearableExtender = new NotificationCompat.WearableExtender(); addMarkAllAsReadAction(wearableExtender, notificationData); if (isDeleteActionAvailableForWe... | @Test public void testAddSummaryActions() throws Exception { disableOptionalSummaryActions(); int notificationId = NotificationIds.getNewMailSummaryNotificationId(account); ArrayList<MessageReference> messageReferences = createMessageReferenceList(); NotificationData notificationData = createNotificationData(messageRef... |
AuthenticationErrorNotifications { public void showAuthenticationErrorNotification(Account account, boolean incoming) { int notificationId = NotificationIds.getAuthenticationErrorNotificationId(account, incoming); Context context = controller.getContext(); PendingIntent editServerSettingsPendingIntent = createContentIn... | @Test public void showAuthenticationErrorNotification_withIncomingServer_shouldCreateNotification() throws Exception { int notificationId = NotificationIds.getAuthenticationErrorNotificationId(account, INCOMING); authenticationErrorNotifications.showAuthenticationErrorNotification(account, INCOMING); verify(notificatio... |
AuthenticationErrorNotifications { public void clearAuthenticationErrorNotification(Account account, boolean incoming) { int notificationId = NotificationIds.getAuthenticationErrorNotificationId(account, incoming); getNotificationManager().cancel(notificationId); } AuthenticationErrorNotifications(NotificationControlle... | @Test public void clearAuthenticationErrorNotification_withIncomingServer_shouldCancelNotification() throws Exception { int notificationId = NotificationIds.getAuthenticationErrorNotificationId(account, INCOMING); authenticationErrorNotifications.clearAuthenticationErrorNotification(account, INCOMING); verify(notificat... |
NotificationContentCreator { public NotificationContent createFromMessage(Account account, LocalMessage message) { MessageReference messageReference = message.makeMessageReference(); String sender = getMessageSender(account, message); String displaySender = getMessageSenderForDisplay(sender); String subject = getMessag... | @Test public void createFromMessage_withRegularMessage() throws Exception { NotificationContent content = contentCreator.createFromMessage(account, message); assertEquals(messageReference, content.messageReference); assertEquals(SENDER_NAME, content.sender); assertEquals(SUBJECT, content.subject); assertEquals(SUBJECT ... |
LockScreenNotification { public void configureLockScreenNotification(Builder builder, NotificationData notificationData) { if (!NotificationController.platformSupportsLockScreenNotifications()) { return; } switch (QMail.getLockScreenNotificationVisibility()) { case NOTHING: { builder.setVisibility(NotificationCompat.VI... | @Test public void configureLockScreenNotification_NOTHING() throws Exception { QMail.setLockScreenNotificationVisibility(LockScreenNotificationVisibility.NOTHING); lockScreenNotification.configureLockScreenNotification(builder, notificationData); verify(builder).setVisibility(NotificationCompat.VISIBILITY_SECRET); }
@T... |
LockScreenNotification { String createCommaSeparatedListOfSenders(List<NotificationContent> contents) { Set<CharSequence> senders = new LinkedHashSet<CharSequence>(MAX_NUMBER_OF_SENDERS_IN_LOCK_SCREEN_NOTIFICATION); for (NotificationContent content : contents) { senders.add(content.sender); if (senders.size() == MAX_NU... | @Test public void createCommaSeparatedListOfSenders_withMoreSendersThanShouldBeDisplayed() throws Exception { NotificationContent content1 = createNotificationContent("alice@example.com"); NotificationContent content2 = createNotificationContent("bob@example.com"); NotificationContent content3 = createNotificationConte... |
NotificationIds { public static int getNewMailSummaryNotificationId(Account account) { return getBaseNotificationId(account) + OFFSET_NEW_MAIL_SUMMARY; } static int getNewMailSummaryNotificationId(Account account); static int getNewMailStackedNotificationId(Account account, int index); static int getFetchingMailNotifi... | @Test public void getNewMailSummaryNotificationId_withDefaultAccount() throws Exception { Account account = createMockAccountWithAccountNumber(0); int notificationId = NotificationIds.getNewMailSummaryNotificationId(account); assertEquals(6, notificationId); }
@Test public void getNewMailSummaryNotificationId_withSecon... |
NotificationIds { public static int getNewMailStackedNotificationId(Account account, int index) { if (index < 0 || index >= NUMBER_OF_STACKED_NOTIFICATIONS) { throw new IndexOutOfBoundsException("Invalid value: " + index); } return getBaseNotificationId(account) + OFFSET_NEW_MAIL_STACKED + index; } static int getNewMa... | @Test public void getNewMailStackedNotificationId_withDefaultAccount() throws Exception { Account account = createMockAccountWithAccountNumber(0); int notificationIndex = 0; int notificationId = NotificationIds.getNewMailStackedNotificationId(account, notificationIndex); assertEquals(7, notificationId); }
@Test(expecte... |
MessageCryptoStructureDetector { public static List<Part> findMultipartSignedParts(Part startPart, MessageCryptoAnnotations messageCryptoAnnotations) { List<Part> signedParts = new ArrayList<>(); Stack<Part> partsToCheck = new Stack<>(); partsToCheck.push(startPart); while (!partsToCheck.isEmpty()) { Part part = partsT... | @Test public void findSigned__withSimpleMultipartSigned__shouldReturnRoot() throws Exception { Message message = messageFromBody( multipart("signed", "protocol=\"application/pgp-signature\"", bodypart("text/plain"), bodypart("application/pgp-signature") ) ); List<Part> signedParts = MessageCryptoStructureDetector .find... |
NotificationIds { public static int getFetchingMailNotificationId(Account account) { return getBaseNotificationId(account) + OFFSET_FETCHING_MAIL; } static int getNewMailSummaryNotificationId(Account account); static int getNewMailStackedNotificationId(Account account, int index); static int getFetchingMailNotificatio... | @Test public void getFetchingMailNotificationId_withDefaultAccount() throws Exception { Account account = createMockAccountWithAccountNumber(0); int notificationId = NotificationIds.getFetchingMailNotificationId(account); assertEquals(5, notificationId); }
@Test public void getFetchingMailNotificationId_withSecondAccou... |
NotificationIds { public static int getSendFailedNotificationId(Account account) { return getBaseNotificationId(account) + OFFSET_SEND_FAILED_NOTIFICATION; } static int getNewMailSummaryNotificationId(Account account); static int getNewMailStackedNotificationId(Account account, int index); static int getFetchingMailNo... | @Test public void getSendFailedNotificationId_withDefaultAccount() throws Exception { Account account = createMockAccountWithAccountNumber(0); int notificationId = NotificationIds.getSendFailedNotificationId(account); assertEquals(0, notificationId); }
@Test public void getSendFailedNotificationId_withSecondAccount() t... |
NotificationIds { public static int getCertificateErrorNotificationId(Account account, boolean incoming) { int offset = incoming ? OFFSET_CERTIFICATE_ERROR_INCOMING : OFFSET_CERTIFICATE_ERROR_OUTGOING; return getBaseNotificationId(account) + offset; } static int getNewMailSummaryNotificationId(Account account); static... | @Test public void getCertificateErrorNotificationId_forIncomingServerWithDefaultAccount() throws Exception { Account account = createMockAccountWithAccountNumber(0); int notificationId = NotificationIds.getCertificateErrorNotificationId(account, INCOMING); assertEquals(1, notificationId); }
@Test public void getCertifi... |
NotificationIds { public static int getAuthenticationErrorNotificationId(Account account, boolean incoming) { int offset = incoming ? OFFSET_AUTHENTICATION_ERROR_INCOMING : OFFSET_AUTHENTICATION_ERROR_OUTGOING; return getBaseNotificationId(account) + offset; } static int getNewMailSummaryNotificationId(Account account... | @Test public void getAuthenticationErrorNotificationId_forIncomingServerWithDefaultAccount() throws Exception { Account account = createMockAccountWithAccountNumber(0); int notificationId = NotificationIds.getAuthenticationErrorNotificationId(account, INCOMING); assertEquals(3, notificationId); }
@Test public void getA... |
DeviceNotifications extends BaseNotifications { public Notification buildSummaryNotification(Account account, NotificationData notificationData, boolean silent) { int unreadMessageCount = notificationData.getUnreadMessageCount(); NotificationCompat.Builder builder; if (isPrivacyModeActive() || !platformSupportsExtended... | @Test public void buildSummaryNotification_withPrivacyModeActive() throws Exception { QMail.setNotificationHideSubject(NotificationHideSubject.ALWAYS); Notification result = notifications.buildSummaryNotification(account, notificationData, false); verify(builder).setSmallIcon(R.drawable.notification_icon_new_mail); ver... |
SyncNotifications { public void showSendingNotification(Account account) { Context context = controller.getContext(); String accountName = controller.getAccountName(account); String title = context.getString(R.string.notification_bg_send_title); String tickerText = context.getString(R.string.notification_bg_send_ticker... | @Test public void testShowSendingNotification() throws Exception { int notificationId = NotificationIds.getFetchingMailNotificationId(account); syncNotifications.showSendingNotification(account); verify(notificationManager).notify(eq(notificationId), any(Notification.class)); verify(builder).setSmallIcon(R.drawable.ic_... |
SyncNotifications { public void clearSendingNotification(Account account) { int notificationId = NotificationIds.getFetchingMailNotificationId(account); getNotificationManager().cancel(notificationId); } SyncNotifications(NotificationController controller, NotificationActionCreator actionBuilder); void showSendingNotif... | @Test public void testClearSendingNotification() throws Exception { int notificationId = NotificationIds.getFetchingMailNotificationId(account); syncNotifications.clearSendingNotification(account); verify(notificationManager).cancel(notificationId); } |
SyncNotifications { public void showFetchingMailNotification(Account account, Folder folder) { String accountName = account.getDescription(); String folderName = folder.getId(); Context context = controller.getContext(); String tickerText = context.getString(R.string.notification_bg_sync_ticker, accountName, folderName... | @Test public void testGetFetchingMailNotificationId() throws Exception { Folder folder = createFakeFolder(); int notificationId = NotificationIds.getFetchingMailNotificationId(account); syncNotifications.showFetchingMailNotification(account, folder); verify(notificationManager).notify(eq(notificationId), any(Notificati... |
SyncNotifications { public void clearFetchingMailNotification(Account account) { int notificationId = NotificationIds.getFetchingMailNotificationId(account); getNotificationManager().cancel(notificationId); } SyncNotifications(NotificationController controller, NotificationActionCreator actionBuilder); void showSending... | @Test public void testClearSendFailedNotification() throws Exception { int notificationId = NotificationIds.getFetchingMailNotificationId(account); syncNotifications.clearFetchingMailNotification(account); verify(notificationManager).cancel(notificationId); } |
SendFailedNotifications { public void showSendFailedNotification(Account account, Exception exception) { Context context = controller.getContext(); String title = context.getString(R.string.send_failure_subject); String text = ExceptionHelper.getRootCauseMessage(exception); int notificationId = NotificationIds.getSendF... | @Test public void testShowSendFailedNotification() throws Exception { Exception exception = new Exception(); sendFailedNotifications.showSendFailedNotification(account, exception); verify(notificationManager).notify(eq(notificationId), any(Notification.class)); verify(builder).setSmallIcon(R.drawable.notification_icon_... |
SendFailedNotifications { public void clearSendFailedNotification(Account account) { int notificationId = NotificationIds.getSendFailedNotificationId(account); getNotificationManager().cancel(notificationId); } SendFailedNotifications(NotificationController controller, NotificationActionCreator actionBuilder); void sho... | @Test public void testClearSendFailedNotification() throws Exception { sendFailedNotifications.clearSendFailedNotification(account); verify(notificationManager).cancel(notificationId); } |
NotificationData { public AddNotificationResult addNotificationContent(NotificationContent content) { int notificationId; boolean cancelNotificationIdBeforeReuse; if (isMaxNumberOfActiveNotificationsReached()) { NotificationHolder notificationHolder = activeNotifications.removeLast(); addToAdditionalNotifications(notif... | @Test public void testAddNotificationContent() throws Exception { NotificationContent content = createNotificationContent("1"); AddNotificationResult result = notificationData.addNotificationContent(content); assertFalse(result.shouldCancelNotification()); NotificationHolder holder = result.getNotificationHolder(); ass... |
NotificationData { public RemoveNotificationResult removeNotificationForMessage(MessageReference messageReference) { NotificationHolder holder = getNotificationHolderForMessage(messageReference); if (holder == null) { return RemoveNotificationResult.unknownNotification(); } activeNotifications.remove(holder); int notif... | @Test public void testRemoveNotificationForMessage() throws Exception { NotificationContent content = createNotificationContent("1"); notificationData.addNotificationContent(content); RemoveNotificationResult result = notificationData.removeNotificationForMessage(content.messageReference); assertFalse(result.isUnknownN... |
NotificationData { public boolean containsStarredMessages() { for (NotificationHolder holder : activeNotifications) { if (holder.content.starred) { return true; } } for (NotificationContent content : additionalNotifications) { if (content.starred) { return true; } } return false; } NotificationData(Account account); Ad... | @Test public void testContainsStarredMessages() throws Exception { assertFalse(notificationData.containsStarredMessages()); notificationData.addNotificationContent(createNotificationContentForStarredMessage()); assertTrue(notificationData.containsStarredMessages()); } |
NotificationData { public boolean isSingleMessageNotification() { return activeNotifications.size() == 1; } NotificationData(Account account); AddNotificationResult addNotificationContent(NotificationContent content); boolean containsStarredMessages(); boolean hasSummaryOverflowMessages(); int getSummaryOverflowMessage... | @Test public void testIsSingleMessageNotification() throws Exception { assertFalse(notificationData.isSingleMessageNotification()); notificationData.addNotificationContent(createNotificationContent("1")); assertTrue(notificationData.isSingleMessageNotification()); notificationData.addNotificationContent(createNotificat... |
NotificationData { public List<NotificationContent> getContentForSummaryNotification() { int size = calculateNumberOfMessagesForSummaryNotification(); List<NotificationContent> result = new ArrayList<NotificationContent>(size); Iterator<NotificationHolder> iterator = activeNotifications.iterator(); int notificationCoun... | @Test public void testGetContentForSummaryNotification() throws Exception { notificationData.addNotificationContent(createNotificationContent("1")); NotificationContent content4 = createNotificationContent("2"); notificationData.addNotificationContent(content4); NotificationContent content3 = createNotificationContent(... |
NotificationData { public int[] getActiveNotificationIds() { int size = activeNotifications.size(); int[] notificationIds = new int[size]; for (int i = 0; i < size; i++) { NotificationHolder holder = activeNotifications.get(i); notificationIds[i] = holder.notificationId; } return notificationIds; } NotificationData(Acc... | @Test public void testGetActiveNotificationIds() throws Exception { notificationData.addNotificationContent(createNotificationContent("1")); notificationData.addNotificationContent(createNotificationContent("2")); int[] notificationIds = notificationData.getActiveNotificationIds(); assertEquals(2, notificationIds.lengt... |
NotificationData { public Account getAccount() { return account; } NotificationData(Account account); AddNotificationResult addNotificationContent(NotificationContent content); boolean containsStarredMessages(); boolean hasSummaryOverflowMessages(); int getSummaryOverflowMessagesCount(); int getNewMessagesCount(); bool... | @Test public void testGetAccount() throws Exception { assertEquals(account, notificationData.getAccount()); } |
NotificationData { public ArrayList<MessageReference> getAllMessageReferences() { int newSize = activeNotifications.size() + additionalNotifications.size(); ArrayList<MessageReference> messageReferences = new ArrayList<MessageReference>(newSize); for (NotificationHolder holder : activeNotifications) { messageReferences... | @Test public void testGetAllMessageReferences() throws Exception { MessageReference messageReference0 = createMessageReference("1"); MessageReference messageReference1 = createMessageReference("2"); MessageReference messageReference2 = createMessageReference("3"); MessageReference messageReference3 = createMessageRefer... |
NewMailNotifications { public void addNewMailNotification(Account account, LocalMessage message, int unreadMessageCount) { NotificationContent content = contentCreator.createFromMessage(account, message); synchronized (lock) { NotificationData notificationData = getOrCreateNotificationData(account, unreadMessageCount);... | @Test public void testAddNewMailNotification() throws Exception { int notificationIndex = 0; LocalMessage message = createLocalMessage(); NotificationContent content = createNotificationContent(); NotificationHolder holder = createNotificationHolder(content, notificationIndex); addToNotificationContentCreator(message, ... |
NewMailNotifications { public void removeNewMailNotification(Account account, MessageReference messageReference) { synchronized (lock) { NotificationData notificationData = getNotificationData(account); if (notificationData == null) { return; } RemoveNotificationResult result = notificationData.removeNotificationForMes... | @Test public void testRemoveNewMailNotificationWithoutNotificationData() throws Exception { MessageReference messageReference = createMessageReference(1); newMailNotifications.removeNewMailNotification(account, messageReference); verify(notificationManager, never()).cancel(anyInt()); }
@Test public void testRemoveNewMa... |
NewMailNotifications { public void clearNewMailNotifications(Account account) { NotificationData notificationData; synchronized (lock) { notificationData = removeNotificationData(account); } if (notificationData == null) { return; } for (int notificationId : notificationData.getActiveNotificationIds()) { cancelNotifica... | @Test public void testClearNewMailNotificationsWithoutNotificationData() throws Exception { newMailNotifications.clearNewMailNotifications(account); verify(notificationManager, never()).cancel(anyInt()); }
@Test public void testClearNewMailNotifications() throws Exception { int notificationIndex = 0; int notificationId... |
CertificateErrorNotifications { public void showCertificateErrorNotification(Account account, boolean incoming) { int notificationId = NotificationIds.getCertificateErrorNotificationId(account, incoming); Context context = controller.getContext(); PendingIntent editServerSettingsPendingIntent = createContentIntent(cont... | @Test public void testShowCertificateErrorNotificationForIncomingServer() throws Exception { int notificationId = NotificationIds.getCertificateErrorNotificationId(account, INCOMING); certificateErrorNotifications.showCertificateErrorNotification(account, INCOMING); verify(notificationManager).notify(eq(notificationId)... |
CertificateErrorNotifications { public void clearCertificateErrorNotifications(Account account, boolean incoming) { int notificationId = NotificationIds.getCertificateErrorNotificationId(account, incoming); getNotificationManager().cancel(notificationId); } CertificateErrorNotifications(NotificationController controlle... | @Test public void testClearCertificateErrorNotificationsForIncomingServer() throws Exception { int notificationId = NotificationIds.getCertificateErrorNotificationId(account, INCOMING); certificateErrorNotifications.clearCertificateErrorNotifications(account, INCOMING); verify(notificationManager).cancel(notificationId... |
ServerNameSuggester { public String suggestServerName(Type serverType, String domainPart) { switch (serverType) { case IMAP: { return "imap." + domainPart; } case SMTP: { return "smtp." + domainPart; } case EWS: return "outlook.office365.com"; case WebDAV: { return "exchange." + domainPart; } case POP3: { return "pop3.... | @Test public void suggestServerName_forImapServer() throws Exception { Type serverType = Type.IMAP; String domainPart = "example.org"; String result = serverNameSuggester.suggestServerName(serverType, domainPart); assertEquals("imap.example.org", result); }
@Test public void suggestServerName_forPop3Server() throws Exc... |
ReceivedHeaders { public static SecureTransportState wasMessageTransmittedSecurely(Message message) { String[] headers = message.getHeader(RECEIVED); Timber.d("Received headers: " + headers.length); for(String header: headers) { String fromAddress = "", toAddress = "", sslVersion = null, cipher, bits; header = header.t... | @Test public void wasMessageTransmittedSecurely_withNoHeaders_shouldReturnUnknown() throws MessagingException { String[] noReceivedHeaders = new String[]{}; Message unknownMessage = mock(Message.class); when(unknownMessage.getHeader("Received")).thenReturn(noReceivedHeaders); assertEquals(SecureTransportError.UNKNOWN, ... |
SettingsExporter { static void exportPreferences(Context context, OutputStream os, boolean includeGlobals, Set<String> accountUuids) throws SettingsImportExportException { try { XmlSerializer serializer = Xml.newSerializer(); serializer.setOutput(os, "UTF-8"); serializer.startDocument(null, Boolean.TRUE); serializer.se... | @Test public void exportPreferences_producesXML() throws Exception { Document document = exportPreferences(false, Collections.<String>emptySet()); assertEquals("k9settings", document.getRootElement().getName()); }
@Test public void exportPreferences_setsVersionToLatest() throws Exception { Document document = exportPre... |
SettingsImporter { public static ImportResults importSettings(Context context, InputStream inputStream, boolean globalSettings, List<String> accountUuids, boolean overwrite) throws SettingsImportExportException { try { boolean globalSettingsImported = false; List<AccountDescriptionPair> importedAccounts = new ArrayList... | @Test(expected = SettingsImportExportException.class) public void importSettings_throwsExceptionOnBlankFile() throws SettingsImportExportException { InputStream inputStream = new StringInputStream(""); List<String> accountUuids = new ArrayList<>(); SettingsImporter.importSettings(RuntimeEnvironment.application, inputSt... |
SettingsImporter { @VisibleForTesting static Imported parseSettings(InputStream inputStream, boolean globalSettings, List<String> accountUuids, boolean overview) throws SettingsImportExportException { if (!overview && accountUuids == null) { throw new IllegalArgumentException("Argument 'accountUuids' must not be null."... | @Test public void parseSettings_account() throws SettingsImportExportException { String validUUID = UUID.randomUUID().toString(); InputStream inputStream = new StringInputStream("<k9settings format=\"1\" version=\"1\">" + "<accounts><account uuid=\"" + validUUID + "\"><name>Account</name></account></accounts></k9settin... |
SettingsImporter { public static ImportContents getImportStreamContents(InputStream inputStream) throws SettingsImportExportException { try { Imported imported = parseSettings(inputStream, false, null, true); boolean globalSettings = (imported.globalSettings != null); final List<AccountDescription> accounts = new Array... | @Test public void getImportStreamContents_account() throws SettingsImportExportException { String validUUID = UUID.randomUUID().toString(); InputStream inputStream = new StringInputStream("<k9settings format=\"1\" version=\"1\">" + "<accounts>" + "<account uuid=\"" + validUUID + "\">" + "<name>Account</name>" + "<ident... |
ICalData { public List<ICalendarData> getCalendarData() { return calendarData; } ICalData(List<ICalendar> iCalendars); List<ICalendarData> getCalendarData(); static final String METHOD_PUBLISH; static final String METHOD_REPLY; static final String METHOD_REQUEST; static final String METHOD_COUNTER; } | @Test public void ICalendar_constructor_storedRequiredAttendeesFromEvent() { List<ICalendar> iCalendars = new ArrayList<>(); ICalendar iCalendar = new ICalendar(); VEvent event = new VEvent(); Attendee requiredAttendee = new Attendee("A", "a@b.com"); requiredAttendee.setParticipationLevel(ParticipationLevel.REQUIRED); ... |
ICalParser { public static ICalData parse(ICalPart part) { String iCalText = MessageExtractor.getTextFromPart(part.getPart()); if (iCalText == null) { return new ICalData(new ArrayList<ICalendar>()); } return new ICalData(Biweekly.parse(iCalText).all()); } static ICalData parse(ICalPart part); static final String MIME... | @Test public void parse_withNoText_returnsDataWithNoEvents() throws MessagingException { ICalPart part = new ICalPart(null); ICalData data = ICalParser.parse(part); assertEquals(0, data.getCalendarData().size()); }
@Test public void parse_returnsCorrectDataForMinimalPublishEvent() throws MessagingException { String cal... |
TransportUris { public static ServerSettings decodeTransportUri(String uri) { if (uri.startsWith("smtp")) { return decodeSmtpUri(uri); } else if (uri.startsWith("webdav")) { return decodeWebDavUri(uri); } else if (uri.startsWith("ews")) { return decodeEwsUri(uri); } else { throw new IllegalArgumentException("Not a vali... | @Test public void decodeTransportUri_canDecodeAuthType() { String storeUri = "smtp: ServerSettings result = TransportUris.decodeTransportUri(storeUri); assertEquals(AuthType.PLAIN, result.authenticationType); }
@Test public void decodeTransportUri_canDecodeUsername() { String storeUri = "smtp: ServerSettings result = T... |
MessageCryptoStructureDetector { public static boolean isPartPgpInlineEncrypted(@Nullable Part part) { if (part == null) { return false; } if (!part.isMimeType(TEXT_PLAIN) && !part.isMimeType(APPLICATION_PGP)) { return false; } String text = MessageExtractor.getTextFromPart(part, TEXT_LENGTH_FOR_INLINE_CHECK); if (Text... | @Test public void isPgpInlineMethods__withPgpInlineData__shouldReturnTrue() throws Exception { String pgpInlineData = "-----BEGIN PGP MESSAGE-----\n" + "Header: Value\n" + "\n" + "base64base64base64base64\n" + "-----END PGP MESSAGE-----\n"; MimeMessage message = new MimeMessage(); message.setBody(new TextBody(pgpInline... |
TransportUris { public static String createTransportUri(ServerSettings server) { if (Type.SMTP == server.type) { return createSmtpUri(server); } else if (Type.WebDAV == server.type) { return createWebDavUri(server); } else if (Type.EWS == server.type) { return createEwsUri(server); } else { throw new IllegalArgumentExc... | @Test public void createTransportUri_canEncodeSmtpSslUri() { ServerSettings serverSettings = new ServerSettings( ServerSettings.Type.SMTP, "server", 123456, ConnectionSecurity.SSL_TLS_REQUIRED, AuthType.EXTERNAL, "user", "password", "clientCert"); String result = TransportUris.createTransportUri(serverSettings); assert... |
SmtpTransport extends Transport { @Override public void open() throws MessagingException { try { boolean secureConnection = false; InetAddress[] addresses = InetAddress.getAllByName(host); for (int i = 0; i < addresses.length; i++) { try { SocketAddress socketAddress = new InetSocketAddress(addresses[i], port); if (con... | @Test public void open_withoutAuthLoginExtension_shouldConnectWithoutAuthentication() throws Exception { MockSmtpServer server = new MockSmtpServer(); server.output("220 localhost Simple Mail Transfer Service Ready"); server.expect("EHLO localhost"); server.output("250-localhost Hello client.localhost"); server.output(... |
MessageCryptoStructureDetector { @VisibleForTesting static boolean isPartPgpInlineEncryptedOrSigned(Part part) { if (!part.isMimeType(TEXT_PLAIN) && !part.isMimeType(APPLICATION_PGP)) { return false; } String text = MessageExtractor.getTextFromPart(part, TEXT_LENGTH_FOR_INLINE_CHECK); if (TextUtils.isEmpty(text)) { ret... | @Test public void isPartPgpInlineEncryptedOrSigned__withSignedData__shouldReturnTrue() throws Exception { String pgpInlineData = "-----BEGIN PGP SIGNED MESSAGE-----\n" + "Header: Value\n" + "\n" + "-----BEGIN PGP SIGNATURE-----\n" + "Header: Value\n" + "\n" + "base64base64base64base64\n" + "-----END PGP SIGNED MESSAGE-... |
SmtpTransport extends Transport { @Override public void sendMessage(Message message) throws MessagingException { List<Address> addresses = new ArrayList<>(); { addresses.addAll(Arrays.asList(message.getRecipients(RecipientType.TO))); addresses.addAll(Arrays.asList(message.getRecipients(RecipientType.CC))); addresses.ad... | @Test public void sendMessage_withoutAddressToSendTo_shouldNotOpenConnection() throws Exception { MimeMessage message = new MimeMessage(); MockSmtpServer server = createServerAndSetupForPlainAuthentication(); SmtpTransport transport = startServerAndCreateSmtpTransport(server); transport.sendMessage(message); server.ver... |
OpenPgpApiHelper { public static String buildUserId(Identity identity) { StringBuilder sb = new StringBuilder(); String name = identity.getName(); if (!TextUtils.isEmpty(name)) { sb.append(name).append(" "); } sb.append("<").append(identity.getEmail()).append(">"); return sb.toString(); } static String buildUserId(Ide... | @Test public void buildUserId_withName_shouldCreateOpenPgpAccountName() { Identity identity = new Identity(); identity.setEmail("user@domain.com"); identity.setName("Name"); String result = OpenPgpApiHelper.buildUserId(identity); assertEquals("Name <user@domain.com>", result); }
@Test public void buildUserId_withoutNam... |
MessageIdGenerator { public String generateMessageId(Message message) { String hostname = null; Address[] from = message.getFrom(); if (from != null && from.length >= 1) { hostname = from[0].getHostname(); } if (hostname == null) { Address[] replyTo = message.getReplyTo(); if (replyTo != null && replyTo.length >= 1) { ... | @Test public void generateMessageId_withFromAndReplyToAddress() throws Exception { Message message = new MimeMessage(); message.setFrom(new Address("alice@example.org")); message.setReplyTo(Address.parse("bob@example.com")); String result = messageIdGenerator.generateMessageId(message); assertEquals("<00000000-0000-400... |
MessageExtractor { public static String getTextFromPart(Part part) { return getTextFromPart(part, NO_TEXT_SIZE_LIMIT); } private MessageExtractor(); static String getTextFromPart(Part part); static String getTextFromPart(Part part, long textSizeLimit); static boolean hasMissingParts(Part part); static void findViewabl... | @Test public void getTextFromPart_withNoBody_shouldReturnNull() throws Exception { part.setBody(null); String result = MessageExtractor.getTextFromPart(part); assertNull(result); }
@Test public void getTextFromPart_withTextBody_shouldReturnText() throws Exception { part.setHeader(MimeHeader.HEADER_CONTENT_TYPE, "text/p... |
TextSignatureRemover { public static String stripSignature(String content) { if (DASH_SIGNATURE_PLAIN.matcher(content).find()) { content = DASH_SIGNATURE_PLAIN.matcher(content).replaceFirst("\r\n"); } return content; } static String stripSignature(String content); } | @Test public void shouldStripSignature() throws Exception { String text = "This is the body text\r\n" + "\r\n" + "-- \r\n" + "Sent from my Android device with K-9 Mail. Please excuse my brevity."; String withoutSignature = TextSignatureRemover.stripSignature(text); assertEquals("This is the body text\r\n\r\n", withoutS... |
FlowedMessageUtils { static boolean isFormatFlowed(String contentType) { String mimeType = getHeaderParameter(contentType, null); if (isSameMimeType(TEXT_PLAIN, mimeType)) { String formatParameter = getHeaderParameter(contentType, HEADER_PARAM_FORMAT); return HEADER_FORMAT_FLOWED.equalsIgnoreCase(formatParameter); } re... | @Test public void isFormatFlowed_withTextPlainFormatFlowed_shouldReturnTrue() throws Exception { assertTrue(isFormatFlowed("text/plain; format=flowed")); }
@Test public void isFormatFlowed_withTextPlain_shouldReturnFalse() throws Exception { assertFalse(isFormatFlowed("text/plain")); }
@Test public void isFormatFlowed_... |
FlowedMessageUtils { static boolean isDelSp(String contentType) { if (isFormatFlowed(contentType)) { String delSpParameter = getHeaderParameter(contentType, HEADER_PARAM_DELSP); return HEADER_DELSP_YES.equalsIgnoreCase(delSpParameter); } return false; } } | @Test public void isDelSp_withFormatFlowed_shouldReturnTrue() throws Exception { assertTrue(isDelSp("text/plain; format=flowed; delsp=yes")); }
@Test public void isDelSp_withTextPlainFormatFlowed_shoulReturnFalse() throws Exception { assertFalse(isDelSp("text/plain; format=flowed")); }
@Test public void isDelSp_without... |
ListHeaders { public static Address[] getListPostAddresses(Message message) { String[] headerValues = message.getHeader(LIST_POST_HEADER); if (headerValues.length < 1) { return new Address[0]; } List<Address> listPostAddresses = new ArrayList<>(); for (String headerValue : headerValues) { Address address = extractAddre... | @Test public void getListPostAddresses_withMailTo_shouldReturnCorrectAddress() throws Exception { for (String emailAddress : TEST_EMAIL_ADDRESSES) { String headerValue = "<mailto:" + emailAddress + ">"; Message message = buildMimeMessageWithListPostValue(headerValue); Address[] result = ListHeaders.getListPostAddresses... |
HtmlSignatureRemover { public static String stripSignature(String content) { return new HtmlSignatureRemover().stripSignatureInternal(content); } static String stripSignature(String content); } | @Test public void shouldStripSignatureFromK9StyleHtml() throws Exception { String html = "This is the body text" + "<br>" + "-- <br>" + "Sent from my Android device with K-9 Mail. Please excuse my brevity."; String withoutSignature = HtmlSignatureRemover.stripSignature(html); assertEquals("This is the body text", extra... |
MimeUtility { public static String getHeaderParameter(String headerValue, String parameterName) { if (headerValue == null) { return null; } headerValue = headerValue.replaceAll("\r|\n", ""); String[] parts = headerValue.split(";"); if (parameterName == null && parts.length > 0) { return parts[0].trim(); } for (String p... | @Test public void testGetHeaderParameter() { String result; result = MimeUtility.getHeaderParameter(";", null); assertEquals(null, result); result = MimeUtility.getHeaderParameter("name", "name"); assertEquals(null, result); result = MimeUtility.getHeaderParameter("name=", "name"); assertEquals("", result); result = Mi... |
MimeUtility { public static boolean isMultipart(String mimeType) { return mimeType != null && mimeType.toLowerCase(Locale.US).startsWith("multipart/"); } static String unfold(String s); static String unfoldAndDecode(String s); static String unfoldAndDecode(String s, Message message); static String foldAndEncode(String... | @Test public void isMultipart_withLowerCaseMultipart_shouldReturnTrue() throws Exception { assertTrue(MimeUtility.isMultipart("multipart/mixed")); }
@Test public void isMultipart_withUpperCaseMultipart_shouldReturnTrue() throws Exception { assertTrue(MimeUtility.isMultipart("MULTIPART/ALTERNATIVE")); }
@Test public voi... |
MimeUtility { public static boolean isMessage(String mimeType) { return isSameMimeType(mimeType, "message/rfc822"); } static String unfold(String s); static String unfoldAndDecode(String s); static String unfoldAndDecode(String s, Message message); static String foldAndEncode(String s); static String getHeaderParamete... | @Test public void isMessage_withLowerCaseMessage_shouldReturnTrue() throws Exception { assertTrue(MimeUtility.isMessage("message/rfc822")); }
@Test public void isMessage_withUpperCaseMessage_shouldReturnTrue() throws Exception { assertTrue(MimeUtility.isMessage("MESSAGE/RFC822")); }
@Test public void isMessage_withMixe... |
MimeUtility { public static boolean isSameMimeType(String mimeType, String otherMimeType) { return mimeType != null && mimeType.equalsIgnoreCase(otherMimeType); } static String unfold(String s); static String unfoldAndDecode(String s); static String unfoldAndDecode(String s, Message message); static String foldAndEnco... | @Test public void isSameMimeType_withSameTypeAndCase_shouldReturnTrue() throws Exception { assertTrue(MimeUtility.isSameMimeType("text/plain", "text/plain")); }
@Test public void isSameMimeType_withSameTypeButMixedCase_shouldReturnTrue() throws Exception { assertTrue(MimeUtility.isSameMimeType("text/plain", "Text/Plain... |
CharsetSupport { static String fixupCharset(String charset, Message message) throws MessagingException { if (charset == null || "0".equals(charset)) charset = "US-ASCII"; charset = charset.toLowerCase(Locale.US); if (charset.equals("cp932")) charset = SHIFT_JIS; if (charset.equals(SHIFT_JIS) || charset.equals("iso-2022... | @Test public void testFixupCharset() throws Exception { String charsetOnMail; String expect; charsetOnMail = "CP932"; expect = "shift_jis"; assertEquals(expect, CharsetSupport.fixupCharset(charsetOnMail, new MimeMessage())); MimeMessage message; message = new MimeMessage(); message.setHeader("From", "aaa@docomo.ne.jp")... |
DecoderUtil { public static String decodeEncodedWords(String body, Message message) { if (!body.contains("=?")) { return body; } int previousEnd = 0; boolean previousWasEncoded = false; StringBuilder sb = new StringBuilder(); while (true) { int begin = body.indexOf("=?", previousEnd); if (begin == -1) { sb.append(body.... | @Test public void testDecodeEncodedWords() { String body, expect; MimeMessage message; body = "abc"; expect = "abc"; message = null; assertEquals(expect, DecoderUtil.decodeEncodedWords(body, message)); body = "=?us-ascii?q?abc?="; expect = "abc"; message = null; assertEquals(expect, DecoderUtil.decodeEncodedWords(body,... |
SmtpDataStuffing extends FilterOutputStream { @Override public void write(int oneByte) throws IOException { if (oneByte == '\r') { state = STATE_CR; } else if ((state == STATE_CR) && (oneByte == '\n')) { state = STATE_CRLF; } else if ((state == STATE_CRLF) && (oneByte == '.')) { super.write('.'); state = STATE_NORMAL; ... | @Test public void dotAtStartOfLine() throws IOException { smtpDataStuffing.write(bytesFor("Hello dot\r\n.")); assertEquals("Hello dot\r\n..", buffer.readUtf8()); }
@Test public void dotAtStartOfStream() throws IOException { smtpDataStuffing.write(bytesFor(".Hello dots")); assertEquals("..Hello dots", buffer.readUtf8())... |
FixedLengthInputStream extends InputStream { @Override public int read() throws IOException { if (mCount >= mLength) { return -1; } int d = mIn.read(); if (d != -1) { mCount++; } return d; } FixedLengthInputStream(InputStream in, int length); @Override int available(); @Override int read(); @Override int read(byte[] b,... | @Test public void read_withOverSizedByteArray_shouldReturnDataUpToLimit() throws Exception { FixedLengthInputStream fixedLengthInputStream = new FixedLengthInputStream(inputStream("Hello World"), 6); byte[] data = new byte[100]; int numberOfBytesRead = fixedLengthInputStream.read(data); assertEquals(6, numberOfBytesRea... |
FixedLengthInputStream extends InputStream { @Override public int available() throws IOException { return mLength - mCount; } FixedLengthInputStream(InputStream in, int length); @Override int available(); @Override int read(); @Override int read(byte[] b, int offset, int length); @Override int read(byte[] b); @Override... | @Test public void available_atStartOfStream() throws Exception { FixedLengthInputStream fixedLengthInputStream = new FixedLengthInputStream(inputStream("Hello World"), 5); int available = fixedLengthInputStream.available(); assertEquals(5, available); }
@Test public void available_afterPartialReadArray() throws Excepti... |
FixedLengthInputStream extends InputStream { public void skipRemaining() throws IOException { while (available() > 0) { skip(available()); } } FixedLengthInputStream(InputStream in, int length); @Override int available(); @Override int read(); @Override int read(byte[] b, int offset, int length); @Override int read(byt... | @Test public void skipRemaining_shouldExhaustStream() throws IOException { FixedLengthInputStream fixedLengthInputStream = new FixedLengthInputStream(inputStream("Hello World"), 5); fixedLengthInputStream.skipRemaining(); assertInputStreamExhausted(fixedLengthInputStream); }
@Test public void skipRemaining_shouldNotCon... |
SignSafeOutputStream extends FilterOutputStream { public SignSafeOutputStream(OutputStream out) { super(out); outBuffer = new byte[DEFAULT_BUFFER_SIZE]; } SignSafeOutputStream(OutputStream out); void encode(byte next); @Override void write(int b); @Override void write(byte[] b, int off, int len); @Override void flush()... | @Test public void testSignSafeOutputStream() throws IOException { ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); OutputStream output = new SignSafeOutputStream(byteArrayOutputStream); output.write(INPUT_STRING.getBytes("US-ASCII")); output.close(); assertEquals(EXPECTED_SIGNSAFE, new String(... |
Address implements Serializable { @VisibleForTesting static String quoteString(String s) { if (s == null) { return null; } if (!s.matches("^\".*\"$")) { return "\"" + s + "\""; } else { return s; } } Address(Address address); Address(String address, String personal); Address(String address); private Address(String a... | @Test public void stringQuotationShouldCorrectlyQuote() { assertEquals("\"sample\"", Address.quoteString("sample")); assertEquals("\"\"sample\"\"", Address.quoteString("\"\"sample\"\"")); assertEquals("\"sample\"", Address.quoteString("\"sample\"")); assertEquals("\"sa\"mp\"le\"", Address.quoteString("sa\"mp\"le")); as... |
Pop3Store extends RemoteStore { public static ServerSettings decodeUri(String uri) { String host; int port; ConnectionSecurity connectionSecurity; String username = null; String password = null; String clientCertificateAlias = null; URI pop3Uri; try { pop3Uri = new URI(uri); } catch (URISyntaxException use) { throw new... | @Test public void decodeUri_withTLSUri_shouldUseStartTls() { ServerSettings settings = Pop3Store.decodeUri("pop3+tls+: assertEquals(settings.connectionSecurity, ConnectionSecurity.STARTTLS_REQUIRED); }
@Test public void decodeUri_withPlainUri_shouldUseNoSecurity() { ServerSettings settings = Pop3Store.decodeUri("pop3: ... |
Pop3Store extends RemoteStore { public static String createUri(ServerSettings server) { String userEnc = encodeUtf8(server.username); String passwordEnc = (server.password != null) ? encodeUtf8(server.password) : ""; String clientCertificateAliasEnc = (server.clientCertificateAlias != null) ? encodeUtf8(server.clientCe... | @Test public void createUri_withSSLTLS_required_shouldProduceSSLUri() { ServerSettings settings = new ServerSettings(Type.POP3, "server", 12345, ConnectionSecurity.SSL_TLS_REQUIRED, AuthType.PLAIN, "user", "password", null); String uri = Pop3Store.createUri(settings); assertEquals(uri, "pop3+ssl+: }
@Test public void c... |
Pop3Store extends RemoteStore { @Override @NonNull public Pop3Folder getFolder(String name) { Pop3Folder folder = mFolders.get(name); if (folder == null) { folder = new Pop3Folder(this, name); mFolders.put(folder.getId(), folder); } return folder; } Pop3Store(StoreConfig storeConfig, TrustedSocketFactory socketFactory)... | @Test public void getFolder_shouldReturnSameFolderEachTime() { Pop3Folder folderOne = store.getFolder("TestFolder"); Pop3Folder folderTwo = store.getFolder("TestFolder"); assertSame(folderOne, folderTwo); }
@Test public void getFolder_shouldReturnFolderWithCorrectName() throws Exception { Pop3Folder folder = store.getF... |
Pop3Store extends RemoteStore { @Override @NonNull public List <Pop3Folder> getFolders(boolean forceListAll) throws MessagingException { List<Pop3Folder> folders = new LinkedList<>(); folders.add(getFolder(mStoreConfig.getInboxFolderId())); return folders; } Pop3Store(StoreConfig storeConfig, TrustedSocketFactory socke... | @Test public void getPersonalNamespace_shouldReturnListConsistingOfInbox() throws Exception { List<Pop3Folder> folders = store.getFolders(true); assertEquals(1, folders.size()); assertEquals("Inbox", folders.get(0).getId()); } |
EthereumUriParser implements UriParser { @Override public int linkifyUri(String text, int startPos, StringBuffer outputBuffer) { Matcher matcher = ETHEREUM_URI_PATTERN.matcher(text); if (!matcher.find(startPos) || matcher.start() != startPos) { return startPos; } String ethereumURI = matcher.group(); outputBuffer.appen... | @Test public void uriInMiddleOfInput() throws Exception { String prefix = "prefix "; String uri = "ethereum:0xfdf1210fc262c73d0436236a0e07be419babbbc4?value=42"; String text = prefix + uri; parser.linkifyUri(text, prefix.length(), outputBuffer); assertLinkOnly(uri, outputBuffer); } |
Pop3Store extends RemoteStore { @Override public boolean isSeenFlagSupported() { return false; } Pop3Store(StoreConfig storeConfig, TrustedSocketFactory socketFactory); static ServerSettings decodeUri(String uri); static String createUri(ServerSettings server); @Override @NonNull Pop3Folder getFolder(String name); @Ove... | @Test public void isSeenFlagSupported_shouldReturnFalse() throws Exception { boolean result = store.isSeenFlagSupported(); assertFalse(result); } |
Pop3Store extends RemoteStore { @Override public void checkSettings() throws MessagingException { Pop3Folder folder = new Pop3Folder(this, mStoreConfig.getInboxFolderId()); try { folder.open(Folder.OPEN_MODE_RW); folder.requestUidl(); } finally { folder.close(); } } Pop3Store(StoreConfig storeConfig, TrustedSocketFacto... | @Test(expected = MessagingException.class) public void checkSetting_whenConnectionThrowsException_shouldThrowMessagingException() throws Exception { when(mockTrustedSocketFactory.createSocket(any(Socket.class), anyString(), anyInt(), anyString())).thenThrow(new IOException("Test")); store.checkSettings(); }
@Test(expec... |
Pop3Capabilities { @Override public String toString() { return String.format("CRAM-MD5 %b, PLAIN %b, STLS %b, TOP %b, UIDL %b, EXTERNAL %b", cramMD5, authPlain, stls, top, uidl, external); } @Override String toString(); } | @Test public void toString_producesReadableOutput() { String result = new Pop3Capabilities().toString(); assertEquals( "CRAM-MD5 false, PLAIN false, STLS false, TOP false, UIDL false, EXTERNAL false", result); } |
Pop3Folder extends Folder<Pop3Message> { @Override public boolean create(FolderType type) throws MessagingException { return false; } Pop3Folder(Pop3Store pop3Store, String name); @Override String getParentId(); @Override synchronized void open(int mode); @Override boolean isOpen(); @Override int getMode(); @Override v... | @Test public void create_withHoldsFoldersArgument_shouldDoNothing() throws Exception { Pop3Folder folder = new Pop3Folder(mockStore, "TestFolder"); boolean result = folder.create(FolderType.HOLDS_FOLDERS); assertFalse(result); verifyZeroInteractions(mockConnection); }
@Test public void create_withHoldsMessagesArgument_... |
Pop3Folder extends Folder<Pop3Message> { @Override public boolean exists() throws MessagingException { return name.equalsIgnoreCase(pop3Store.getConfig().getInboxFolderId()); } Pop3Folder(Pop3Store pop3Store, String name); @Override String getParentId(); @Override synchronized void open(int mode); @Override boolean isO... | @Test public void exists_withInbox_shouldReturnTrue() throws Exception { boolean result = folder.exists(); assertTrue(result); }
@Test public void exists_withNonInboxFolder_shouldReturnFalse() throws Exception { folder = new Pop3Folder(mockStore, "TestFolder"); boolean result = folder.exists(); assertFalse(result); } |
UriLinkifier { public static void linkifyText(String text, StringBuffer outputBuffer) { int currentPos = 0; Matcher matcher = URI_SCHEME.matcher(text); while (matcher.find(currentPos)) { int startPos = matcher.start(1); String textBeforeMatch = text.substring(currentPos, startPos); outputBuffer.append(textBeforeMatch);... | @Test public void emptyText() { String text = ""; UriLinkifier.linkifyText(text, outputBuffer); assertEquals(text, outputBuffer.toString()); }
@Test public void textWithoutUri_shouldBeCopiedToOutputBuffer() { String text = "some text here"; UriLinkifier.linkifyText(text, outputBuffer); assertEquals(text, outputBuffer.t... |
Pop3Folder extends Folder<Pop3Message> { @Override public int getUnreadMessageCount() throws MessagingException { return -1; } Pop3Folder(Pop3Store pop3Store, String name); @Override String getParentId(); @Override synchronized void open(int mode); @Override boolean isOpen(); @Override int getMode(); @Override void clo... | @Test public void getUnreadMessageCount_shouldBeMinusOne() throws Exception { int result = folder.getUnreadMessageCount(); assertEquals(-1, result); } |
Pop3Folder extends Folder<Pop3Message> { @Override public int getFlaggedMessageCount() throws MessagingException { return -1; } Pop3Folder(Pop3Store pop3Store, String name); @Override String getParentId(); @Override synchronized void open(int mode); @Override boolean isOpen(); @Override int getMode(); @Override void cl... | @Test public void getFlaggedMessageCount_shouldBeMinusOne() throws Exception { int result = folder.getFlaggedMessageCount(); assertEquals(-1, result); } |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.