• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2007 Mockito contributors
3  * This program is made available under the terms of the MIT License.
4  */
5 
6 package org.mockito.internal.util;
7 
8 /**
9  * Pre-made preconditions
10  */
11 public class Checks {
12 
checkNotNull(T value, String checkedValue)13     public static <T> T checkNotNull(T value, String checkedValue) {
14         return checkNotNull(value, checkedValue, null);
15     }
16 
checkNotNull(T value, String checkedValue, String additionalMessage)17     public static <T> T checkNotNull(T value, String checkedValue, String additionalMessage) {
18         if(value == null) {
19             String message = checkedValue + " should not be null";
20             if (additionalMessage != null) {
21                 message += ". " + additionalMessage;
22             }
23             throw new IllegalArgumentException(message);
24         }
25         return value;
26     }
27 
checkItemsNotNull(T iterable, String checkedIterable)28     public static <T extends Iterable<?>> T checkItemsNotNull(T iterable, String checkedIterable) {
29         checkNotNull(iterable, checkedIterable);
30         for (Object item : iterable) {
31             checkNotNull(item, "item in " + checkedIterable);
32         }
33         return iterable;
34     }
35 }
36