@Test
public void testFlexTierMultiInstanceAllocation() {

    List<AgentInstanceGroup> instanceGroups = asList(
            getInstanceGroup(Tier.Critical, M4_XLARGE_ID, 0, 0),
            getInstanceGroup(Tier.Critical, M4_4XLARGE_ID, 0, 0),
            getInstanceGroup(Tier.Flex, R4_8XLARGE_ID, 0, 5),
            getInstanceGroup(Tier.Flex, R4_4XLARGE_ID, 0, 5),
            getInstanceGroup(Tier.Flex, P2_8XLARGE_ID, 0, 5)
    );
    when(agentManagementService.getInstanceGroups()).thenReturn(instanceGroups);
    ApplicationSLA defaultSLA = ApplicationSLA.newBuilder()
            .withAppName(ApplicationSlaManagementEndpoint.DEFAULT_APPLICATION)
            .withTier(Tier.Flex)
            .withResourceDimension(ResourceDimension
                    .newBuilder().withCpus(4).withMemoryMB(512).withNetworkMbs(128).withDiskMB(512).build()
            )
            .withInstanceCount(10)
            .build();
    ApplicationSLA flexAppSLA = ApplicationSLA.newBuilder(defaultSLA).withInstanceCount(40).build();
    CapacityRequirements requirements = new CapacityRequirements(singletonMap(Tier.Flex, asList(defaultSLA, flexAppSLA)));
    CapacityAllocations allocations = strategy.compute(requirements);
    allocations.getInstanceGroups().forEach(instanceGroup -> {
        assertThat(instanceGroup.getTier()).isEqualTo(Tier.Flex);
    });
    AgentInstanceGroup r48xlInstanceGroup = findInstanceGroupByInstanceType(allocations.getInstanceGroups(), R4_8XLARGE_ID);
    assertThat(allocations.getExpectedMinSize(r48xlInstanceGroup)).isEqualTo(5);
    AgentInstanceGroup r44xlInstanceGroup = findInstanceGroupByInstanceType(allocations.getInstanceGroups(), R4_4XLARGE_ID);
    assertThat(allocations.getExpectedMinSize(r44xlInstanceGroup)).isEqualTo(4);
    AgentInstanceGroup p28xlInstanceGroup = findInstanceGroupByInstanceType(allocations.getInstanceGroups(), P2_8XLARGE_ID);
    assertThat(allocations.getExpectedMinSize(p28xlInstanceGroup)).isEqualTo(0);
}