Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 532aa76f authored by cketti's avatar cketti
Browse files

Switch NotificationIds.getNewMailStackedNotificationId() to a 0-based index

parent 75cdb7b4
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -66,7 +66,7 @@ class NotificationData {
    }

    private int getNewNotificationId() {
        for (int i = 1; i <= MAX_NUMBER_OF_STACKED_NOTIFICATIONS; i++) {
        for (int i = 0; i < MAX_NUMBER_OF_STACKED_NOTIFICATIONS; i++) {
            int notificationId = NotificationIds.getNewMailStackedNotificationId(account, i);
            if (!isNotificationInUse(notificationId)) {
                markNotificationIdAsInUse(notificationId);
+2 −2
Original line number Diff line number Diff line
@@ -24,11 +24,11 @@ class NotificationIds {
    }

    public static int getNewMailStackedNotificationId(Account account, int index) {
        if (index < 1 || index > NUMBER_OF_STACKED_NOTIFICATIONS) {
        if (index < 0 || index >= NUMBER_OF_STACKED_NOTIFICATIONS) {
            throw new IndexOutOfBoundsException("Invalid value: " + index);
        }

        return getBaseNotificationId(account) + OFFSET_NEW_MAIL_STACKED + index - 1;
        return getBaseNotificationId(account) + OFFSET_NEW_MAIL_STACKED + index;
    }

    public static int getFetchingMailNotificationId(Account account) {
+10 −10
Original line number Diff line number Diff line
@@ -55,7 +55,7 @@ public class NewMailNotificationsTest {

    @Test
    public void testAddNewMailNotification() throws Exception {
        int notificationIndex = 1;
        int notificationIndex = 0;
        LocalMessage message = createLocalMessage();
        NotificationContent content = createNotificationContent();
        NotificationHolder holder = createNotificationHolder(content, notificationIndex);
@@ -76,7 +76,7 @@ public class NewMailNotificationsTest {

    @Test
    public void testAddNewMailNotificationWithCancelingExistingNotification() throws Exception {
        int notificationIndex = 1;
        int notificationIndex = 0;
        LocalMessage message = createLocalMessage();
        NotificationContent content = createNotificationContent();
        NotificationHolder holder = createNotificationHolder(content, notificationIndex);
@@ -99,7 +99,7 @@ public class NewMailNotificationsTest {
    @Test
    public void testAddNewMailNotificationWithPrivacyModeEnabled() throws Exception {
        enablePrivacyMode();
        int notificationIndex = 1;
        int notificationIndex = 0;
        LocalMessage message = createLocalMessage();
        NotificationContent content = createNotificationContent();
        NotificationHolder holder = createNotificationHolder(content, notificationIndex);
@@ -118,8 +118,8 @@ public class NewMailNotificationsTest {

    @Test
    public void testAddNewMailNotificationTwice() throws Exception {
        int notificationIndexOne = 1;
        int notificationIndexTwo = 2;
        int notificationIndexOne = 0;
        int notificationIndexTwo = 1;
        LocalMessage messageOne = createLocalMessage();
        LocalMessage messageTwo = createLocalMessage();
        NotificationContent contentOne = createNotificationContent();
@@ -161,7 +161,7 @@ public class NewMailNotificationsTest {
    public void testRemoveNewMailNotificationWithUnknownMessageReference() throws Exception {
        enablePrivacyMode();
        MessageReference messageReference = createMessageReference(1);
        int notificationIndex = 1;
        int notificationIndex = 0;
        LocalMessage message = createLocalMessage();
        NotificationContent content = createNotificationContent();
        NotificationHolder holder = createNotificationHolder(content, notificationIndex);
@@ -181,7 +181,7 @@ public class NewMailNotificationsTest {
    public void testRemoveNewMailNotification() throws Exception {
        enablePrivacyMode();
        MessageReference messageReference = createMessageReference(1);
        int notificationIndex = 1;
        int notificationIndex = 0;
        int notificationId = NotificationIds.getNewMailStackedNotificationId(account, notificationIndex);
        LocalMessage message = createLocalMessage();
        NotificationContent content = createNotificationContent();
@@ -203,7 +203,7 @@ public class NewMailNotificationsTest {
    @Test
    public void testRemoveNewMailNotificationClearingAllNotifications() throws Exception {
        MessageReference messageReference = createMessageReference(1);
        int notificationIndex = 1;
        int notificationIndex = 0;
        int notificationId = NotificationIds.getNewMailStackedNotificationId(account, notificationIndex);
        LocalMessage message = createLocalMessage();
        NotificationContent content = createNotificationContent();
@@ -227,7 +227,7 @@ public class NewMailNotificationsTest {
    @Test
    public void testRemoveNewMailNotificationWithCreateNotification() throws Exception {
        MessageReference messageReference = createMessageReference(1);
        int notificationIndex = 1;
        int notificationIndex = 0;
        int notificationId = NotificationIds.getNewMailStackedNotificationId(account, notificationIndex);
        LocalMessage message = createLocalMessage();
        NotificationContent contentOne = createNotificationContent();
@@ -262,7 +262,7 @@ public class NewMailNotificationsTest {

    @Test
    public void testClearNewMailNotifications() throws Exception {
        int notificationIndex = 1;
        int notificationIndex = 0;
        int notificationId = NotificationIds.getNewMailStackedNotificationId(account, notificationIndex);
        LocalMessage message = createLocalMessage();
        NotificationContent content = createNotificationContent();
+7 −7
Original line number Diff line number Diff line
@@ -46,7 +46,7 @@ public class NotificationDataTest {
        assertFalse(result.shouldCancelNotification());
        NotificationHolder holder = result.getNotificationHolder();
        assertNotNull(holder);
        assertEquals(NotificationIds.getNewMailStackedNotificationId(account, 1), holder.notificationId);
        assertEquals(NotificationIds.getNewMailStackedNotificationId(account, 0), holder.notificationId);
        assertEquals(content, holder.content);
    }

@@ -65,7 +65,7 @@ public class NotificationDataTest {
        AddNotificationResult result = notificationData.addNotificationContent(createNotificationContent("9"));

        assertTrue(result.shouldCancelNotification());
        assertEquals(NotificationIds.getNewMailStackedNotificationId(account, 1), result.getNotificationId());
        assertEquals(NotificationIds.getNewMailStackedNotificationId(account, 0), result.getNotificationId());
    }

    @Test
@@ -76,7 +76,7 @@ public class NotificationDataTest {
        RemoveNotificationResult result = notificationData.removeNotificationForMessage(content.messageReference);

        assertFalse(result.isUnknownNotification());
        assertEquals(NotificationIds.getNewMailStackedNotificationId(account, 1), result.getNotificationId());
        assertEquals(NotificationIds.getNewMailStackedNotificationId(account, 0), result.getNotificationId());
        assertFalse(result.shouldCreateNotification());
    }

@@ -99,11 +99,11 @@ public class NotificationDataTest {
                notificationData.removeNotificationForMessage(latestContent.messageReference);

        assertFalse(result.isUnknownNotification());
        assertEquals(NotificationIds.getNewMailStackedNotificationId(account, 2), result.getNotificationId());
        assertEquals(NotificationIds.getNewMailStackedNotificationId(account, 1), result.getNotificationId());
        assertTrue(result.shouldCreateNotification());
        NotificationHolder holder = result.getNotificationHolder();
        assertNotNull(holder);
        assertEquals(NotificationIds.getNewMailStackedNotificationId(account, 2), holder.notificationId);
        assertEquals(NotificationIds.getNewMailStackedNotificationId(account, 1), holder.notificationId);
        assertEquals(content, holder.content);
    }

@@ -214,8 +214,8 @@ public class NotificationDataTest {
        int[] notificationIds = notificationData.getActiveNotificationIds();

        assertEquals(2, notificationIds.length);
        assertEquals(NotificationIds.getNewMailStackedNotificationId(account, 2), notificationIds[0]);
        assertEquals(NotificationIds.getNewMailStackedNotificationId(account, 1), notificationIds[1]);
        assertEquals(NotificationIds.getNewMailStackedNotificationId(account, 1), notificationIds[0]);
        assertEquals(NotificationIds.getNewMailStackedNotificationId(account, 0), notificationIds[1]);
    }

    @Test
+4 −4
Original line number Diff line number Diff line
@@ -29,7 +29,7 @@ public class NotificationIdsTest {
    @Test
    public void getNewMailStackedNotificationId_withDefaultAccount() throws Exception {
        Account account = createMockAccountWithAccountNumber(0);
        int notificationIndex = 1;
        int notificationIndex = 0;

        int notificationId = NotificationIds.getNewMailStackedNotificationId(account, notificationIndex);

@@ -40,14 +40,14 @@ public class NotificationIdsTest {
    public void getNewMailStackedNotificationId_withTooLowIndex() throws Exception {
        Account account = createMockAccountWithAccountNumber(0);

        NotificationIds.getNewMailStackedNotificationId(account, 0);
        NotificationIds.getNewMailStackedNotificationId(account, -1);
    }

    @Test(expected = IndexOutOfBoundsException.class)
    public void getNewMailStackedNotificationId_withTooLargeIndex() throws Exception {
        Account account = createMockAccountWithAccountNumber(0);

        NotificationIds.getNewMailStackedNotificationId(account, 9);
        NotificationIds.getNewMailStackedNotificationId(account, 8);
    }

    @Test
@@ -62,7 +62,7 @@ public class NotificationIdsTest {
    @Test
    public void getNewMailStackedNotificationId_withSecondAccount() throws Exception {
        Account account = createMockAccountWithAccountNumber(1);
        int notificationIndex = 8;
        int notificationIndex = 7;

        int notificationId = NotificationIds.getNewMailStackedNotificationId(account, notificationIndex);

Loading