Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import org.junit.Before;
import org.junit.Test;
import static junit.framework.TestCase.assertEquals;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
public class MockitoTest {
interface StringProvider {
String getString();
}
private StringProvider provider;
@Before
public void setUp() {
provider = mock(StringProvider.class);
}
@Test
public void mokitoSample() {
when(provider.getString()).thenReturn("mocked");
String result = provider.getString();
assertEquals("mocked", result);
verify(provider).getString();
}
}
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.