TherapyWarningsProvider { Comparator<MedicationsWarningDto> getMedicationsWarningDtoComparator() { return Comparator .comparing((MedicationsWarningDto w) -> w.getType() != WarningType.UNMATCHED) .thenComparing(MedicationsWarningDto::getSeverity, Comparator.nullsLast(Comparator.naturalOrder())) .thenComparing(MedicationsWarningDto::getType); }  @Required void setMedicationsDao(final MedicationsDao medicationsDao); @Required void setMedicationsExternalService(final MedicationsExternalService medicationsExternalService); @Required void setMentalHealthWarningsHandler(final MentalHealthWarningsHandler mentalHealthWarningsHandler); MedicationWarningsDto findMedicationWarnings(
      final String patientId,
      final long patientAgeInDays,
      final Double patientWeightInKg,
      final Double bsaInM2,
      final boolean isFemale,
      final List<ExternalCatalogDto> patientDiseasesList,
      final List<NamedExternalDto> patientAllergiesList,
      final List<MedicationForWarningsSearchDto> medicationSummaries,
      final Set<WarningSeverity> severityFilterValues,
      final boolean loadCustomWarnings,
      final DateTime when);  }
@Test public void compareSameMedicationsWarnings() { final Comparator<MedicationsWarningDto> comparator = therapyWarningsProvider.getMedicationsWarningDtoComparator(); final MedicationsWarningDto o1 = getMedicationsWarningDto(WarningType.ALLERGY, WarningSeverity.SIGNIFICANT); final MedicationsWarningDto o2 = getMedicationsWarningDto(WarningType.ALLERGY, WarningSeverity.SIGNIFICANT); final int compare = Objects.compare(o1, o2, comparator); assertEquals(0, compare); }
@Test public void compareUnmatchedWithOtherWarningType() { final Comparator<MedicationsWarningDto> comparator = therapyWarningsProvider.getMedicationsWarningDtoComparator(); final MedicationsWarningDto o1 = getMedicationsWarningDto(WarningType.UNMATCHED, null); final MedicationsWarningDto o2 = getMedicationsWarningDto(WarningType.ALLERGY, WarningSeverity.SIGNIFICANT); final int compare = Objects.compare(o1, o2, comparator); final int reverseCompare = Objects.compare(o2, o1, comparator); assertTrue(compare < 0); assertEquals(0, compare + reverseCompare); }
@Test public void compareSameSeverityDifferentWarningType() { final Comparator<MedicationsWarningDto> comparator = therapyWarningsProvider.getMedicationsWarningDtoComparator(); final MedicationsWarningDto o1 = getMedicationsWarningDto(WarningType.DUPLICATE, WarningSeverity.SIGNIFICANT); final MedicationsWarningDto o2 = getMedicationsWarningDto(WarningType.ALLERGY, WarningSeverity.SIGNIFICANT); final int compare = Objects.compare(o1, o2, comparator); final int reverseCompare = Objects.compare(o2, o1, comparator); assertTrue(compare > 0); assertEquals(0, compare + reverseCompare); }
@Test public void compareSameWarningTypeDifferentSeverity() { final Comparator<MedicationsWarningDto> comparator = therapyWarningsProvider.getMedicationsWarningDtoComparator(); final MedicationsWarningDto o1 = getMedicationsWarningDto(WarningType.DUPLICATE, WarningSeverity.LOW); final MedicationsWarningDto o2 = getMedicationsWarningDto(WarningType.DUPLICATE, WarningSeverity.SIGNIFICANT); final int compare = Objects.compare(o1, o2, comparator); final int reverseCompare = Objects.compare(o2, o1, comparator); assertTrue(compare > 0); assertEquals(0, compare + reverseCompare); }
@Test public void compareSameWarningTypeDifferentSeverity2() { final Comparator<MedicationsWarningDto> comparator = therapyWarningsProvider.getMedicationsWarningDtoComparator(); final MedicationsWarningDto o1 = getMedicationsWarningDto(WarningType.DUPLICATE, WarningSeverity.LOW); final MedicationsWarningDto o2 = getMedicationsWarningDto(WarningType.DUPLICATE, WarningSeverity.HIGH); final int compare = Objects.compare(o1, o2, comparator); final int reverseCompare = Objects.compare(o2, o1, comparator); assertTrue(compare > 0); assertEquals(0, compare + reverseCompare); }