Created
December 7, 2016 17:06
-
-
Save anonymous/1eab366c60efb75b9075f100a67c851b to your computer and use it in GitHub Desktop.
Mocking external method calls from mock
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
public class DefaultOptionPane(){ | |
public String printAwsome() { | |
System.out.println("this is awsome"); | |
return "a"; | |
} | |
} |
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
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"); | |
} | |
} |
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.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