Skip to content

Instantly share code, notes, and snippets.

@ytnk531 ytnk531/MockTest.java
Last active Aug 11, 2018

Embed
What would you like to do?
initMocks
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
import java.util.List;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Mockito.when;
import static org.mockito.MockitoAnnotations.initMocks;
public class MockTest {
@Mock
private List mockedList;
@Before
public void setUp() {
// これがないとmockedListはnullのまま
initMocks(this);
}
@Test
public void test1() {
when(mockedList.get(anyInt()))
.thenReturn(500);
Object actual = mockedList.get(120);
Assert.assertEquals(500, actual);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.