@Test
public void testPublishListOfMachines() throws Exception {

    AmazonEC2 client = mock(AmazonEC2.class);
    ProviderClientCache clientCache = mock(ProviderClientCache.class);
    when(clientCache.get(Matchers.<Provider>any())).thenReturn(client);
    DelegateExecution execution = mock(DelegateExecution.class);
    List<String> instanceIds = Lists.newArrayList("i-123", "i-456");
    when(execution.getVariable(ProcessVariables.INSTANCE_IDS)).thenReturn(instanceIds);
    when(client.describeInstances(Matchers.<DescribeInstancesRequest>any()))
        .thenReturn(new DescribeInstancesResult()
            .withReservations(new Reservation().withInstances(
                new Instance().withInstanceId("i-123").withPublicDnsName("i1.amazonaws.com")
                    .withPublicIpAddress("1.2.3.4").withPrivateDnsName("i1.internal").withPrivateIpAddress("10.1.2.3"),
                new Instance().withInstanceId("i-456").withPublicDnsName("i2.amazonaws.com")
                    .withPublicIpAddress("5.6.7.8").withPrivateDnsName("i2.internal").withPrivateIpAddress("10.4.5.6")
            )));
    ProcessVariablesCollector collector = new ProcessVariablesCollector();
    collector.install(execution);
    AmazonActivity activity = new PublishListOfMachines(clientCache);
    activity.execute(client, null /* not used */, execution);
    @SuppressWarnings("unchecked")
    List<Machine> machines = (List<Machine>) collector.getVariable(CoreProcessVariables.MACHINES);
    assertThat(machines).hasSize(2);
    assertThat(machines.get(0).getPublicDnsName()).isEqualTo("i1.amazonaws.com");
}