Using Validate where possible in builder package.

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@1593622 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Duncan Jones 2014-05-09 21:13:01 +00:00
parent 3728344459
commit 10641f9ae7
2 changed files with 10 additions and 8 deletions

View File

@ -25,6 +25,7 @@
import java.util.Set;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.Validate;
/**
* <p>
@ -536,12 +537,8 @@ public HashCodeBuilder() {
* if the number is even
*/
public HashCodeBuilder(final int initialOddNumber, final int multiplierOddNumber) {
if (initialOddNumber % 2 == 0) {
throw new IllegalArgumentException("HashCodeBuilder requires an odd initial value");
}
if (multiplierOddNumber % 2 == 0) {
throw new IllegalArgumentException("HashCodeBuilder requires an odd multiplier");
}
Validate.isTrue(initialOddNumber % 2 != 0, "HashCodeBuilder requires an odd initial value");
Validate.isTrue(multiplierOddNumber % 2 != 0, "HashCodeBuilder requires an odd multiplier");
iConstant = multiplierOddNumber;
iTotal = initialOddNumber;
}

View File

@ -60,8 +60,13 @@ public void testConstructorExZero() {
}
@Test(expected=IllegalArgumentException.class)
public void testConstructorExEven() {
new HashCodeBuilder(2, 2);
public void testConstructorExEvenFirst() {
new HashCodeBuilder(2, 3);
}
@Test(expected=IllegalArgumentException.class)
public void testConstructorExEvenSecond() {
new HashCodeBuilder(3, 2);
}
@Test(expected=IllegalArgumentException.class)