### Question:
Duration { public static Duration createWithSuitableUnit(long sourceDuration, TimeUnit sourceUnit) { long durationMillis = Math.abs(TimeUnit.MILLISECONDS.convert(sourceDuration, sourceUnit)); TimeUnit targetUnit; if (durationMillis > 1000L * 60L * 60L * 24L) { targetUnit = TimeUnit.DAYS; } else if (durationMillis > 1000L * 60L * 60L) { targetUnit = TimeUnit.HOURS; } else if (durationMillis > 1000L * 60L) { targetUnit = TimeUnit.MINUTES; } else { targetUnit = TimeUnit.SECONDS; } long durationInTargetUnit = targetUnit.convert(sourceDuration, sourceUnit); return new Duration(durationInTargetUnit, targetUnit); } Duration(long duration, TimeUnit unit); static Duration createWithSuitableUnit(long sourceDuration, TimeUnit sourceUnit); long getDuration(); TimeUnit getTimeUnit();  }### Answer:
@Test public void shouldConvertToAppropriateTimeUnit() { check(Duration.createWithSuitableUnit(0, TimeUnit.HOURS), 0, TimeUnit.SECONDS); check(Duration.createWithSuitableUnit(124, TimeUnit.MINUTES), 2, TimeUnit.HOURS); check(Duration.createWithSuitableUnit(300, TimeUnit.HOURS), 12, TimeUnit.DAYS); check(Duration.createWithSuitableUnit(60 * 24 * 50 + 8, TimeUnit.MINUTES), 50, TimeUnit.DAYS); check(Duration.createWithSuitableUnit(1000L * 60 * 60 * 24 * 7 + 3000, TimeUnit.MILLISECONDS), 7, TimeUnit.DAYS); check(Duration.createWithSuitableUnit(1000L * 60 * 60 * 3 + 1400, TimeUnit.MILLISECONDS), 3, TimeUnit.HOURS); check(Duration.createWithSuitableUnit(248, TimeUnit.SECONDS), 4, TimeUnit.MINUTES); }