NotificationsCleaner { public Completable cleanOtherUsersNotifications(String id) { List<String> idsList = new ArrayList<>(2); idsList.add(id); idsList.add(""); return roomNotificationPersistence.deleteAllExcluding(idsList); } 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 cleanOtherUsersNotifications() throws Exception { Map<String, RoomNotification> list = new HashMap<>(); Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("UTC")); long timeStamp = calendar.getTimeInMillis(); RoomNotification notification = createNotification(timeStamp + 1000, timeStamp, "me", true); list.put(notification.getKey(), notification); timeStamp = System.currentTimeMillis(); notification = createNotification(timeStamp + 1000, 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()); TestSubscriber<Object> objectTestSubscriber = TestSubscriber.create(); notificationsCleaner.cleanOtherUsersNotifications("you") .subscribe(objectTestSubscriber); objectTestSubscriber.awaitTerminalEvent(); objectTestSubscriber.assertCompleted(); objectTestSubscriber.assertNoErrors(); assertEquals(roomNotificationPersistence.getAllSortedDesc() .toBlocking() .first() .size(), 0); }