K8sImpl implements K8s { @Override public Future<List<KafkaTopic>> listResources() { return crdOperator.listAsync(namespace, io.strimzi.operator.common.model.Labels.fromMap(labels.labels())); } K8sImpl(Vertx vertx, KubernetesClient client, Labels labels, String namespace); @Override Future<KafkaTopic> createResource(KafkaTopic topicResource); @Override Future<KafkaTopic> updateResource(KafkaTopic topicResource); @Override Future<KafkaTopic> updateResourceStatus(KafkaTopic topicResource); @Override Future<Void> deleteResource(ResourceName resourceName); @Override Future<List<KafkaTopic>> listResources(); @Override Future<KafkaTopic> getFromName(ResourceName resourceName); @SuppressWarnings("deprecation") @Override Future<Void> createEvent(Event event);  }
@Test public void testList(VertxTestContext context) { Checkpoint async = context.checkpoint(); List<KafkaTopic> mockKafkaTopicsList = Collections.singletonList(new KafkaTopicBuilder() .withMetadata(new ObjectMetaBuilder() .withName("unrelated") .withLabels(Collections.singletonMap("foo", "bar")).build()) .build()); KubernetesClient mockClient = mock(KubernetesClient.class); MixedOperation<KafkaTopic, KafkaTopicList, TopicOperator.DeleteKafkaTopic, Resource<KafkaTopic, TopicOperator.DeleteKafkaTopic>> mockResources = mock(MixedOperation.class); when(mockClient.customResources(any(CustomResourceDefinitionContext.class), any(Class.class), any(Class.class), any(Class.class))).thenReturn(mockResources); when(mockClient.customResources(any(CustomResourceDefinition.class), any(Class.class), any(Class.class), any(Class.class))).thenReturn(mockResources); when(mockResources.withLabels(any())).thenReturn(mockResources); when(mockResources.inNamespace(any())).thenReturn(mockResources); when(mockResources.list()).thenAnswer(invocation -> { KafkaTopicList ktl = new KafkaTopicList(); ktl.setItems(mockKafkaTopicsList); return ktl; }); K8sImpl k8s = new K8sImpl(vertx, mockClient, new Labels("foo", "bar"), "default"); k8s.listResources().onComplete(context.succeeding(kafkaTopics -> context.verify(() -> { assertThat(kafkaTopics, is(mockKafkaTopicsList)); async.flag(); }))); }