Skip to content

Instantly share code, notes, and snippets.

Created December 7, 2016 17:06
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 anonymous/1eab366c60efb75b9075f100a67c851b to your computer and use it in GitHub Desktop.
Save anonymous/1eab366c60efb75b9075f100a67c851b to your computer and use it in GitHub Desktop.
Mocking external method calls from mock
public class DefaultOptionPane(){
public String printAwsome() {
System.out.println("this is awsome");
return "a";
}
}
public class ExcelSupport {
/**
* Default constructor
*
*/
public ExcelSupport() {}
public void testMethod() {
DefaultOptionPane optionPane = new DefaultOptionPane();
System.out.println("Entering method");
optionPane.printAwsome();
System.out.println("Exiting Method");
}
}
import static org.mockito.Mockito.when;
import static org.mockito.Mockito.mock;
import static org.mockito.Matchers.*;
public class ExcelSupportTest{
@Test
public void testMethodTest() {
DefaultOptionPane optionPane = mock(DefaultOptionPane.class);
when(optionPane.printAwsome()).thenReturn("tada");
// System.out.println(dp.printAwsome());
ExcelSupport es2 = new ExcelSupport();
es2.testMethod();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment