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

View File

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