Skip to content

Commit

Permalink
Merge pull request #23 from TNG/issue_19_consistent_API_min_max_2
Browse files Browse the repository at this point in the history
Issue 19 consistent api min max 2
  • Loading branch information
stefanhechtltng authored Jul 18, 2022
2 parents e35d0ab + efd3e00 commit acd5ad4
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ public String numericString(int length) {
* @param min the lower limit (inclusive) of the generated number (as String).
* @param max the upper limit (inclusive) of the generated number (as String).
* @return the generated String.
* @throws IllegalArgumentException if {@code min} > {@code max}.
* @throws IllegalArgumentException if {@code min} > {@code max}.
* @throws IllegalArgumentException if {@code min} <= 0.
* @throws IllegalArgumentException if the requested length of the String is smaller than the number of digits of {@code min}.
* @see #numericString(int)
Expand Down Expand Up @@ -359,8 +359,7 @@ public int positiveIntNumber() {
* @param min the minimum value of the returned number.
* @param max the maximum value of the returned number.
* @return the generated number.
* @throws IllegalArgumentException if {@code min} > {@code max}.
* @see #positiveIntNumber()
* @throws IllegalArgumentException if {@code min} > {@code max}.
*/
public int intNumber(int min, int max) {
return (int) longNumber(min, max);
Expand Down Expand Up @@ -397,7 +396,7 @@ public long positiveLongNumber() {
* @param min the minimum value of the returned number.
* @param max the maximum value of the returned number.
* @return the generated number.
* @throws IllegalArgumentException if {@code min} > {@code max}.
* @throws IllegalArgumentException if {@code min} > {@code max}.
* @see #positiveLongNumber()
*/
public long longNumber(long min, long max) {
Expand Down Expand Up @@ -434,7 +433,7 @@ public BigInteger positiveBigIntegerNumber() {
* @param min the minimum value of the returned number.
* @param max the maximum value of the returned number.
* @return the generated number.
* @throws IllegalArgumentException if {@code min} > {@code max}.
* @throws IllegalArgumentException if {@code min} > {@code max}.
* @see #positiveBigIntegerNumber()
*/
public BigInteger bigIntegerNumber(BigInteger min, BigInteger max) {
Expand Down Expand Up @@ -471,7 +470,7 @@ public BigDecimal positiveBigDecimalNumber() {
* @param min the minimum value of the returned number.
* @param max the maximum value of the returned number.
* @return the generated number.
* @throws IllegalArgumentException if {@code min} > {@code max}.
* @throws IllegalArgumentException if {@code min} > {@code max}.
* @see #positiveBigDecimalNumber()
*/
public BigDecimal bigDecimalNumber(Number min, Number max) {
Expand All @@ -491,7 +490,7 @@ public BigDecimal bigDecimalNumber(Number min, Number max) {
* @param min the minimum value of the returned number.
* @param max the maximum value of the returned number.
* @return the generated number.
* @throws IllegalArgumentException if {@code min} > {@code max}.
* @throws IllegalArgumentException if {@code min} > {@code max}.
* @see #positiveBigDecimalNumber()
*/
public BigDecimal bigDecimalNumber(BigDecimal min, BigDecimal max) {
Expand Down Expand Up @@ -525,7 +524,7 @@ private BigInteger randomBigIntegerNumber(BigInteger min, BigInteger max) {
* @param max the maximum value of the returned number.
* @param scale the scale to be set on the BigDecimal.
* @return the generated number.
* @throws IllegalArgumentException if {@code min} > {@code max}.
* @throws IllegalArgumentException if {@code min} > {@code max}.
*/
public BigDecimal bigDecimalNumberWithScale(Number min, Number max, int scale) {
BigDecimal result = bigDecimalNumber(min, max);
Expand All @@ -550,7 +549,7 @@ public BigDecimal bigDecimalNumberWithScale(Number min, Number max, int scale) {
* @param max the maximum value of the returned number.
* @param scale the scale to be set on the BigDecimal.
* @return the generated number.
* @throws IllegalArgumentException if {@code min} > {@code max}.
* @throws IllegalArgumentException if {@code min} > {@code max}.
*/
public BigDecimal bigDecimalNumberWithScale(BigDecimal min, BigDecimal max, int scale) {
BigDecimal result = bigDecimalNumber(min, max);
Expand Down Expand Up @@ -742,7 +741,8 @@ public <T extends Enum<T>> Set<T> someOf(Class<T> enumClass, int numberOfElement
* @param elements the elements to draw from.
* @return the drawn elements (none / some / all).
*/
@SafeVarargs final public <T> Collection<T> someOf(T... elements) {
@SafeVarargs
public final <T> Collection<T> someOf(T... elements) {
return someOf(asList(elements));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -326,8 +326,14 @@ private void assertBigIntegerNumber(ValueProvider provider, BigInteger min, BigI
}

@Test
void bigIntegerNumber_should_thrown_an_exception_if_min_is_greater_than_max() {
assertThrows(IllegalArgumentException.class, () -> withRandomValues().bigIntegerNumber(BigInteger.valueOf(-1), BigInteger.valueOf(-2)));
void bigIntegerNumber_should_throw_an_exception_if_min_is_greater_than_max() {
ValueProvider random = withRandomValues();
BigInteger max = BigInteger.valueOf(-2);
BigInteger minGreaterThanMax = BigInteger.valueOf(-1);

assertThatThrownBy(() -> random.bigIntegerNumber(minGreaterThanMax, max))
.isInstanceOf(IllegalArgumentException.class)
.hasMessageContainingAll("" + minGreaterThanMax, "" + max);
}

@SuppressWarnings("unchecked")
Expand Down Expand Up @@ -437,8 +443,14 @@ private void assertBigDecimalNumber(ValueProvider provider, double min, double m
}

@Test
void bigDecimalNumber_should_thrown_an_exception_if_min_is_greater_than_max() {
assertThrows(IllegalArgumentException.class, () -> withRandomValues().bigDecimalNumber(-1.000, -1.001));
void bigDecimalNumber_should_throw_an_exception_if_min_is_greater_than_max() {
ValueProvider random = withRandomValues();
Number max = 1.000;
Number minGreaterThanMax = 1.001;

assertThatThrownBy(() -> random.bigDecimalNumber(minGreaterThanMax, max))
.isInstanceOf(IllegalArgumentException.class)
.hasMessageContainingAll("" + minGreaterThanMax, "" + max);
}

@Test
Expand Down

0 comments on commit acd5ad4

Please sign in to comment.