I am having problems with the mocking UrlEncode.encode method, which is inside the static method.
MyEncodeClass.java has this method
public static myEncode(String s) { UrlEncoder.encode(s, "utf-8"); }
I want to force an exception to be thrown when the UrlEncode.encode method is called.
@Test(expect = UnsupportedEncodingException.class) public void myTest() { PowerMockito.mockStatic(URLEncoder.class); when(URLEncoder.encode("aa", "utf-8")).thenThrow(UnsupportedEncodingException.class); MyEncodeClass.myEncode("aa"); }
but I always get the following exception
Caused by: java.lang.NoSuchMethodError: org.mockito.mock.MockCreationSettings.isUsingConstructor()Z
source share