### Question:
AreQueuesEmptyOperation { public boolean execute(final RabbitMQConnectionInfo connectionInfo) { final RabbitManagementApiFacade api = rabbitManagementApiProvider.getApi(connectionInfo); final List<Queue> queueStates; try { queueStates = api.listQueues(); } catch (final Exception e) { throw new RuntimeException(e); } final List<String> nonEmptyQueues = queueStates.stream() .filter(queue -> queue.getMessages() > 0) .map(Queue::getName) .collect(Collectors.toList()); log.info("Non-empty queues: {}", nonEmptyQueues); return nonEmptyQueues.isEmpty(); } AreQueuesEmptyOperation(
            final RabbitManagementApiProvider rabbitManagementApiProvider
    ); boolean execute(final RabbitMQConnectionInfo connectionInfo);  }### Answer:
@Test public void testAllQueuesEmpty() { final RabbitMQConnectionInfo connectionInfo = new RabbitMQConnectionInfo("username", "password", "nodename", "servicename"); final Queue queue1 = new Queue().withName("queue1").withMessages(0L); final Queue queue2 = new Queue().withName("queue2").withMessages(0L); final Queue queue3 = new Queue().withName("queue3").withMessages(0L); final RabbitManagementApiFacade apiClient = mock(RabbitManagementApiFacade.class); when(apiCache.getApi(connectionInfo)).thenReturn(apiClient); when(apiClient.listQueues()).thenReturn(Lists.newArrayList(queue1, queue2, queue3)); assertTrue(operation.execute(connectionInfo)); }
@Test public void testOneQueuesHasMessages() { final RabbitMQConnectionInfo connectionInfo = new RabbitMQConnectionInfo("username", "password", "nodename", "servicename"); final Queue queue1 = new Queue().withName("queue1").withMessages(0L); final Queue queue2 = new Queue().withName("queue2").withMessages(1L); final Queue queue3 = new Queue().withName("queue1").withMessages(0L); final RabbitManagementApiFacade apiClient = mock(RabbitManagementApiFacade.class); when(apiCache.getApi(connectionInfo)).thenReturn(apiClient); when(apiClient.listQueues()).thenReturn(Lists.newArrayList(queue1, queue2, queue3)); assertFalse(operation.execute(connectionInfo)); }
@Test public void testMultipleQueuesHaveMessages() { final RabbitMQConnectionInfo connectionInfo = new RabbitMQConnectionInfo("username", "password", "nodename", "servicename"); final Queue queue1 = new Queue().withName("queue1").withMessages(0L); final Queue queue2 = new Queue().withName("queue2").withMessages(1L); final Queue queue3 = new Queue().withName("queue3").withMessages(1L); final RabbitManagementApiFacade apiClient = mock(RabbitManagementApiFacade.class); when(apiCache.getApi(connectionInfo)).thenReturn(apiClient); when(apiClient.listQueues()).thenReturn(Lists.newArrayList(queue1, queue2, queue3)); assertFalse(operation.execute(connectionInfo)); }