org.mockito.Spy Maven / Gradle / Ivy
/*
* Copyright (c) 2007 Mockito contributors
* This program is made available under the terms of the MIT License.
*/
package org.mockito;
import java.lang.annotation.*;
/**
* Allows shorthand wrapping of field instances in an spy object.
*
*
* Example:
*
*
* public class Test{
* @Spy Foo spyOnFoo = new Foo();
* @Before
* public void init(){
* MockitoAnnotations.initMocks(this);
* }
* ...
* }
*
*
* Same as doing:
*
*
* Foo spyOnFoo = Mockito.spy(new Foo());
*
*
* Warning if you call MockitoAnnotations.initMocks(this)
in a
* super class constructor then this will not work. It is because fields
* in subclass are only instantiated after super class constructor has returned.
* It's better to use @Before.
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
@Documented
public @interface Spy {
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy