1 /* 2 * Copyright (c) 2007 Mockito contributors 3 * This program is made available under the terms of the MIT License. 4 */ 5 package org.mockitousage.annotation; 6 7 import static org.assertj.core.api.Assertions.assertThat; 8 import static org.junit.Assert.fail; 9 10 import java.util.List; 11 12 import org.junit.Before; 13 import org.junit.Test; 14 import org.mockito.Captor; 15 import org.mockito.MockitoAnnotations; 16 import org.mockito.exceptions.base.MockitoException; 17 import org.mockitoutil.TestBase; 18 19 public class CaptorAnnotationUnhappyPathTest extends TestBase { 20 21 @Captor List<?> notACaptorField; 22 23 @Before 24 @Override init()25 public void init() { 26 // we need to get rid of parent implementation this time 27 } 28 29 @Test shouldFailIfCaptorHasWrongType()30 public void shouldFailIfCaptorHasWrongType() throws Exception { 31 try { 32 // when 33 MockitoAnnotations.openMocks(this); 34 fail(); 35 } catch (MockitoException e) { 36 // then 37 assertThat(e) 38 .hasMessageContaining("notACaptorField") 39 .hasMessageContaining("wrong type"); 40 } 41 } 42 } 43