NetworkSettings { public void setTimeout(Duration timeout) { if (timeout == null || timeout.isNegative() || timeout.isZero()) { throw new IllegalArgumentException("Timeout must be positive"); } if (timeout.toMillis() > Integer.MAX_VALUE) { throw new IllegalArgumentException("Timeout is out of range"); } this.timeout = timeout; }  Proxy getProxy(); void setProxy(@Nullable Proxy proxy); Duration getTimeout(); void setTimeout(Duration timeout);  }
@Test public void testInvalidTimeouts() { NetworkSettings settings = new NetworkSettings(); try { settings.setTimeout(null); fail("timeout accepted null"); } catch (IllegalArgumentException ex) { } try { settings.setTimeout(Duration.ZERO); fail("timeout accepted zero duration"); } catch (IllegalArgumentException ex) { } try { settings.setTimeout(Duration.ofSeconds(20).negated()); fail("timeout accepted negative duration"); } catch (IllegalArgumentException ex) { } try { settings.setTimeout(Duration.ofMillis(Integer.MAX_VALUE + 1L)); fail("timeout accepted out of range value"); } catch (IllegalArgumentException ex) { } }