Limit { public static Limit of(int value) { Preconditions.checkArgument(value >= 0, "A limit need to be positive"); return new Limit(Optional.of(value)); } private  Limit(Optional<Integer> value); static Limit of(int value); static Limit unlimited(); Optional<Integer> getValue(); boolean isLimited(); @Override final boolean equals(Object o); @Override final int hashCode(); @Override String toString();  }
@Test void ofShouldThrowOnNegativeValue() { assertThatThrownBy(() -> Limit.of(-1)) .isInstanceOf(IllegalArgumentException.class); }