如何模拟具有lambda表达式的方法

时间:2018-04-05 05:59:20

标签: java powermock

        ClientBuilder builder = ResteasyClientBuilder.newBuilder();
        builder = builder.sslContext(sslContext);
        builder = builder.hostnameVerifier((s1,s2)-> true);

我想模拟builder.hostnameVerifier

我以不同的方式尝试了它,

对于前2行,我可以模拟。我的代码如下:

    PowerMockito.mockStatic(ResteasyClientBuilder.class);
    PowerMockito.when(ResteasyClientBuilder.newBuilder()).thenReturn(clientBuilder);
    PowerMockito.when(clientBuilder.sslContext(sslContext)).thenReturn(clientBuilder);
    PowerMockito.when(this.verifier.verify(Matchers.anyString(), Matchers.anyObject())).thenReturn(true);
    PowerMockito.when(clientBuilder.hostnameVerifier(this.verifier)).thenReturn(clientBuilder);

0 个答案:

没有答案