ConfigConverters { public static ConfigConverter<Duration> ofDuration() { return new SimpleConfigConverter<Duration>() { @Override protected Duration fromString(String string) { return StringFormatUtils.parseDuration(string); } @Override protected String toString(Duration value) { return StringFormatUtils.formatDuration(value); } }; }  static ConfigConverter<LocalDate> ofLocalDate(); static ConfigConverter<LocalTime> ofLocalTime(); static ConfigConverter<LocalDateTime> ofLocalDateTime(); static ConfigConverter<Period> ofPeriod(); static ConfigConverter<Integer> ofPeriodAsDays(); static ConfigConverter<Duration> ofDuration(); static ConfigConverter<Long> ofDurationAsMillis(); static ConfigConverter<Instant> ofInstant(); static ConfigConverter<Long> ofInstantAsEpochMillis(); static ConfigConverter<String> ofString(); static ConfigConverter<String> ofNullableString(); static ConfigConverter<Byte> ofByte(); static ConfigConverter<Integer> ofInteger(); static ConfigConverter<Long> ofLong(); static ConfigConverter<Float> ofFloat(); static ConfigConverter<Double> ofDouble(); static ConfigConverter<Boolean> ofBoolean(); static SimpleConfigConverter<E> ofEnum(Class<E> enumClass); static ConfigConverter<Class<?>> ofClass(); static ConfigConverter<InetAddress> ofInetAddress(); static ConfigConverter<InetSocketAddress> ofInetSocketAddress(); static ConfigConverter<Path> ofPath(); static ConfigConverter<MemSize> ofMemSize(); static ConfigConverter<Long> ofMemSizeAsLong(); static ConfigConverter<Integer> ofMemSizeAsInt(); static ConfigConverter<List<T>> ofList(ConfigConverter<T> elementConverter, CharSequence separators); static ConfigConverter<List<T>> ofList(ConfigConverter<T> elementConverter); static ConfigConverter<ServerSocketSettings> ofServerSocketSettings(); static ConfigConverter<SocketSettings> ofSocketSettings(); static ConfigConverter<DatagramSocketSettings> ofDatagramSocketSettings(); static ConfigConverter<FatalErrorHandler> ofFatalErrorHandler(); static ConfigConverter<Schedule> ofEventloopTaskSchedule(); static ConfigConverter<RetryPolicy> ofRetryPolicy(); static ConfigConverter<ThrottlingController> ofThrottlingController(); static ConfigConverter<SimpleThreadFactory> ofThreadFactory(); static ExecutorService getExecutor(Config config); static ConfigConverter<ExecutorService> ofExecutor(); static UnaryOperator<T> apply(BiFunction<T, ? super V, T> modifier, V value); static UnaryOperator<T> applyIf(BiFunction<T, ? super V, T> modifier, V value, Predicate<? super V> predicate); static UnaryOperator<T> applyIfNotNull(BiFunction<T, ? super V, T> modifier, V value); static final ConfigConverter<List<Class<?>>> OF_CLASSES; }
@Test public void testDuration() { Duration expected = Duration.ofDays(-2).plusHours(2).plusMinutes(8).plusSeconds(-3).plusMillis(-322).plusNanos(228); assertEquals(expected, Config.EMPTY.get(ofDuration(), THIS, expected)); assertEquals("-1 days -21 hours -52 minutes -4 seconds 678 millis 228 nanos", Config.ofValue(ofDuration(), expected).getValue()); assertEquals("0 seconds", Config.ofValue(ofDuration(), Duration.ZERO).getValue()); assertEquals(Duration.ZERO, Config.ofValue(ofDuration(), Duration.ZERO).get(ofDuration(), THIS)); assertEquals(expected, Config.ofValue("2 hour -2 days 8 minutes 228 nanos -3 second -322 millis").get(ofDuration(), THIS)); assertEquals(Duration.ofDays(2).plusHours(14).plusMinutes(1).plusSeconds(30), Config.ofValue("2.5 days 2 hour 1.5 minute").get(ofDuration(), THIS)); assertEquals(Duration.ofHours(12).plusMinutes(40).plusSeconds(1).plusMillis(500), Config.ofValue("12.5 hours 10 minutes 1.5 second").get(ofDuration(), THIS)); assertEquals(Duration.ofHours(2).plusSeconds(36), Config.ofValue("2.01 hours").get(ofDuration(), THIS)); assertEquals(Duration.ofDays(2).plusMinutes(1).plusSeconds(26).plusMillis(400), Config.ofValue("2.001 days").get(ofDuration(), THIS)); try { Config.ofValue(" 1 2 3 ").get(ofDuration(), THIS); Assert.fail(); } catch (IllegalArgumentException ignored) { } try { Config.ofValue("1 days2 hours").get(ofDuration(), THIS); Assert.fail(); } catch (IllegalArgumentException ignored) { } try { Config.ofValue("1 day 2 hours 2 hours").get(ofDuration(), THIS); Assert.fail(); } catch (IllegalArgumentException ignored) { } try { Config.ofValue("2.2 nanos").get(ofDuration(), THIS); Assert.fail(); } catch (IllegalArgumentException ignored) { } }