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

v1.8.0 release:

- Validatec: notNull deprecated in favor of newly added noNulls, which supports an Object vararg
- README polishing
- cava.iml file deleted since it is Intellij specific and not project specific
parent b8c532d5
Pipeline #9908211 passed with stage
in 1 minute and 9 seconds
.idea/
dependency-reduced-pom.xml
target/
# TODO cava.iml
\ No newline at end of file
......@@ -27,8 +27,8 @@ GPG Instructions
If needed, ensure that GnuPG is installed.
```
Name: Rajiv Prabhakar
Email: gitlab email
Password: Laptop
Email: {gitlab email}
Password: {laptop password}
```
If hitting error saying *"Signing failed: Inappropriate ioctl for device"*, run:
......@@ -37,6 +37,6 @@ If hitting error saying *"Signing failed: Inappropriate ioctl for device"*, run:
Pending Tasks
=========
More unit tests. Most code in this library has been thoroughly tested by the [Caucus](www.thecaucus.net) project, but for more thorough testing, and to aid in future project development, it will be good to have more unit tests integrated into thsi repository.
More unit tests. Most code in this library has been thoroughly tested by the [Caucus](www.thecaucus.net) project, but for more thorough testing, and to aid in future project development, it will be good to have more unit tests integrated into this repository.
Repository cleanup of various sorts.
<?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
<output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Maven: org.apache.commons:commons-lang3:3.5" level="project" />
<orderEntry type="library" name="Maven: commons-io:commons-io:2.5" level="project" />
<orderEntry type="library" name="Maven: commons-logging:commons-logging:1.2" level="project" />
<orderEntry type="library" name="Maven: org.json:json:20160810" level="project" />
<orderEntry type="library" name="Maven: org.javatuples:javatuples:1.2" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.12" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
<orderEntry type="library" name="Maven: org.slf4j:slf4j-log4j12:1.7.25" level="project" />
<orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.7.25" level="project" />
<orderEntry type="library" name="Maven: log4j:log4j:1.2.17" level="project" />
<orderEntry type="library" name="Maven: org.mockito:mockito-all:1.10.19" level="project" />
<orderEntry type="library" name="Maven: com.google.guava:guava:22.0" level="project" />
<orderEntry type="library" name="Maven: com.google.code.findbugs:jsr305:1.3.9" level="project" />
<orderEntry type="library" name="Maven: com.google.errorprone:error_prone_annotations:2.0.18" level="project" />
<orderEntry type="library" name="Maven: com.google.j2objc:j2objc-annotations:1.1" level="project" />
<orderEntry type="library" name="Maven: org.codehaus.mojo:animal-sniffer-annotations:1.14" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: com.google.truth:truth:0.33" level="project" />
</component>
</module>
\ No newline at end of file
......@@ -6,7 +6,7 @@
<groupId>com.rajivprab</groupId>
<artifactId>cava</artifactId>
<version>1.7.1</version>
<version>1.8.0</version>
<name>Cava: Clean Java</name>
<description>A library that enables users to write minimal, clean and simple Java code</description>
......
......@@ -336,28 +336,34 @@ public class Validatec {
return "Expecting null. Found: " + object;
}
// ---------- Not Null
// ---------- Not Null. Deprecated, use NoNulls
@Deprecated
public static void notNull(Object object) {
notNull(object, "Found unexpected null object");
}
@Deprecated
public static void notNull(Object object, RuntimeException e) {
notNull(object, () -> throwException(e));
}
@Deprecated
public static void notNull(Object object, String message) {
notNull(object, message, DEFAULT_EXCEPTION);
}
@Deprecated
public static void notNull(Object object, Class<? extends RuntimeException> exceptionType) {
notNull(object, "Found unexpected null object", exceptionType);
}
@Deprecated
public static void notNull(Object object, String message, Class<? extends RuntimeException> exceptionType) {
notNull(object, () -> throwException(message, exceptionType));
}
@Deprecated
public static void notNull(Object object, Runnable runnable) {
if (object == null) {
log.error("Not expecting object to be null");
......@@ -365,6 +371,45 @@ public class Validatec {
}
}
// ---------- No Nulls
public static void noNulls(Object... objects) {
noNulls(getNullObjectsString(objects), objects);
}
public static void noNulls(String message, Object... objects) {
noNulls(message, DEFAULT_EXCEPTION, objects);
}
public static void noNulls(Class<? extends RuntimeException> exceptionType, Object... objects) {
noNulls(getNullObjectsString(objects), exceptionType, objects);
}
public static void noNulls(String message, Class<? extends RuntimeException> exceptionType, Object... objects) {
noNulls(() -> throwException(message, exceptionType), objects);
}
public static void noNulls(RuntimeException e, Object... objects) {
noNulls(() -> throwException(e), objects);
}
public static void noNulls(Runnable runnable, Object... objects) {
if (objects == null) {
log.error(getNullObjectsString(objects));
runnable.run();
}
for (Object object : objects) {
if (object == null) {
log.error(getNullObjectsString(objects));
runnable.run();
}
}
}
private static String getNullObjectsString(Object... objects) {
return "Found null in: " + Arrays.toString(objects);
}
// ---------- String Contains
public static void contains(String string, String subString) {
......
......@@ -7,6 +7,8 @@ import com.google.common.truth.Truth;
import org.junit.Assert;
import org.junit.Test;
import java.util.Optional;
/**
* Unit tests for Validatec
* <p>
......@@ -76,17 +78,17 @@ public class ValidatecTest extends TestBase {
}
@Test (expected = IllegalArgumentException.class)
public void isNotNull_constructDefaultException() {
public void isNull_fail_constructDefaultException() {
Validatec.isNull(1);
}
@Test (expected = ArithmeticException.class)
public void isNotNull_throwGivenException() {
public void isNull_fail_throwGivenException() {
Validatec.isNull("", new ArithmeticException());
}
@Test
public void isNotNull_constructException() {
public void isNull_fail_constructException() {
try {
Validatec.isNull(true, "Expecting to find null", ArithmeticException.class);
Assert.fail();
......@@ -103,17 +105,17 @@ public class ValidatecTest extends TestBase {
}
@Test (expected = IllegalArgumentException.class)
public void isNull_constructDefaultException() {
public void notNull_fail_constructDefaultException() {
Validatec.notNull(null);
}
@Test (expected = ArithmeticException.class)
public void isNull_throwGivenException() {
public void notNull_fail_throwGivenException() {
Validatec.notNull(null, new ArithmeticException());
}
@Test
public void isNull_constructException() {
public void notNull_fail_constructException() {
try {
Validatec.notNull(null, ArithmeticException.class);
Assert.fail();
......@@ -122,6 +124,48 @@ public class ValidatecTest extends TestBase {
}
}
// ------ NoNulls
@Test
public void noNulls_allGood() {
Validatec.noNulls(123, "abc");
}
@Test (expected = IllegalArgumentException.class)
public void noNulls_nullArray_constructDefaultException() {
Validatec.noNulls("abc",null);
}
@Test
public void noNulls_fail_throwGivenException() {
try {
Validatec.noNulls(new ArithmeticException(), null, Optional.empty());
Assert.fail();
} catch (ArithmeticException e) {
Truth.assertThat(e).hasMessageThat().isNull();
}
}
@Test
public void noNulls_fail_constructExceptionWithDefaultMessage() {
try {
Validatec.noNulls(ArithmeticException.class, null, Optional.empty());
Assert.fail();
} catch (ArithmeticException e) {
Truth.assertThat(e).hasMessageThat().contains("Found null in: [null, Optional.empty]");
}
}
@Test
public void noNulls_fail_constructExceptionWithCustomMessage() {
try {
Validatec.noNulls("My custom message", ArithmeticException.class, null, 123);
Assert.fail();
} catch (ArithmeticException expected) {
Truth.assertThat(expected).hasMessageThat().contains("My custom message");
}
}
// ----- Collection.Size
@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