aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/junit/internal/Checks.java
blob: 9724947f99779981f2122e7dd58ca2902010e03b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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> 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> T notNull(T value, String message) {
        if (value == null) {
            throw new NullPointerException(message);
        }
        return value;
    }
}