Commit ac9f00cc authored by Rajiv Prabhakar's avatar Rajiv Prabhakar
Browse files

v1.7.0 release:

- Validatec.isFalse added
- Misc Validatec refactoring
- gitlab CI config updated
parent 71581a14
Pipeline #9586452 failed with stage
in 1 minute and 28 seconds
# https://stackoverflow.com/questions/33430487/how-to-use-gitlab-ci-to-build-a-java-maven-project
image: maven:3.5.0-jdk-8
job1:
script: "mvn clean install"
\ No newline at end of file
script: "mvn clean integration-test -DrunIT -B"
......@@ -9,7 +9,7 @@ Populate ~/.m2/settings.xml with:
<server>
<id>ossrh</id>
<username>{sonatype.org user-name}</username>
<password>{password}</password>
<password>{sonatype.org password}</password>
</server>
</servers>
</settings>
......
......@@ -6,7 +6,7 @@
<groupId>com.rajivprab</groupId>
<artifactId>cava</artifactId>
<version>1.6.0</version>
<version>1.7.0</version>
<name>Cava: Clean Java</name>
<description>A library that enables users to write minimal, clean and simple Java code</description>
......@@ -86,8 +86,6 @@
<dependency>
<groupId>com.google.truth</groupId>
<artifactId>truth</artifactId>
<!-- Using newer versions causes caucus unit tests to break with a "cannot-find-method" error!? -->
<!-- <version>0.30</version> -->
<version>0.33</version>
<scope>test</scope>
</dependency>
......
......@@ -25,10 +25,6 @@ public class Validatec {
isTrue(bool, "Found: " + bool);
}
public static void isTrue(boolean bool, RuntimeException e) {
isTrue(bool, () -> throwException(e));
}
public static void isTrue(boolean bool, String message) {
isTrue(bool, message, DEFAULT_EXCEPTION);
}
......@@ -37,12 +33,40 @@ public class Validatec {
isTrue(bool, () -> throwException(message, exceptionType));
}
public static void isTrue(boolean bool, RuntimeException e) {
isTrue(bool, () -> throwException(e));
}
public static void isTrue(boolean bool, Runnable runnable) {
if (!bool) {
runnable.run();
}
}
// ----------- Is false
public static void isFalse(boolean bool) {
isFalse(bool, "Found: " + bool);
}
public static void isFalse(boolean bool, String message) {
isFalse(bool, message, DEFAULT_EXCEPTION);
}
public static void isFalse(boolean bool, String message, Class<? extends RuntimeException> exceptionType) {
isFalse(bool, () -> throwException(message, exceptionType));
}
public static void isFalse(boolean bool, RuntimeException e) {
isFalse(bool, () -> throwException(e));
}
public static void isFalse(boolean bool, Runnable runnable) {
if (bool) {
runnable.run();
}
}
// ---------- Size
public static void size(Collection collection, int size) {
......@@ -159,129 +183,128 @@ public class Validatec {
return "String matches check failed. Expecting: " + regex + ", found: " + string;
}
// ---------- Less than - Numbers
// ---------- Less than
public static <T> void lessThan(Comparable<T> one, T two) {
lessThan(one, two, getLessThanMessage(one, two));
public static <T> void lessThan(Comparable<T> a, T b) {
lessThan(a, b, getLessThanMessage(a, b));
}
public static <T> void lessThan(Comparable<T> one, T two, RuntimeException e) {
lessThan(one, two, () -> throwException(e));
public static <T> void lessThan(Comparable<T> a, T b, RuntimeException e) {
lessThan(a, b, () -> throwException(e));
}
public static <T> void lessThan(Comparable<T> one, T two, String message) {
lessThan(one, two, message, DEFAULT_EXCEPTION);
public static <T> void lessThan(Comparable<T> a, T b, String message) {
lessThan(a, b, message, DEFAULT_EXCEPTION);
}
public static <T> void lessThan(Comparable<T> one, T two, String message, Class<? extends RuntimeException> exceptionType) {
lessThan(one, two, () -> throwException(message, exceptionType));
public static <T> void lessThan(Comparable<T> a, T b, String message, Class<? extends RuntimeException> exceptionType) {
lessThan(a, b, () -> throwException(message, exceptionType));
}
public static <T> void lessThan(Comparable<T> one, T two, Runnable runnable) {
if (one == null || two == null || one.compareTo(two) >= 0) {
log.error(getLessThanMessage(one, two));
public static <T> void lessThan(Comparable<T> a, T b, Runnable runnable) {
if (a == null || b == null || a.compareTo(b) >= 0) {
log.error(getLessThanMessage(a, b));
runnable.run();
}
}
private static <T> String getLessThanMessage(Comparable<T> one, T two) {
return "Less than constraint not met: " + one + " < " + two;
private static <T> String getLessThanMessage(Comparable<T> a, T b) {
return "Less than constraint not met: " + a + " < " + b;
}
// ---------- Greater than - Comparable
// ---------- Greater than
public static <T> void greaterThan(Comparable<T> one, T two) {
greaterThan(one, two, getGreaterThanMessage(one, two));
public static <T> void greaterThan(Comparable<T> a, T b) {
greaterThan(a, b, getGreaterThanMessage(a, b));
}
public static <T> void greaterThan(Comparable<T> one, T two, RuntimeException e) {
greaterThan(one, two, () -> throwException(e));
public static <T> void greaterThan(Comparable<T> a, T b, RuntimeException e) {
greaterThan(a, b, () -> throwException(e));
}
public static <T> void greaterThan(Comparable<T> one, T two, String message) {
greaterThan(one, two, message, DEFAULT_EXCEPTION);
public static <T> void greaterThan(Comparable<T> a, T b, String message) {
greaterThan(a, b, message, DEFAULT_EXCEPTION);
}
public static <T> void greaterThan(Comparable<T> one, T two, String message,
Class<? extends RuntimeException> exceptionType) {
greaterThan(one, two, () -> throwException(message, exceptionType));
public static <T> void greaterThan(Comparable<T> a, T b, String message, Class<? extends RuntimeException> exceptionType) {
greaterThan(a, b, () -> throwException(message, exceptionType));
}
public static <T> void greaterThan(Comparable<T> one, T two, Runnable runnable) {
if (one == null || two == null || one.compareTo(two) <= 0) {
log.error(getGreaterThanMessage(one, two));
public static <T> void greaterThan(Comparable<T> a, T b, Runnable runnable) {
if (a == null || b == null || a.compareTo(b) <= 0) {
log.error(getGreaterThanMessage(a, b));
runnable.run();
}
}
private static <T> String getGreaterThanMessage(Comparable<T> one, T two) {
return "Greater than constraint not met: " + one + " > " + two;
private static <T> String getGreaterThanMessage(Comparable<T> a, T b) {
return "Greater than constraint not met: " + a + " > " + b;
}
// ---------- Equals
public static void equals(Object one, Object two) {
equals(one, two, equalsErrorMessage(one, two));
public static void equals(Object a, Object b) {
equals(a, b, equalsErrorMessage(a, b));
}
public static void equals(Object one, Object two, String message) {
equals(one, two, message, DEFAULT_EXCEPTION);
public static void equals(Object a, Object b, String message) {
equals(a, b, message, DEFAULT_EXCEPTION);
}
public static void equals(Object one, Object two, RuntimeException e) {
equals(one, two, () -> throwException(e));
public static void equals(Object a, Object b, RuntimeException e) {
equals(a, b, () -> throwException(e));
}
public static void equals(Object one, Object two, Class<? extends RuntimeException> exceptionType) {
equals(one, two, equalsErrorMessage(one, two), exceptionType);
public static void equals(Object a, Object b, Class<? extends RuntimeException> exceptionType) {
equals(a, b, equalsErrorMessage(a, b), exceptionType);
}
public static void equals(Object one, Object two, String message, Class<? extends RuntimeException> exceptionType) {
equals(one, two, () -> throwException(message, exceptionType));
public static void equals(Object a, Object b, String message, Class<? extends RuntimeException> exceptionType) {
equals(a, b, () -> throwException(message, exceptionType));
}
public static void equals(Object one, Object two, Runnable runnable) {
if (one == null || !one.equals(two)) {
log.error(equalsErrorMessage(one, two));
public static void equals(Object a, Object b, Runnable runnable) {
if (a == null || !a.equals(b)) {
log.error(equalsErrorMessage(a, b));
runnable.run();
}
}
private static String equalsErrorMessage(Object one, Object two) {
return "Values are not equal. First arg: " + one + ", Second arg: " + two;
private static String equalsErrorMessage(Object a, Object b) {
return "Values are not equal. First arg: " + a + ", Second arg: " + b;
}
// ---------- Not Equals
public static void notEquals(Object one, Object two) {
notEquals(one, two, notEqualsErrorMessage(one, two));
public static void notEquals(Object a, Object b) {
notEquals(a, b, notEqualsErrorMessage(a, b));
}
public static void notEquals(Object one, Object two, String message) {
notEquals(one, two, message, DEFAULT_EXCEPTION);
public static void notEquals(Object a, Object b, String message) {
notEquals(a, b, message, DEFAULT_EXCEPTION);
}
public static void notEquals(Object one, Object two, Class<? extends RuntimeException> exceptionType) {
notEquals(one, two, notEqualsErrorMessage(one, two), exceptionType);
public static void notEquals(Object a, Object b, Class<? extends RuntimeException> exceptionType) {
notEquals(a, b, notEqualsErrorMessage(a, b), exceptionType);
}
public static void notEquals(Object one, Object two, String message, Class<? extends RuntimeException> exceptionType) {
notEquals(one, two, () -> throwException(message, exceptionType));
public static void notEquals(Object a, Object b, String message, Class<? extends RuntimeException> exceptionType) {
notEquals(a, b, () -> throwException(message, exceptionType));
}
public static void notEquals(Object one, Object two, RuntimeException e) {
notEquals(one, two, () -> throwException(e));
public static void notEquals(Object a, Object b, RuntimeException e) {
notEquals(a, b, () -> throwException(e));
}
public static void notEquals(Object one, Object two, Runnable runnable) {
if (one == null || two == null || one.equals(two)) {
log.error(equalsErrorMessage(one, two));
public static void notEquals(Object a, Object b, Runnable runnable) {
if (a == null || b == null || a.equals(b)) {
log.error(equalsErrorMessage(a, b));
runnable.run();
}
}
private static String notEqualsErrorMessage(Object one, Object two) {
return "Values are equal. First arg: " + one + ", Second arg: " + two;
private static String notEqualsErrorMessage(Object a, Object b) {
return "Values are equal. First arg: " + a + ", Second arg: " + b;
}
// ---------- Null
......
......@@ -41,6 +41,33 @@ public class ValidatecTest extends TestBase {
}
}
// ------ IsFalse
@Test
public void isFalse_allGood() {
Validatec.isFalse(false);
}
@Test (expected = IllegalArgumentException.class)
public void isFalse_failed_throwDefaultException() {
Validatec.isFalse(true);
}
@Test (expected = ArithmeticException.class)
public void isFalse_failed_throwGivenException() {
Validatec.isFalse(true, new ArithmeticException());
}
@Test
public void isFalse_failed_constructException() {
try {
Validatec.isFalse(true, "2 is equal to 2", ArithmeticException.class);
Assert.fail();
} catch (ArithmeticException e) {
Truth.assertThat(e).hasMessageThat().contains("2 is equal to 2");
}
}
// ------ IsNull
@Test
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment