Skip to content

Instantly share code, notes, and snippets.

@ytnk531
Created August 11, 2018 02:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ytnk531/9f84aef93b4ceab30af2de8e392a1b50 to your computer and use it in GitHub Desktop.
Save ytnk531/9f84aef93b4ceab30af2de8e392a1b50 to your computer and use it in GitHub Desktop.
Rule
import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;
import java.util.List;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Mockito.when;
public class MockTest {
@Rule
public MockitoRule rule = MockitoJUnit.rule();
@Mock
private List mockedList;
@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