org.mockito
Annotation Type Mock


@Target(value=FIELD)
@Retention(value=RUNTIME)
@Documented
public @interface Mock

   public class ArticleManagerTest extends SampleBaseTestCase {

       @Mock private ArticleCalculator calculator;
       @Mock(name = "dbMock") private ArticleDatabase database;
       @Mock(answer = RETURNS_MOCKS) private UserProvider userProvider;

       private ArticleManager manager;

       @Before public void setup() {
           manager = new ArticleManager(userProvider, database, calculator);
       }
   }

   public class SampleBaseTestCase {

       @Before public void initMocks() {
           MockitoAnnotations.initMocks(this);
       }
   }
 
MockitoAnnotations.initMocks(this) method has to called to initialize annotated mocks.

In above example, initMocks() is called in @Before (JUnit4) method of test's base class. For JUnit3 initMocks() can go to setup() method of a base class. You can also put initMocks() in your JUnit runner (@RunWith) or use built-in runners: MockitoJUnitRunner


Optional Element Summary
 Answers answer
           
 java.lang.Class<?>[] extraInterfaces
           
 java.lang.String name
           
 

answer

public abstract Answers answer
Default:
RETURNS_DEFAULTS

name

public abstract java.lang.String name
Default:
""

extraInterfaces

public abstract java.lang.Class<?>[] extraInterfaces
Default:
{}