1 package org.mockito.internal.verification; 2 3 import org.junit.Before; 4 import org.junit.Test; 5 import org.mockito.Mock; 6 import org.mockito.MockitoAnnotations; 7 import org.mockito.exceptions.base.MockitoAssertionError; 8 9 import java.util.List; 10 11 import static junit.framework.TestCase.assertTrue; 12 import static org.assertj.core.api.Assertions.fail; 13 import static org.mockito.Mockito.description; 14 import static org.mockito.Mockito.verify; 15 16 public class VerificationWithDescriptionTest { 17 18 @Mock 19 private List<?> mock; 20 21 @Before 22 public void setUp() { 23 MockitoAnnotations.initMocks(this); 24 } 25 26 @Test 27 public void assertion_error_message_should_start_with_the_custom_specified_message() { 28 29 String failureMessage = "Verification failed!"; 30 try { 31 verify(mock, description(failureMessage)).clear(); 32 fail("Should not have made it this far"); 33 34 } catch (MockitoAssertionError e) { 35 assertTrue(e.getMessage().startsWith(failureMessage)); 36 } 37 } 38 } 39