static method mocking example

import static org.powermock.api.mockito.PowerMockito.doReturn;
import static org.powermock.api.mockito.PowerMockito.mockStatic;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;

@RunWith(PowerMockRunner.class)
@PrepareForTest(ZStatic.class)
public class ZStaticTest {

	@Test
	public void sayHello() throws Exception {
		mockStatic(ZStatic.class);
		doReturn("안녕하세요").when(ZStatic.class, "hello");
		System.out.println(ZStatic.hello());
	}
}
Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2013-11-01 13:37:32
Processing time 0.0044 sec