* Tests {@link GerritTrigger#gerritSlavesToWaitFor(String serverName)}. It should
* return default slave when slave configure at the job level does not exist.
*/
@Test
public void shouldReturnDefaultSlaveWhenJobConfiguredSlaveDoesNotExist() {
ReplicationConfig replicationConfigMock = setupReplicationConfigMock();
GerritTrigger gerritTrigger = new GerritTrigger(null, null, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, true, false, true,
false, false, "", "", "", "", "", "", "", null, PluginImpl.DEFAULT_SERVER_NAME, "slaveUUID", null,
false, false, "", null);
// Replication is configured at job level but slave and default no longer exist.
when(replicationConfigMock.isEnableReplication()).thenReturn(true);
when(replicationConfigMock.isEnableSlaveSelectionInJobs()).thenReturn(true);
when(replicationConfigMock.getGerritSlave("slaveUUID", true)).thenReturn(null);
List<GerritSlave> slaves = gerritTrigger.gerritSlavesToWaitFor(PluginImpl.DEFAULT_SERVER_NAME);
assertNotNull(slaves);
assertEquals(0, slaves.size());
// Replication is configured at job level but slave no longer exist
when(replicationConfigMock.isEnableReplication()).thenReturn(true);
when(replicationConfigMock.isEnableSlaveSelectionInJobs()).thenReturn(true);
GerritSlave expectedSlave = new GerritSlave("defaultSlaveUUID", "defaultSlave", "defaultSlave", 1234);
when(replicationConfigMock.getGerritSlave("slaveUUID", true)).thenReturn(expectedSlave);
slaves = gerritTrigger.gerritSlavesToWaitFor(PluginImpl.DEFAULT_SERVER_NAME);
assertNotNull(slaves);
assertEquals(1, slaves.size());
assertEquals(expectedSlave, slaves.get(0));
}