Created
January 30, 2013 05:48
-
-
Save muga/4671001 to your computer and use it in GitHub Desktop.
sample with mockito
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import static org.mockito.Mockito.mock; | |
import static org.mockito.Mockito.spy; | |
import static org.mockito.Mockito.when; | |
import org.junit.Test; | |
public class Sample { | |
static class Reader { | |
private String fileName; | |
public Reader() { | |
} | |
public void init(String fileName) { | |
this.fileName = fileName; | |
readHeader(); | |
} | |
public boolean readHeader() { | |
return true; | |
} | |
} | |
@Test | |
public void sample() throws Exception { | |
//Reader orig = new Reader(); | |
//Reader reader = spy(orig); | |
Reader reader = mock(Reader.class); | |
when(reader.readHeader()).thenThrow(new RuntimeException()); | |
reader.init("theFile"); // RuntimeException is not thrown | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment