Skip to content

Commit

Permalink
Updating more unit tests and explicitly dealing with null other argum…
Browse files Browse the repository at this point in the history
…ents for comparable
  • Loading branch information
littleclay committed Oct 8, 2016
1 parent 74f0497 commit 5165efc
Show file tree
Hide file tree
Showing 34 changed files with 1,211 additions and 568 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<groupId>com.redfin</groupId>
<artifactId>validity</artifactId>
<version>1.0-SNAPSHOT</version>
<version>0.2.0-beta</version>
<modelVersion>4.0.0</modelVersion>
<packaging>jar</packaging>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,19 @@ public T isNotEqualTo(T other) throws X {

/**
* Tests for equality using the {@link Comparable#compareTo(Object)} method. If the
* subject is not null and the compareTo method returns 0, then the values are considered
* to be equal.
* subject is not null, if other is not null, and the compareTo method returns 0,
* then the values are considered to be equal.
*
* @param other the object to compare the subject against.
* May not be null.
* @return the subject if it is comparable to other.
* @throws X if the subject is null or not comparable to other.
* @throws X if the subject is null or not comparable to other.
* @throws NullPointerException if other is null.
*/
public T isComparableTo(T other) throws X {
if (null == other) {
throw new NullPointerException(ValidityUtils.nullArgumentMessage("other"));
}
T subject = getSubject();
if (null == subject || subject.compareTo(other) != 0) {
fail("t -> t == " + ValidityUtils.describe(other));
Expand All @@ -91,14 +96,19 @@ public T isComparableTo(T other) throws X {

/**
* Tests for equality using the {@link Comparable#compareTo(Object)} method. If the
* subject is not null and the compareTo method returns 0, then the values are considered
* to be equal.
* subject is not null, if other is not null, and the compareTo method returns 0,
* then the values are considered to be equal.
*
* @param other the object to compare the subject against.
* May not be null.
* @return the subject if it is not comparable to other.
* @throws X if the subject is null or is comparable to other.
* @throws X if the subject is null or is comparable to other.
* @throws NullPointerException if other is null.
*/
public T isNotComparableTo(T other) throws X {
if (null == other) {
throw new NullPointerException(ValidityUtils.nullArgumentMessage("other"));
}
T subject = getSubject();
if (null == subject || subject.compareTo(other) == 0) {
fail("t -> t.compareTo(" + ValidityUtils.describe(other) + ") != 0");
Expand All @@ -108,10 +118,15 @@ public T isNotComparableTo(T other) throws X {

/**
* @param other the object to compare the subject against.
* May not be null.
* @return the subject if it is greater than other.
* @throws X if the subject is null or not greater than other.
* @throws X if the subject is null or not greater than other.
* @throws NullPointerException if other is null.
*/
public T isGreaterThan(T other) throws X {
if (null == other) {
throw new NullPointerException(ValidityUtils.nullArgumentMessage("other"));
}
T subject = getSubject();
if (null == subject || subject.compareTo(other) <= 0) {
fail("t -> t > " + ValidityUtils.describe(other));
Expand All @@ -121,10 +136,15 @@ public T isGreaterThan(T other) throws X {

/**
* @param other the object to compare the subject against.
* May not be null.
* @return the subject if it is greater than or equal to other.
* @throws X if the subject is null or is not greater than or equal to other.
* @throws X if the subject is null or is not greater than or equal to other.
* @throws NullPointerException if other is null.
*/
public T isGreaterThanOrEqualTo(T other) throws X {
if (null == other) {
throw new NullPointerException(ValidityUtils.nullArgumentMessage("other"));
}
T subject = getSubject();
if (null == subject || subject.compareTo(other) < 0) {
fail("t -> t >= " + ValidityUtils.describe(other));
Expand All @@ -134,19 +154,26 @@ public T isGreaterThanOrEqualTo(T other) throws X {

/**
* @param other the object to compare the subject against.
* May not be null.
* @return the subject if it is greater than or equal to other.
* @throws X if the subject is null or is not greater than or equal to other.
* @throws X if the subject is null or is not greater than or equal to other.
* @throws NullPointerException if other is null.
*/
public T isAtLeast(T other) throws X {
return isGreaterThanOrEqualTo(other);
}

/**
* @param other the object to compare the subject against.
* May not be null.
* @return the subject if it is less than other.
* @throws X if the subject is null or is not less than other.
* @throws X if the subject is null or is not less than other.
* @throws NullPointerException if other is null.
*/
public T isLessThan(T other) throws X {
if (null == other) {
throw new NullPointerException(ValidityUtils.nullArgumentMessage("other"));
}
T subject = getSubject();
if (null == subject || subject.compareTo(other) >= 0) {
fail("t -> t < " + ValidityUtils.describe(other));
Expand All @@ -156,10 +183,15 @@ public T isLessThan(T other) throws X {

/**
* @param other the object to compare the subject against.
* May not be null.
* @return the subject if it is less than or equal to other.
* @throws X if the subject is null or is not less than or equal to to other.
* @throws X if the subject is null or is not less than or equal to to other.
* @throws NullPointerException if other is null.
*/
public T isLessThanOrEqualTo(T other) throws X {
if (null == other) {
throw new NullPointerException(ValidityUtils.nullArgumentMessage("other"));
}
T subject = getSubject();
if (null == subject || subject.compareTo(other) > 0) {
fail("t -> t <= " + ValidityUtils.describe(other));
Expand All @@ -169,8 +201,10 @@ public T isLessThanOrEqualTo(T other) throws X {

/**
* @param other the object to compare the subject against.
* May not be null.
* @return the subject if it is less than or equal to other.
* @throws X if the subject is null or is not less than or equal to other.
* @throws X if the subject is null or is not less than or equal to other.
* @throws NullPointerException if other is null.
*/
public T isAtMost(T other) throws X {
return isLessThanOrEqualTo(other);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@ public T isNotEqualTo(T other) throws X {
}

/**
* Tests the subject with the given predicate. Note that any {@link Throwable} thrown
* during the testing of the predicate is not handled and will be thrown instead
* of the usual throwable for this verifiable instance.
*
* @param expected the {@link Predicate} to use to test the subject.
* May not be null.
* @return the subject if it satisfies the predicate.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,10 @@ public byte isAtMost(byte other) throws X {
}

/**
* Tests the subject with the given predicate. Note that any {@link Throwable} thrown
* during the testing of the predicate is not handled and will be thrown instead
* of the usual throwable for this verifiable instance.
*
* @param expected the {@link IntPredicate} to use to test the subject.
* May not be null.
* @return the subject if it satisfies the predicate.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,10 @@ public char isDigit() throws X {
}

/**
* Tests the subject with the given predicate. Note that any {@link Throwable} thrown
* during the testing of the predicate is not handled and will be thrown instead
* of the usual throwable for this verifiable instance.
*
* @param expected the {@link IntPredicate} to use to test the subject.
* May not be null.
* @return the subject if it satisfies the predicate.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,10 @@ public double isAtMost(double other) throws X {
}

/**
* Tests the subject with the given predicate. Note that any {@link Throwable} thrown
* during the testing of the predicate is not handled and will be thrown instead
* of the usual throwable for this verifiable instance.
*
* @param expected the {@link DoublePredicate} to use to test the subject.
* May not be null.
* @return the subject if it satisfies the predicate.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,10 @@ public float isAtMost(float other) throws X {
}

/**
* Tests the subject with the given predicate. Note that any {@link Throwable} thrown
* during the testing of the predicate is not handled and will be thrown instead
* of the usual throwable for this verifiable instance.
*
* @param expected the {@link DoublePredicate} to use to test the subject.
* May not be null.
* @return the subject if it satisfies the predicate.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,10 @@ public int isAtMost(int other) throws X {
}

/**
* Tests the subject with the given predicate. Note that any {@link Throwable} thrown
* during the testing of the predicate is not handled and will be thrown instead
* of the usual throwable for this verifiable instance.
*
* @param expected the {@link IntPredicate} to use to test the subject.
* May not be null.
* @return the subject if it satisfies the predicate.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,10 @@ public long isAtMost(long other) throws X {
}

/**
* Tests the subject with the given predicate. Note that any {@link Throwable} thrown
* during the testing of the predicate is not handled and will be thrown instead
* of the usual throwable for this verifiable instance.
*
* @param expected the {@link LongPredicate} to use to test the subject.
* May not be null.
* @return the subject if it satisfies the predicate.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,10 @@ public short isAtMost(short other) throws X {
}

/**
* Tests the subject with the given predicate. Note that any {@link Throwable} thrown
* during the testing of the predicate is not handled and will be thrown instead
* of the usual throwable for this verifiable instance.
*
* @param expected the {@link IntPredicate} to use to test the subject.
* May not be null.
* @return the subject if it satisfies the predicate.
Expand Down
Loading

0 comments on commit 5165efc

Please sign in to comment.