TherapyDisplayProvider { String getTherapyDurationDisplay(final TherapyDto therapy, final Locale locale) { if (therapy.getStart() == null || therapy.getEnd() == null || (therapy.getDosingFrequency() != null && therapy.getDosingFrequency().getType() == DosingFrequencyTypeEnum.ONCE_THEN_EX)) { return ""; } final StringBuilder therapyDisplay = new StringBuilder(); therapyDisplay.append("<span class='TherapyDuration'>"); therapyDisplay.append(addLineBreak()); final String whiteSpace = " "; final Duration therapyDuration = new Duration(therapy.getEnd().getMillis() - therapy.getStart().getMillis()); final PeriodFormatter therapyDurationFormatter = new PeriodFormatterBuilder() .appendWeeks() .appendSuffix(whiteSpace + Dictionary.getEntry("week.lc", locale), whiteSpace + Dictionary.getEntry("weeks", locale)) .appendSeparator(", ") .appendDays() .appendSuffix(whiteSpace + Dictionary.getEntry("day.lc", locale), whiteSpace + Dictionary.getEntry("days", locale)) .appendSeparator(", ") .appendHours() .appendSuffix(whiteSpace + Dictionary.getEntry("hour.lc", locale), whiteSpace + Dictionary.getEntry("hours.accusative", locale)) .appendSeparator(", ") .appendMinutes() .appendSuffix(whiteSpace + Dictionary.getEntry("minute.short.lc", locale)) .appendSeparator(", ") .toFormatter(); final String formattedTherapyDuration = therapyDurationFormatter.print(therapyDuration.toPeriod().normalizedStandard()); therapyDisplay.append( createSpannedValue( Dictionary.getEntry("duration", locale), "DurationLabel TextLabel MedicationLabel", true)); therapyDisplay.append( createSpannedValue( formattedTherapyDuration, "Duration TextData", true)); therapyDisplay.append("</span>"); return therapyDisplay.toString(); }  void fillDisplayValues(
      final TherapyDto therapy,
      final boolean showLongFormattedDescription,
      final boolean showTherapyInterval,
      final Locale locale); void fillDisplayValues(
      final TherapyDto therapy,
      final boolean showLongFormattedDescription,
      final boolean showTherapyInterval,
      final boolean showTherapyDuration,
      final Locale locale,
      final boolean showCommentOnShortFormat); String getFormattedDecimalValue(final String decimalValue, final Locale locale, final boolean bold); String getMedicationDisplay(final MedicationSimpleDto medication); String getRateDisplayString(final Double rate, final String rateUnit, final Locale locale); String getDecimalStringValue(final Double value, final Locale locale);  }
@Test public void testGetTherapyDurationDisplay() { final Locale locale = new Locale("sl"); ConstantSimpleTherapyDto therapy = new ConstantSimpleTherapyDto(); therapy.setStart(new DateTime(2016, 12, 10, 8, 0)); therapy.setEnd(new DateTime(2016, 12, 15, 16, 0)); assertEquals("<span class='TherapyDuration'><br>" + "<span class='DurationLabel TextLabel MedicationLabel'>Trajanje </span>" + "<span class='Duration TextData'>5 dni, 8 ur </span></span>", therapyDisplayProvider.getTherapyDurationDisplay(therapy, locale)); therapy.setEnd(new DateTime(2016, 12, 11, 9, 1)); assertEquals("<span class='TherapyDuration'><br>" + "<span class='DurationLabel TextLabel MedicationLabel'>Trajanje </span>" + "<span class='Duration TextData'>1 dan, 1 ura, 1 min </span></span>", therapyDisplayProvider.getTherapyDurationDisplay(therapy, locale)); therapy.setEnd(new DateTime(2016, 12, 10, 10, 15)); assertEquals("<span class='TherapyDuration'><br>" + "<span class='DurationLabel TextLabel MedicationLabel'>Trajanje </span>" + "<span class='Duration TextData'>2 ur, 15 min </span></span>", therapyDisplayProvider.getTherapyDurationDisplay(therapy, locale)); therapy.setEnd(new DateTime(2016, 12, 10, 8, 15)); assertEquals("<span class='TherapyDuration'><br>" + "<span class='DurationLabel TextLabel MedicationLabel'>Trajanje </span>" + "<span class='Duration TextData'>15 min </span></span>", therapyDisplayProvider.getTherapyDurationDisplay(therapy, locale)); therapy.setEnd(new DateTime(2016, 12, 25, 6, 0)); assertEquals("<span class='TherapyDuration'><br>" + "<span class='DurationLabel TextLabel MedicationLabel'>Trajanje </span>" + "<span class='Duration TextData'>2 tednov, 22 ur </span></span>", therapyDisplayProvider.getTherapyDurationDisplay(therapy, locale)); therapy.setEnd(new DateTime(2016, 12, 11, 8, 0)); assertEquals("<span class='TherapyDuration'><br>" + "<span class='DurationLabel TextLabel MedicationLabel'>Trajanje </span>" + "<span class='Duration TextData'>1 dan </span></span>", therapyDisplayProvider.getTherapyDurationDisplay(therapy, locale)); }