# Mock

## 1. Initialising Mock Objects - Mockito

<https://stackoverflow.com/questions/15494926/initialising-mock-objects-mockito>

1\). MockitoAnnotations

```java
public class SampleBaseTestCase{

    @Before public void initMocks(){

        MockiotAnnotations.initMocks(this);
    }
}
```

2\). RunWith

```java
@RunWith(MockitoJUnitRunner.class)
```

3\).

```java
mock(xxx.class);
```

## 2. @Mock VS @InjectMocks

@Mock creates a mock. @InjectMocks creates an instance of the class and injects the mocks that are created with the @Mock(or @Spy) annotations into this instance. Note that you must use @RunWith(MockitoJUnitRunner.class) or Mockito.initMocks(this) to initialize these mocks and inject them.

```java
Mockito.when(mockclass.methof(Mockito.any())).thenReturn(true);
```
