samedi 23 avril 2016

How to mock static method of API

Hi here is my method to test:

public String getRequestBuilder(String foo1) {
RequestBuilder RequestBuilder = ClientRequest
    .authorizationProvider(AuthProviderType.foo);
String locationURI = someclassmethod.getLocationURI(RequestBuilder, foo, foo1);
return locationURI;
}

Here is my test case:

@Test
public void test_foo() {
when(someotherclass.getLocationURI(Matchers.eq(mockRequestBuilder), Matchers.eq("foo"),
    Matchers.eq("foo1"))).thenReturn("locationURI");
assertEquals("locationURI", Properties.getRequestBuilder("foo1"));
}

In the method

RequestBuilder RequestBuilder = ClientRequest.authorizationProvider(AuthProviderType.foo);

is a static method provided by API. I do not want to use PowerMockito for this. If I use

Matchers.any() 

in place of

Matchers.eq(mockRequestBuilder) 

the test case passes. But using Matchers.any wouldn't provide me the exact value. Is there any way to work into this test case?

Aucun commentaire:

Enregistrer un commentaire