De-flake `InitMilestoneTest`
package hudson.init;
-import static org.junit.Assert.assertEquals;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.contains;
-import java.util.ArrayList;
-import java.util.List;
+import java.util.Queue;
+import java.util.concurrent.ConcurrentLinkedQueue;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.JenkinsRule;
@@ -17,48 +18,48 @@ public class InitMilestoneTest {
@Test
public void testInitMilestones() {
- List<InitMilestone> attained = r.jenkins.getExtensionList(Initializers.class).get(0).getAttained();
+ Queue<InitMilestone> attained = r.jenkins.getExtensionList(Initializers.class).get(0).getAttained();
- assertEquals(InitMilestone.EXTENSIONS_AUGMENTED, attained.get(0));
- assertEquals(InitMilestone.SYSTEM_CONFIG_LOADED, attained.get(1));
- assertEquals(InitMilestone.SYSTEM_CONFIG_ADAPTED, attained.get(2));
- assertEquals(InitMilestone.JOB_LOADED, attained.get(3));
- assertEquals(InitMilestone.JOB_CONFIG_ADAPTED, attained.get(4));
+ assertThat(attained, contains(
+ InitMilestone.EXTENSIONS_AUGMENTED,
+ InitMilestone.SYSTEM_CONFIG_LOADED,
+ InitMilestone.SYSTEM_CONFIG_ADAPTED,
+ InitMilestone.JOB_LOADED,
+ InitMilestone.JOB_CONFIG_ADAPTED));
}
// Using @Initializer in static methods to check all the InitMilestones are loaded in all tests instances and make them fail,
// so using a TestExtension and checking only the InitMilestone after EXTENSION_AUGMENTED
@TestExtension("testInitMilestones")
public static class Initializers {
- private int order = 0;
- private List<InitMilestone> attained = new ArrayList<>();
+ private Queue<InitMilestone> attained = new ConcurrentLinkedQueue<>();
@Initializer(after = InitMilestone.EXTENSIONS_AUGMENTED)
public void extensionsAugmented() {
- attained.add(order++, InitMilestone.EXTENSIONS_AUGMENTED);
+ attained.offer(InitMilestone.EXTENSIONS_AUGMENTED);
}
@Initializer(after = InitMilestone.SYSTEM_CONFIG_LOADED)
public void pluginsSystemConfigLoaded() {
- attained.add(order++, InitMilestone.SYSTEM_CONFIG_LOADED);
+ attained.offer(InitMilestone.SYSTEM_CONFIG_LOADED);
}
@Initializer(after = InitMilestone.SYSTEM_CONFIG_ADAPTED)
public void pluginsSystemConfigAdapted() {
- attained.add(order++, InitMilestone.SYSTEM_CONFIG_ADAPTED);
+ attained.offer(InitMilestone.SYSTEM_CONFIG_ADAPTED);
}
@Initializer(after = InitMilestone.JOB_LOADED)
public void jobLoaded() {
- attained.add(order++, InitMilestone.JOB_LOADED);
+ attained.offer(InitMilestone.JOB_LOADED);
}
@Initializer(after = InitMilestone.JOB_CONFIG_ADAPTED)
public void jobConfigAdapted() {
- attained.add(order++, InitMilestone.JOB_CONFIG_ADAPTED);
+ attained.offer(InitMilestone.JOB_CONFIG_ADAPTED);
}
- public List<InitMilestone> getAttained() {
+ public Queue<InitMilestone> getAttained() {
return attained;
}
}
