aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/junit/internal/Checks.java
diff options
context:
space:
mode:
authorPete Bentley <prb@google.com>2021-02-24 11:41:00 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2021-02-24 11:41:00 +0000
commitf7adff9d456ec1fd10bfe84951d4756d78dbba6f (patch)
tree5ae2f0fddfaf8cf38a22f2e954387f1e59ec6e1f /src/main/java/org/junit/internal/Checks.java
parentb7d327f57d78e42387240a4caf22875227df7a68 (diff)
parent99022df227f5503b68838d97e0a6b3fa5f558f1b (diff)
downloadjunit-f7adff9d456ec1fd10bfe84951d4756d78dbba6f.tar.gz
Merge changes I8f5cd126,Ifdb59336,I6abae5ae,I5ec909df am: d135966357 am: d8911c6e95 am: 82af4b8b1d am: 99022df227
Original change: https://android-review.googlesource.com/c/platform/external/junit/+/1601635 MUST ONLY BE SUBMITTED BY AUTOMERGER Change-Id: Ie9d6917a074028da6e240c6974f79d484e028da3
Diffstat (limited to 'src/main/java/org/junit/internal/Checks.java')
-rw-r--r--src/main/java/org/junit/internal/Checks.java37
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;
+ }
+}