Created
February 7, 2014 08:44
-
-
Save mid0111/8859159 to your computer and use it in GitHub Desktop.
Junit spy static 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
public class Foo { | |
public static String testMethod() { | |
return "foo"; | |
} | |
} |
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.junit.Assert.assertNotNull; | |
import static org.junit.Assert.fail; | |
import java.util.HashMap; | |
import java.util.Map; | |
import org.junit.Test; | |
import org.junit.runner.RunWith; | |
import org.powermock.api.mockito.PowerMockito; | |
import org.powermock.core.classloader.annotations.PrepareForTest; | |
import org.powermock.modules.junit4.PowerMockRunner; | |
@RunWith(PowerMockRunner.class) | |
@PrepareForTest({Foo.class }) | |
public class Snipets { | |
@Test | |
public void hoge() throws Exception { | |
PowerMockito.spy(Foo.class); | |
PowerMockito.when(Foo.class, "testMethod").thenReturn("dummy"); | |
String actual = Foo.testMethod(); | |
assertEquals("dummy", actual); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment