KafkaOperations implements AutoCloseable { public boolean removeTopic(final String topic) { try { final DeleteTopicsResult result = adminClient.deleteTopics(Collections.singletonList(topic)); result.all().get(); return true; } catch (final ExecutionException e) { throw handleExecutionException(e); } catch (final InterruptedException exception) { throw new RuntimeException(exception.getMessage(), exception); } } KafkaOperations(final AdminClient adminClient, final KafkaConsumer<String, String> consumerClient); TopicList getAvailableTopics(); NodeList getClusterNodes(); Map<String, TopicDetails> getTopicDetails(final Collection<String> topics); TopicDetails getTopicDetails(final String topic); TopicConfig getTopicConfig(final String topic); BrokerConfig getBrokerConfig(final String brokerId); boolean createTopic(final CreateTopic createTopic); TopicConfig alterTopicConfig(final String topic, final Map<String, String> configItems); boolean removeTopic(final String topic); List<ConsumerGroupIdentifier> listConsumers(); boolean removeConsumerGroup(final String id); ConsumerGroupDetails getConsumerGroupDetails(final String consumerGroupId); List<ConsumerGroupDetails> getConsumerGroupDetails(final List<String> consumerGroupIds); ConsumerGroupOffsets getConsumerGroupOffsets(final String consumerGroupId); ConsumerGroupOffsetsWithTailPositions getConsumerGroupOffsetsWithTailOffsets(final String consumerGroupId); TailOffsets getTailOffsets(final String topic); TailOffsets getTailOffsets(final String topic, final Collection<Integer> partitions); void close();  }
@Test public void testRemoveTopic() { final String newTopic = "TestTopic-" + System.currentTimeMillis(); sharedKafkaTestResource .getKafkaTestUtils() .createTopic(newTopic, 1, (short) 1); TopicList topicsList = kafkaOperations.getAvailableTopics(); assertTrue("Should contain our topic now", topicsList.getTopicNames().contains(newTopic)); final boolean result = kafkaOperations.removeTopic(newTopic); assertTrue("Should have returned true", result); topicsList = kafkaOperations.getAvailableTopics(); assertFalse("Should not contain our topic anymore", topicsList.getTopicNames().contains(newTopic)); }