• 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.mockitousage.annotation;
7 
8 import org.junit.Before;
9 import org.junit.Test;
10 import org.mockito.Captor;
11 import org.mockito.MockitoAnnotations;
12 import org.mockito.exceptions.base.MockitoException;
13 import org.mockitoutil.TestBase;
14 
15 import java.util.List;
16 
17 import static org.junit.Assert.fail;
18 import static org.assertj.core.api.Assertions.assertThat;
19 
20 public class CaptorAnnotationUnhappyPathTest extends TestBase {
21 
22     @Captor List<?> notACaptorField;
23 
24     @Before
25     @Override
init()26     public void init() {
27         //we need to get rid of parent implementation this time
28     }
29 
30     @Test
shouldFailIfCaptorHasWrongType()31     public void shouldFailIfCaptorHasWrongType() throws Exception {
32         try {
33             //when
34             MockitoAnnotations.initMocks(this);
35             fail();
36         } catch (MockitoException e) {
37             //then
38             assertThat(e)
39                 .hasMessageContaining("notACaptorField")
40                 .hasMessageContaining("wrong type");
41         }
42     }
43 }
44