powermock在线程“主”中遇到Exception java.lang.ExceptionInInitializerError

时间:2019-04-03 18:12:09

标签: java junit mockito powermock

我正在使用junit 4.12,mockito 1.10.9,powermock 1.6.6 版本的相同组合在其他项目中也可以使用。

我遇到了异常。 线程“主”中的异常java.lang.ExceptionInInitializerError 在org.mockito.internal.exceptions.stacktrace.ConditionalStackTraceFilter中。

import static org.mockito.Mockito.mock;

@RunWith(PowerMockRunner.class)
@PrepareForTest(OfsClientUtilities.class)
public class deleteme {

@Test
public void getAverageTest() throws IOException {
    Client client = mock(Client.class);
    Invocation.Builder target = mock(Invocation.Builder.class);
    Response response = mock(Response.class);

    PowerMockito.mockStatic(OfsClientUtilities.class);

    Mockito.when(OfsClientUtilities.getOfsRestClient(any(), anyString(), 
    anyString())).thenReturn(target);

    Mockito.when(target.get()).thenReturn(response);
    Mockito.when(response.getStatus()).thenReturn(HttpStatus.SC_OK);

    String jsonString = deleteme.read("somefile.json");

    Mockito.when(response.readEntity(String.class)).thenReturn(jsonString);
....}

0 个答案:

没有答案