@Override
    public Map<String, String> getAddresses() {
        AwsCredentials credentials = awsCredentialsProvider.credentials();
        Map<String, String> instances = Collections.emptyMap();
        if (!awsConfig.anyOfEcsPropertiesConfigured()) {
            instances = awsEc2Api.describeInstances(credentials);
        }
        if (awsConfig.anyOfEc2PropertiesConfigured()) {
            return instances;
        }
        if (instances.isEmpty() && DiscoveryMode.Client == awsConfig.getDiscoveryMode()) {
            return getEcsAddresses(credentials);
        }
        return instances;
    }
@Test
    public void doNotGetEcsAddressesWhenEc2Configured() {
        AwsCredentials credentials = AwsCredentials.builder()
                .setAccessKey("access-key")
                .setSecretKey("secret-key")
                .setToken("token")
                .build();
        AwsConfig awsConfig = AwsConfig.builder()
                .setDiscoveryMode(DiscoveryMode.Client)
                .setSecurityGroupName("my-security-group")
                .build();
        awsEc2Client = new AwsEc2Client(awsEc2Api, awsEcsApi, awsMetadataApi, awsCredentialsProvider, awsConfig);
        given(awsCredentialsProvider.credentials()).willReturn(credentials);
        given(awsEc2Api.describeInstances(credentials)).willReturn(emptyMap());

        // when
        Map<String, String> result = awsEc2Client.getAddresses();

        // then
        then(awsEcsApi).should(never()).listTaskPrivateAddresses("CLUSTER", credentials);
        then(awsEc2Api).should(never()).describeNetworkInterfaces(anyList(), any(AwsCredentials.class));
        assertEquals(emptyMap(), result);
    }