justcode
justcode

Reputation: 11

Java 1.8 Upgrade Mockito matchers compilation error

This is an Issue which I am having while Upgrading my REST project from 1.7 to 1.8

The test cases seem to show compilation errors after the upgrade

This is the Old code which used to work

when(mockBuilder.post(any(Class.class), anyObject()))
        .thenReturn(mockResponse);

where the post method in my builder is

@Override
    public <T> T post(Class<T> c, Object requestEntity) {
        return response();
    }

Now after the Upgrade my mock test case shows a compilation failure I have java 1.8 and mockito 1.9

Seems like the compiler is unable to find a method with matching arguments

I have tried using other mockito mathcers like any(),isA() and Eq() None of them seems to works,Any suggestions are appreciated

Upvotes: 1

Views: 523

Answers (1)

BretC
BretC

Reputation: 4209

Try just...

when(mockBuilder.post(any(), anyObject()))
    .thenReturn(mockResponse);

There have been some changes to Java 8 generics, for example Java 8: Generic type inference improvements

Upvotes: 1

Related Questions