Utils { public static String durationTranslator(String sonarDuration) { String daysPart = "P" + (sonarDuration.contains("d") ? sonarDuration.substring(0, sonarDuration.indexOf('d')) + "D" : ""); String timePart = (sonarDuration.contains("d") ? sonarDuration.substring(sonarDuration.indexOf('d') + 1) : sonarDuration); return daysPart + (timePart.isEmpty() ? "" : "T" + timePart.replaceAll("min", "M").replaceAll("h", "H")); } private  Utils(); static String durationTranslator(String sonarDuration);  }
@Test public void testDateWithDaysWorks() { String input = "1d2h50min"; assertEquals("P1DT2H50M", Utils.durationTranslator(input)); }
@Test public void testDateWithoutDaysWorks() { String input = "2h50min"; assertEquals("PT2H50M", Utils.durationTranslator(input)); }
@Test public void testDateOnlyWithMin() { String input = "50min"; assertEquals("PT50M", Utils.durationTranslator(input)); }
@Test public void testDateOnlyWithHours() { String input = "3h"; assertEquals("PT3H", Utils.durationTranslator(input)); }
@Test public void testDateOnlyWithDays() { String input = "3d"; assertEquals("P3D", Utils.durationTranslator(input)); }