1

for my test I need to mock a io.fabric8.kubernetes.client.KubernetesClient. This is what my test looks like:

    @Mock(answer = Answers.RETURNS_DEEP_STUBS)
    KubernetesClient kubernetesClient;

    ...

    @Test
    void dummyTest() {
        when(kubernetesClient.resources(any()).inNamespace(eq("integration")).withName(eq("bar")).get()).thenReturn(createMockSubscriptionResource());
        ...
    }

I would expect that this line would create a deep-stub for this method-chain. However, when I execute the test I get the following exception:

Method threw 'org.mockito.exceptions.misusing.InvalidUseOfMatchersException' exception. Cannot evaluate io.fabric8.kubernetes.client.KubernetesClient$MockitoMock$1322763925.toString()

This results in a null-pointer-exception. I am wondering why Mockito is trying to call .toString() and why I am getting this error at all. Can anyone give me a hint here?

Thanks in advance!

Turo
  • 4,724
  • 2
  • 14
  • 27
ledex
  • 97
  • 1
  • 1
  • 7

0 Answers0