### Question:
KafkaAdminClient implements Closeable { public Map<TopicPartition, String> getConsumerGroupAssignments(String consumerGroup) { if (StringUtils.isBlank(consumerGroup)) throw new IllegalArgumentException("consumerGroup cannot be null, empty or blank"); Map<TopicPartition, String> assignments = new HashMap<>(); Collection<AdminClient.ConsumerSummary> summaries = getConsumerGroupSummaries(consumerGroup); for (final AdminClient.ConsumerSummary consumerSummary : summaries) { Set<TopicPartition> topicPartitions = convertToJavaSet(consumerSummary.assignment().iterator()); for (final TopicPartition topicPartition : topicPartitions) { assignments.put(topicPartition, consumerSummary.clientId()); } } return Collections.unmodifiableMap(assignments); } KafkaAdminClient(Properties properties); Set<String> getTopics(); Set<TopicAndPartition> getPartitions(); Set<TopicAndPartition> getPartitions(String topic); Authorizer getAuthorizer(); Map<Resource, Set<Acl>> getAcls(); Map<Resource, Set<Acl>> getAcls(KafkaPrincipal principal); Set<Acl> getAcls(Resource resource); void addAcls(Set<Acl> acls, Resource resource); void removeAcls(Set<Acl> acls, Resource resource); void createTopic(String topic, int partitions, int replicationFactor); void createTopic(String topic, int partitions, int replicationFactor, Properties topicConfig); void deleteTopic(String topic); Properties getTopicConfig(String topic); void updateTopicConfig(String topic, Properties properties); int getTopicReplicationFactor(String topic); int getTopicPartitions(String topic); void addTopicPartitions(String topic, int partitions); AdminClient.ConsumerGroupSummary getConsumerGroupSummary(String consumerGroup); Collection<AdminClient.ConsumerSummary> getConsumerGroupSummaries(String consumerGroup); Map<TopicPartition, String> getConsumerGroupAssignments(String consumerGroup); @Override void close(); static final String ZOOKEEPER_SECURE; static final String DEFAULT_ZOOKEEPER_SECURE; static final String OPERATION_TIMEOUT_MS; static final String DEFAULT_OPERATION_TIMEOUT_MS; static final String OPERATION_SLEEP_MS; static final String DEFAULT_OPERATION_SLEEP_MS; }### Answer:
@Test (expected = IllegalArgumentException.class) public void getConsumerGroupAssignments_nullConsumerGroup() { client.getConsumerGroupAssignments(null); }
@Test (expected = IllegalArgumentException.class) public void getConsumerGroupAssignments_emptyConsumerGroup() { client.getConsumerGroupAssignments(""); }
@Test (expected = IllegalArgumentException.class) public void getConsumerGroupAssignments_blankConsumerGroup() { client.getConsumerGroupAssignments(" "); }
@Test public void getConsumerGroupAssignments() { client.createTopic(testName.getMethodName(), 1, 1); Properties properties = new Properties(); properties.putAll(KafkaTests.getProps()); properties.setProperty(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, BytesDeserializer.class.getName()); properties.setProperty(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, BytesDeserializer.class.getName()); properties.setProperty(ConsumerConfig.GROUP_ID_CONFIG, testName.getMethodName()); properties.setProperty(ConsumerConfig.CLIENT_ID_CONFIG, testName.getMethodName() + "-client-id"); try (Consumer<Object, Object> consumer = new KafkaConsumer<>(properties)) { consumer.subscribe(Arrays.asList(testName.getMethodName())); consumer.poll(Duration.ofSeconds(5L)); assertThat(client.getConsumerGroupAssignments(testName.getMethodName()), is(Collections.singletonMap(new TopicPartition(testName.getMethodName(), 0), testName.getMethodName() + "-client-id"))); } }
@Test public void getConsumerGroupAssignments_consumerGroupDoesNotExist() { assertThat(client.getConsumerGroupAssignments("does-not-exist"), is(Collections.emptyMap())); }