1 /* 2 * Copyright (c) 2017 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 import static org.junit.Assert.assertEquals; 9 10 import org.junit.Rule; 11 import org.junit.Test; 12 import org.junit.rules.ExpectedException; 13 14 public class ChecksTest { 15 @Rule 16 public ExpectedException expectedException = ExpectedException.none(); 17 18 @Test checkNotNull_not_null()19 public void checkNotNull_not_null() throws Exception { 20 assertEquals("abc", Checks.checkNotNull("abc", "someValue")); 21 } 22 23 @Test checkNotNull_not_null_additional_message()24 public void checkNotNull_not_null_additional_message() throws Exception { 25 assertEquals("abc", Checks.checkNotNull("abc", "someValue", "Oh no!")); 26 } 27 28 @Test checkNotNull_null()29 public void checkNotNull_null() throws Exception { 30 expectedException.expect(IllegalArgumentException.class); 31 expectedException.expectMessage("someValue should not be null"); 32 Checks.checkNotNull(null, "someValue"); 33 } 34 35 @Test checkNotNull_null_additonal_message()36 public void checkNotNull_null_additonal_message() throws Exception { 37 expectedException.expect(IllegalArgumentException.class); 38 expectedException.expectMessage("someValue should not be null. Oh no!"); 39 Checks.checkNotNull(null, "someValue", "Oh no!"); 40 } 41 } 42