Skip to content
Create a gist now

Instantly share code, notes, and snippets.

Embed URL


Subversion checkout URL

You can clone with
Download ZIP
Java: Using Mockito for Unit Testing
package us.home.electronics;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import org.junit.Test;
public class ProgrammableTest {
public void testBeepBeep() throws Exception {
Programmable clock = new Programmable.AlarmClock();
Programmable.ProgramCoder coder = mock(Programmable.ProgramCoder.class);
// this line 'overrides' the ProgramCoder.getProgramcode() method
when(coder.getProgramCode()).thenReturn("Beep Beep");
assertEquals("Beep Beep", clock.execute());
assertEquals(clock.getCode(), clock.execute());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.