All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.junit.internal.Checks Maven / Gradle / Ivy

Go to download

JUnit is a unit testing framework for Java, created by Erich Gamma and Kent Beck.

There is a newer version: 4.13.2
Show newest version
package org.junit.internal;

/** @since 4.13 */
public final class Checks {

    private Checks() {}

    /**
     * Checks that the given value is not {@code null}.
     *
     * @param value object reference to check
     * @return the passed-in value, if not {@code null}
     * @throws NullPointerException if {@code value} is {@code null}
     */
    public static  T notNull(T value) {
        if (value == null) {
            throw new NullPointerException();
        }
        return value;
    }

    /**
     * Checks that the given value is not {@code null}, using the given message
     * as the exception message if an exception is thrown.
     *
     * @param value object reference to check
     * @param message message to use if {@code value} is {@code null}
     * @return the passed-in value, if not {@code null}
     * @throws NullPointerException if {@code value} is {@code null}
     */
    public static  T notNull(T value, String message) {
        if (value == null) {
            throw new NullPointerException(message);
        }
        return value;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy