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