AlarmService { public Collection<Alarm> searchAlarmsBySubscriptionTarget(String subTarget) { return getAllAlarms().stream().filter(alarm -> alarm.getSubscriptions().stream().anyMatch(sub -> subTarget.equals(sub.getTarget()))) .collect(Collectors.toList()); }  Alarm getAlarm(String id); Collection<Alarm> getAllAlarms(); Alarm subscribeToAAlarm(final Alarm alarm); Alarm searchAlarm(final Alarm alarm); Collection<Alarm> searchAlarmsBySubscriptionTarget(String subTarget); Alarm updateAlarm(final Alarm alarm);  }
@Test public void searchAlarmsBySubscriptionTarget() throws Exception { Subscription notDefaultTargetSubscription = TestUtils.getDefaultSubscription(); notDefaultTargetSubscription.setTarget("supercoucou"); Alarm alarm1 = TestUtils.getDefaultAlarm(); Alarm alarm2 = TestUtils.getDefaultAlarm(); Alarm alarmWithoutDefaultTargetSubscription = TestUtils.getDefaultAlarm(); alarmWithoutDefaultTargetSubscription.setSubscriptions(asList(notDefaultTargetSubscription)); Alarm.Alarms alarms = new Alarm.Alarms(); alarms.setValues(asList(alarm1, alarmWithoutDefaultTargetSubscription, alarm2)); reset(seyrenRepository); when(seyrenRepository.getAllAlarms()).thenReturn(alarms); Collection<Alarm> resultAlarms = alarmService.searchAlarmsBySubscriptionTarget(TestUtils.DEFAULT_EMAIL); assertThat(resultAlarms).containsOnly(alarm1, alarm2); }