All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.mockito.Captor Maven / Gradle / Ivy

There is a newer version: 5.14.2
Show newest version
/*
 * Copyright (c) 2007 Mockito contributors
 * This program is made available under the terms of the MIT License.
 */
package org.mockito;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
 * Allows shorthand {@link org.mockito.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. * * @see ArgumentCaptor * @since 1.8.3 */ @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.FIELD, ElementType.PARAMETER}) @Documented public @interface Captor {}





© 2015 - 2024 Weber Informatics LLC | Privacy Policy