Created
October 19, 2012 03:29
-
-
Save thomo/3916072 to your computer and use it in GitHub Desktop.
Unittest to verify that static method is called - PowerMock, Mockito, TestNG
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
package abc; | |
import static org.mockito.Matchers.any; | |
import static org.mockito.Matchers.eq; | |
import java.awt.Component; | |
import javax.swing.JOptionPane; | |
import org.powermock.api.mockito.PowerMockito; | |
import org.powermock.core.classloader.annotations.PrepareForTest; | |
import org.powermock.modules.testng.PowerMockTestCase; | |
import org.testng.annotations.Test; | |
class MessageBox { | |
public void showErrorMessage(String msg) { | |
JOptionPane.showMessageDialog(null, msg, "Bar", JOptionPane.ERROR_MESSAGE); | |
} | |
} | |
@PrepareForTest(JOptionPane.class) | |
public class VerifyStaticCallTest extends PowerMockTestCase { | |
/** | |
* Unittest to verify that static method is called with the specified parameter. | |
*/ | |
@Test | |
public void showErrorMessage() { | |
String msg = "foo"; | |
PowerMockito.mockStatic(JOptionPane.class); | |
MessageBox cut = new MessageBox(); | |
cut.showErrorMessage(msg); | |
PowerMockito.verifyStatic(); | |
JOptionPane.showMessageDialog(any(Component.class), | |
eq(msg), | |
any(String.class), | |
eq(JOptionPane.ERROR_MESSAGE)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment