diff options
author | Pete Bentley <prb@google.com> | 2021-03-03 15:09:30 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2021-03-03 15:09:30 +0000 |
commit | 6b74b10fa73184d2d997583b5eded4a23324b64d (patch) | |
tree | 10923530939981dd1dc5f44ceb6316fb9442428a /src/main/java/org/junit/internal/Checks.java | |
parent | e4ffdd500e7ca130574414d7ecf208a147167249 (diff) | |
parent | a9a7715d84046efd231e038b0dc2f551daf61701 (diff) | |
download | junit-6b74b10fa73184d2d997583b5eded4a23324b64d.tar.gz |
Merge changes I578a2676,I4b37c2d0,Id1e2d638,I1ebe37da,I6135799c am: b6446bec0a am: fcd81b3e3f am: c7a6d4ec7d am: a9a7715d84
Original change: https://android-review.googlesource.com/c/platform/external/junit/+/1613132
MUST ONLY BE SUBMITTED BY AUTOMERGER
Change-Id: I70a6b61e69982b66be9f6d7c2e7df5afc91bf382
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; + } +} |