Source:
public void testCreateOrReplace() throws IOException { String jsonObject = "{\"apiVersion\": \"test.fabric8.io/v1alpha1\",\"kind\": \"Hello\"," + "\"metadata\": {\"resourceVersion\":\"1\", \"name\": \"example-hello\"},\"spec\": {\"size\": 3, \"scope\": \"Namespaced\"}}"; server.expect().post().withPath("/apis/test.fabric8.io/v1alpha1/namespaces/ns1/hellos").andReturn(HttpURLConnection.HTTP_INTERNAL_ERROR, new StatusBuilder().build()).once(); server.expect().post().withPath("/apis/test.fabric8.io/v1alpha1/namespaces/ns1/hellos").andReturn(HttpURLConnection.HTTP_CREATED, jsonObject).once(); server.expect().post().withPath("/apis/test.fabric8.io/v1alpha1/namespaces/ns1/hellos").andReturn(HttpURLConnection.HTTP_CONFLICT, jsonObject).once(); server.expect().put().withPath("/apis/test.fabric8.io/v1alpha1/namespaces/ns1/hellos/example-hello").andReturn(HttpURLConnection.HTTP_OK, jsonObject).once(); server.expect().get().withPath("/apis/test.fabric8.io/v1alpha1/namespaces/ns1/hellos/example-hello").andReturn(HttpURLConnection.HTTP_OK, jsonObject).once(); KubernetesClient client = server.getClient(); KubernetesClientException exception = Assertions.assertThrows(KubernetesClientException.class, () -> client.customResource(customResourceDefinitionContext).createOrReplace("ns1", jsonObject)); assertEquals(HttpURLConnection.HTTP_INTERNAL_ERROR, exception.getCode()); Map<String, Object> resource = client.customResource(customResourceDefinitionContext).createOrReplace("ns1", jsonObject); assertEquals("example-hello", ((Map<String, Object>)resource.get("metadata")).get("name").toString()); resource = client.customResource(customResourceDefinitionContext).createOrReplace("ns1", jsonObject); assertEquals("example-hello", ((Map<String, Object>)resource.get("metadata")).get("name").toString()); }

Target:
public void testCreateOrReplace() throws IOException { String jsonObject = "{\"apiVersion\": \"test.fabric8.io/v1alpha1\",\"kind\": \"Hello\"," + "\"metadata\": {\"resourceVersion\":\"1\", \"name\": \"example-hello\"},\"spec\": {\"size\": 3}}"; server.expect().post().withPath("/apis/test.fabric8.io/v1alpha1/namespaces/ns1/hellos").andReturn(HttpURLConnection.HTTP_INTERNAL_ERROR, new StatusBuilder().build()).once(); server.expect().post().withPath("/apis/test.fabric8.io/v1alpha1/namespaces/ns1/hellos").andReturn(HttpURLConnection.HTTP_CREATED, jsonObject).once(); server.expect().post().withPath("/apis/test.fabric8.io/v1alpha1/namespaces/ns1/hellos").andReturn(HttpURLConnection.HTTP_CONFLICT, jsonObject).once(); server.expect().put().withPath("/apis/test.fabric8.io/v1alpha1/namespaces/ns1/hellos/example-hello").andReturn(HttpURLConnection.HTTP_OK, jsonObject).once(); server.expect().get().withPath("/apis/test.fabric8.io/v1alpha1/namespaces/ns1/hellos/example-hello").andReturn(HttpURLConnection.HTTP_OK, jsonObject).once(); KubernetesClient client = server.getClient(); KubernetesClientException exception = Assertions.assertThrows(KubernetesClientException.class, () -> client.customResource(customResourceDefinitionContext).createOrReplace("ns1", jsonObject)); assertEquals(HttpURLConnection.HTTP_INTERNAL_ERROR, exception.getCode()); Map<String, Object> resource = client.customResource(customResourceDefinitionContext).createOrReplace("ns1", jsonObject); assertEquals("example-hello", ((Map<String, Object>)resource.get("metadata")).get("name").toString()); resource = client.customResource(customResourceDefinitionContext).createOrReplace("ns1", jsonObject); assertEquals("example-hello", ((Map<String, Object>)resource.get("metadata")).get("name").toString()); }