package hudson.init;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.contains;

import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.JenkinsRule;
import org.jvnet.hudson.test.TestExtension;

public class InitMilestoneTest {

    @Rule
    public JenkinsRule r  = new JenkinsRule();

    @Test
    public void testInitMilestones() {

        Queue<InitMilestone> attained = r.jenkins.getExtensionList(Initializers.class).get(0).getAttained();

        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 Queue<InitMilestone> attained = new ConcurrentLinkedQueue<>();

        @Initializer(after = InitMilestone.EXTENSIONS_AUGMENTED)
        public void extensionsAugmented() {
            attained.offer(InitMilestone.EXTENSIONS_AUGMENTED);
        }

        @Initializer(after = InitMilestone.SYSTEM_CONFIG_LOADED)
        public void pluginsSystemConfigLoaded() {
            attained.offer(InitMilestone.SYSTEM_CONFIG_LOADED);
        }

        @Initializer(after = InitMilestone.SYSTEM_CONFIG_ADAPTED)
        public void pluginsSystemConfigAdapted() {
            attained.offer(InitMilestone.SYSTEM_CONFIG_ADAPTED);
        }

        @Initializer(after = InitMilestone.JOB_LOADED)
        public void jobLoaded() {
            attained.offer(InitMilestone.JOB_LOADED);
        }

        @Initializer(after = InitMilestone.JOB_CONFIG_ADAPTED)
        public void jobConfigAdapted() {
            attained.offer(InitMilestone.JOB_CONFIG_ADAPTED);
        }

        public Queue<InitMilestone> getAttained() {
            return attained;
        }
    }

}

@@ -37,89 +37,86 @@
 org.
-hamcrest.MatcherAssert.assertThat;%0Aimport static org.hamcrest.Matchers.contains;%0A
+junit.Assert.assertEquals;%0A%0Aimport java.util.ArrayList;%0Aimport java.util.List;
 %0Aimp
@@ -470,21 +470,20 @@
         
-Queue
+List
 %3CInitMil
@@ -589,12 +589,14 @@
 sert
-That
+Equals
 (att
@@ -606,16 +606,15 @@
 ed, 
-contains
+List.of
 (%0A  
@@ -2166,21 +2166,20 @@
  public 
-Queue
+List
 %3CInitMil
@@ -2221,24 +2221,40 @@
  return 
+new ArrayList%3C%3E(
 attained
 ;%0A      
@@ -2245,16 +2245,17 @@
 attained
+)
 ;%0A      

Improve `InitMilestoneTest` error message (#7166)