BandwidthLimit { public static BandwidthLimit of(long limit, long overdraftLimit, long initialSize, Duration period) { return new BandwidthLimit(limit, overdraftLimit, initialSize, period); } BandwidthLimit(long limit, long overdraftLimit, long initialSize, Duration period); static BandwidthLimit of(long limit, long overdraftLimit, long initialSize, Duration period); static BandwidthLimit of(long limit, long overdraftLimit, Duration period); static BandwidthLimit of(long limit, Duration period); static BandwidthLimit of(String specification); long limit(); long overdraftLimit(); long initialSize(); Duration period(); @Override String toString();  }
@Test void testInvalidConstructor() { assertThatThrownBy( () -> BandwidthLimit.of(0L, 1000L, 50L, Duration.ofSeconds(60L))) .isInstanceOf(IllegalArgumentException.class) .hasMessageContaining("limit: 0 (expected: > 0)"); assertThatThrownBy( () -> BandwidthLimit.of(100L, 99L, 50L, Duration.ofSeconds(60L))) .isInstanceOf(IllegalArgumentException.class) .hasMessageContaining("overdraftLimit: 99 (expected: > 100)"); assertThatThrownBy( () -> BandwidthLimit.of(100L, 1000L, 50L, Duration.ofSeconds(0L))) .isInstanceOf(IllegalArgumentException.class) .hasMessageContaining("period: PT0S (expected: > PT0S)"); }
@Test void testInvalidSpecification() { assertThatThrownBy( () -> BandwidthLimit.of( "1000000000000000000000000000000000000000000000000000000000000000000;window=60")) .isInstanceOf(NumberFormatException.class) .hasMessageContaining( "For input string: \"1000000000000000000000000000000000000000000000000000000000000000000\""); assertThatThrownBy( () -> BandwidthLimit.of("abcd;window=60")) .isInstanceOf(NumberFormatException.class) .hasMessageContaining("For input string: \"abcd\""); assertThatThrownBy( () -> BandwidthLimit.of("100;window=defg")) .isInstanceOf(NumberFormatException.class) .hasMessageContaining("For input string: \"defg\""); assertThatThrownBy( () -> BandwidthLimit.of("100;")) .isInstanceOf(IllegalArgumentException.class) .hasMessageContaining("Invalid format of \"100;\" - period not found"); assertThatThrownBy( () -> BandwidthLimit.of(";window=60;burst=1000;initial=50")) .isInstanceOf(IllegalArgumentException.class) .hasMessageContaining( "Invalid format of \";window=60;burst=1000;initial=50\" - limit not found"); assertThatThrownBy( () -> BandwidthLimit.of("100")) .isInstanceOf(IllegalArgumentException.class) .hasMessageContaining("Invalid format of \"100\" - period not found"); assertThatThrownBy( () -> BandwidthLimit.of("")) .isInstanceOf(IllegalArgumentException.class) .hasMessageContaining("Empty bandwidth limit specification"); assertThatThrownBy( () -> BandwidthLimit.of(null)) .isInstanceOf(NullPointerException.class) .hasMessageContaining("specification"); }