NotificationsCleaner { public Completable cleanLimitExceededNotifications(int limit) { return removeExpiredNotifications().andThen(removeExceededLimitNotifications(limit)); } NotificationsCleaner(RoomNotificationPersistence roomNotificationPersistence,
      Calendar calendar, AptoideAccountManager accountManager,
      NotificationProvider notificationProvider, CrashReport crashReport); void setup(); Completable cleanOtherUsersNotifications(String id); Completable cleanLimitExceededNotifications(int limit); static final int MAX_NUMBER_NOTIFICATIONS_SAVED; }
@Test public void cleanLimitExceededNotificationsWithAExpiredNotification() throws Exception { TestSubscriber<Object> objectTestSubscriber = TestSubscriber.create(); Map<String, RoomNotification> list = new HashMap<>(); long timeStamp = System.currentTimeMillis(); RoomNotification notification = createNotification(timeStamp, timeStamp, "me", true); list.put(notification.getKey(), notification); timeStamp = System.currentTimeMillis(); notification = createNotification(timeStamp + 10000, timeStamp - 1000, "me", true); list.put(notification.getKey(), notification); timeStamp = System.currentTimeMillis(); notification = createNotification(timeStamp + 20000, timeStamp - 2000, "me", true); list.put(notification.getKey(), notification); RoomNotificationPersistence roomNotificationPersistence = new NotPersistenceRoom(list); NotificationsCleaner notificationsCleaner = new NotificationsCleaner(roomNotificationPersistence, Calendar.getInstance(TimeZone.getTimeZone("UTC")), getAptoideAccountManager(), getNotificationProvider(), CrashReport.getInstance()); notificationsCleaner.cleanLimitExceededNotifications(2) .subscribe(objectTestSubscriber); objectTestSubscriber.awaitTerminalEvent(); objectTestSubscriber.assertCompleted(); objectTestSubscriber.assertNoErrors(); assertEquals(2, roomNotificationPersistence.getAllSortedDesc() .toBlocking() .first() .size()); }
@Test public void cleanLimitExceededNotificationsWithAExpiredNotificationAndExceedingLimit() throws Exception { Map<String, RoomNotification> list = new HashMap<>(); long timeStamp = System.currentTimeMillis(); RoomNotification notification = createNotification(0L, timeStamp, "me", true); list.put(notification.getKey(), notification); timeStamp = System.currentTimeMillis(); notification = createNotification(timeStamp + 2000, timeStamp - 10000, "me", true); list.put(notification.getKey(), notification); timeStamp = System.currentTimeMillis(); notification = createNotification(timeStamp + 2000, timeStamp - 20000, "me", true); list.put(notification.getKey(), notification); RoomNotificationPersistence roomNotificationPersistence = new NotPersistenceRoom(list); NotificationsCleaner notificationsCleaner = new NotificationsCleaner(roomNotificationPersistence, Calendar.getInstance(TimeZone.getTimeZone("UTC")), getAptoideAccountManager(), getNotificationProvider(), CrashReport.getInstance()); TestSubscriber<Object> objectTestSubscriber = TestSubscriber.create(); List<RoomNotification> notificationList = roomNotificationPersistence.getAllSortedDesc() .toBlocking() .first(); notificationsCleaner.cleanLimitExceededNotifications(1) .subscribe(objectTestSubscriber); objectTestSubscriber.awaitTerminalEvent(); objectTestSubscriber.assertCompleted(); objectTestSubscriber.assertNoErrors(); assertEquals(roomNotificationPersistence.getAllSortedDesc() .toBlocking() .first() .size(), 1); assertEquals(roomNotificationPersistence.getAllSortedDesc() .toBlocking() .first() .get(0) .getKey(), notificationList.get(1) .getKey()); }
@Test public void cleanLimitExceededNotificationsExceedingLimit() throws Exception { TestSubscriber<Object> objectTestSubscriber = TestSubscriber.create(); Map<String, RoomNotification> list = new HashMap<>(); long timeStamp = System.currentTimeMillis(); RoomNotification notification = createNotification(timeStamp + 2000, timeStamp, "me", true); list.put(notification.getKey(), notification); timeStamp = System.currentTimeMillis(); notification = createNotification(timeStamp + 2000, timeStamp - 1, "me", true); list.put(notification.getKey(), notification); timeStamp = System.currentTimeMillis(); notification = createNotification(timeStamp + 2000, timeStamp - 2, "me", true); list.put(notification.getKey(), notification); RoomNotificationPersistence roomNotificationPersistence = new NotPersistenceRoom(list); NotificationsCleaner notificationsCleaner = new NotificationsCleaner(roomNotificationPersistence, Calendar.getInstance(TimeZone.getTimeZone("UTC")), getAptoideAccountManager(), getNotificationProvider(), CrashReport.getInstance()); List<RoomNotification> notificationList = roomNotificationPersistence.getAllSortedDesc() .toBlocking() .first(); notificationsCleaner.cleanLimitExceededNotifications(1) .subscribe(objectTestSubscriber); objectTestSubscriber.awaitTerminalEvent(); objectTestSubscriber.assertCompleted(); objectTestSubscriber.assertNoErrors(); assertEquals(roomNotificationPersistence.getAllSortedDesc() .toBlocking() .first() .size(), 1); assertEquals(roomNotificationPersistence.getAllSortedDesc() .toBlocking() .first() .get(0) .getKey(), notificationList.get(0) .getKey()); }
@Test public void cleanLimitExceededNotificationsNotExpiring() throws Exception { TestSubscriber<Object> objectTestSubscriber = TestSubscriber.create(); Map<String, RoomNotification> list = new HashMap<>(); long timeStamp = System.currentTimeMillis(); RoomNotification notification = createNotification(null, timeStamp, "me", true); list.put(notification.getKey(), notification); notification = createNotification(null, timeStamp - 1, "me", true); list.put(notification.getKey(), notification); notification = createNotification(null, timeStamp - 2, "me", true); list.put(notification.getKey(), notification); RoomNotificationPersistence roomNotificationPersistence = new NotPersistenceRoom(list); NotificationsCleaner notificationsCleaner = new NotificationsCleaner(roomNotificationPersistence, Calendar.getInstance(TimeZone.getTimeZone("UTC")), getAptoideAccountManager(), getNotificationProvider(), CrashReport.getInstance()); notificationsCleaner.cleanLimitExceededNotifications(3) .subscribe(objectTestSubscriber); objectTestSubscriber.awaitTerminalEvent(); objectTestSubscriber.assertCompleted(); objectTestSubscriber.assertNoErrors(); assertEquals(roomNotificationPersistence.getAllSortedDesc() .toBlocking() .first() .size(), 3); }