• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package org.junit.internal;
2 
3 /** @since 4.13 */
4 public final class Checks {
5 
Checks()6     private Checks() {}
7 
8     /**
9      * Checks that the given value is not {@code null}.
10      *
11      * @param value object reference to check
12      * @return the passed-in value, if not {@code null}
13      * @throws NullPointerException if {@code value} is {@code null}
14      */
notNull(T value)15     public static <T> T notNull(T value) {
16         if (value == null) {
17             throw new NullPointerException();
18         }
19         return value;
20     }
21 
22     /**
23      * Checks that the given value is not {@code null}, using the given message
24      * as the exception message if an exception is thrown.
25      *
26      * @param value object reference to check
27      * @param message message to use if {@code value} is {@code null}
28      * @return the passed-in value, if not {@code null}
29      * @throws NullPointerException if {@code value} is {@code null}
30      */
notNull(T value, String message)31     public static <T> T notNull(T value, String message) {
32         if (value == null) {
33             throw new NullPointerException(message);
34         }
35         return value;
36     }
37 }
38