Package org.mockito

Annotation Type Captor


  • @Retention(RUNTIME)
    @Target(FIELD)
    @Documented
    public @interface Captor
    Allows shorthand ArgumentCaptor creation on fields.

    Example:

    
     public class Test{
    
        @Captor ArgumentCaptor<AsyncCallback<Foo>> captor;
    
        private AutoCloseable closeable;
    
        @Before
        public void open() {
           closeable = MockitoAnnotations.openMocks(this);
        }
    
        @After
        public void release() throws Exception {
           closeable.close();
        }
    
        @Test public void shouldDoSomethingUseful() {
           //...
           verify(mock).doStuff(captor.capture());
           assertEquals("foo", captor.getValue());
        }
     }
     

    One of the advantages of using @Captor annotation is that you can avoid warnings related capturing complex generic types.

    Since:
    1.8.3
    See Also:
    ArgumentCaptor