diff options
author | Pete Bentley <prb@google.com> | 2021-02-24 09:48:30 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2021-02-24 09:48:30 +0000 |
commit | d8911c6e959a1bda9b2b77d9aa0d35eea7a401f9 (patch) | |
tree | 1331fa1b743d5d0a341f82ff555ce4c602f40ab9 /src/main/java/org/junit/internal/Checks.java | |
parent | dae4d9403d1dbe5618167998d92bf79360632433 (diff) | |
parent | d1359663578e2a49e74ed74eb10d4b663d58cf3f (diff) | |
download | junit-d8911c6e959a1bda9b2b77d9aa0d35eea7a401f9.tar.gz |
Merge changes I8f5cd126,Ifdb59336,I6abae5ae,I5ec909df am: d135966357
Original change: https://android-review.googlesource.com/c/platform/external/junit/+/1601635
MUST ONLY BE SUBMITTED BY AUTOMERGER
Change-Id: I05d47d7655c50db318c4060118dfcd98af542a45
Diffstat (limited to 'src/main/java/org/junit/internal/Checks.java')
-rw-r--r-- | src/main/java/org/junit/internal/Checks.java | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/main/java/org/junit/internal/Checks.java b/src/main/java/org/junit/internal/Checks.java new file mode 100644 index 0000000..9724947 --- /dev/null +++ b/src/main/java/org/junit/internal/Checks.java @@ -0,0 +1,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; + } +} |