@Test
public void testDoNotRemoveMoreAgentsThanInstanceGroupMin() {

    AgentInstanceGroup instanceGroup = createRemovableInstanceGroup("instanceGroup1", 2);
    when(agentManagementService.getInstanceGroups()).thenReturn(singletonList(instanceGroup));
    AgentInstance agentInstance1 = AgentInstance.newBuilder()
            .withId("agentInstance1")
            .withInstanceGroupId("instanceGroup1")
            .build();
    AgentInstance agentInstance2 = AgentInstance.newBuilder()
            .withId("agentInstance2")
            .withInstanceGroupId("instanceGroup1")
            .build();
    List<AgentInstance> agentInstances = asList(agentInstance1, agentInstance2);
    when(agentManagementService.getAgentInstances("instanceGroup1")).thenReturn(agentInstances);
    when(agentManagementService.terminateAgents("instanceGroup1", singletonList("agentInstance1"), true))
            .thenReturn(Observable.just(singletonList(Either.ofValue(true))));
    when(v3JobOperations.getTasks()).thenReturn(emptyList());
    testScheduler.advanceTimeBy(6, TimeUnit.MINUTES);
    ClusterRemovableInstanceGroupAgentRemover clusterRemovableInstanceGroupAgentRemover = new ClusterRemovableInstanceGroupAgentRemover(titusRuntime, configuration,
            agentManagementService, v3JobOperations, testScheduler);
    clusterRemovableInstanceGroupAgentRemover.doRemoveAgents().await();
    verify(agentManagementService, times(0)).terminateAgents(any(), any(), anyBoolean());
}