public <K, V> boolean assignPartitions(Consumer<K, V> consumer, Set<TopicPartition> newAssignment,
        ConsumerRebalanceListener listener) {
        Set<TopicPartition> currentAssignment = consumer.assignment();
        if (!newAssignment.equals(currentAssignment)) {
            listener.onPartitionsRevoked(currentAssignment);
            consumer.assign(newAssignment);
            listener.onPartitionsAssigned(newAssignment);
            return true;
        }
        return false;
    }
@Test
    public void testCanReassignPartitions() {    
        Set<TopicPartition> onePartition = Collections.singleton(new TopicPartition(SingleTopicKafkaSpoutConfiguration.TOPIC, 0));
        Set<TopicPartition> twoPartitions = new HashSet<>();
        twoPartitions.add(new TopicPartition(SingleTopicKafkaSpoutConfiguration.TOPIC, 0));
        twoPartitions.add(new TopicPartition(SingleTopicKafkaSpoutConfiguration.TOPIC, 1));
        KafkaConsumer<String, String> consumerMock = mock(KafkaConsumer.class);
        ConsumerRebalanceListener listenerMock = mock(ConsumerRebalanceListener.class);
        TopicAssigner assigner = new TopicAssigner();
        
        //Set the first assignment
        assigner.assignPartitions(consumerMock, onePartition, listenerMock);
        
        InOrder inOrder = inOrder(consumerMock, listenerMock);
        inOrder.verify(listenerMock).onPartitionsRevoked(Collections.emptySet());
        inOrder.verify(consumerMock).assign(new HashSet<>(onePartition));
        inOrder.verify(listenerMock).onPartitionsAssigned(new HashSet<>(onePartition));
        
        clearInvocations(consumerMock, listenerMock);
        
        when(consumerMock.assignment()).thenReturn(new HashSet<>(onePartition));
        
        //Update to set the second assignment
        assigner.assignPartitions(consumerMock, twoPartitions, listenerMock);
        
        //The partition revocation hook must be called before the new partitions are assigned to the consumer,
        //to allow the revocation hook to commit offsets for the revoked partitions.
        inOrder.verify(listenerMock).onPartitionsRevoked(new HashSet<>(onePartition));
        inOrder.verify(consumerMock).assign(new HashSet<>(twoPartitions));
        inOrder.verify(listenerMock).onPartitionsAssigned(new HashSet<>(twoPartitions));
    }