1

I am writing unit tests for a JestClient wrapper. I'm trying to use Mockito to mock the JestClient, but I'm getting the following error:

Mockito cannot mock this class: interface io.searchbox.client.JestClient

Mockito can only mock visible & non-final classes.
If you're not sure why you're getting this error, please report to the mailing list.

Here is how I am defining the mock:

@Bean(name = Identifiers.JEST_CLIENT)
@Profile(Identifiers.PROFILE_UNIT_TEST)
public JestClient getJestClient() {
    JestClient client = Mockito.mock(JestClient.class);
    return client;
}

I'm not sure why I'm getting the error, since JestClient is just an interface. I am using:

Jest: 0.1.6

Mockito: 2.0.36-beta

Spring: 4.2.4

EDIT: I think the issue is the Elasticsearch library. I was using Elasticsearch 1.5.2; when I switched to 2.2.0, the problem went away. Unfortunately, this doesn't help me, since the cluster I'm talking to runs on 1.5.2.

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
alexgbelov
  • 3,032
  • 4
  • 28
  • 42
  • Add full stacktrace. Seem it is a bug or you don't include enough libraries. – Evgeniy K. Jul 17 '16 at 07:50
  • I think the issue is Elasticsearch 1.5.2. When I updated my libraries to use 2.2.0, the error went away. Unfortunately, the cluster I'm talking to uses 1.5.2, and several of the classes I was using before have been removed. – alexgbelov Jul 17 '16 at 22:50

1 Answers1

0

In my case, the issue was that I was also using Elasticsearch 1.5.2 as one of my libraries. There is a bug with Mockito and Elasticsearch versions before 2.0 where Mockito will not work (see https://github.com/mockito/mockito/issues/341).

alexgbelov
  • 3,032
  • 4
  • 28
  • 42