package hudson.model.labels;

import hudson.model.Label;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.JenkinsRule;

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

public class LabelAtomTest {

    @Rule
    public JenkinsRule j = new JenkinsRule();

    @Test
    public void selfLabel() throws Exception {
        j.createSlave("node", "label", null);
        Label self = new LabelAtom("node");
        assertThat(self.isSelfLabel(), is(true));
        Label label = new LabelAtom("label");
        assertThat(label.isSelfLabel(), is(false));
    }
}

@@ -50,16 +50,70 @@
 .Label;%0A
+import hudson.model.Node;%0Aimport hudson.slaves.Cloud;%0A
 import o
@@ -193,16 +193,68 @@
 sRule;%0A%0A
+import java.util.ArrayList;%0Aimport java.util.List;%0A%0A
 import s
@@ -334,18 +334,117 @@
 atchers.
-is
+containsInAnyOrder;%0Aimport static org.hamcrest.Matchers.is;%0Aimport static org.hamcrest.Matchers.empty
 ;%0A%0Apubli
@@ -816,20 +816,1809 @@
 is(false));%0A
+        Label selfJenkins = j.jenkins.getLabel(%22node%22);%0A        assertThat(selfJenkins.isSelfLabel(), is(true));%0A    %7D%0A%0A    @Test%0A    public void getNodes() throws Exception %7B%0A        Node n1 = j.createSlave(%22n1%22, %22label%22, null);%0A        Node n2 = j.createSlave(%22n2%22, %22label label2%22, null);%0A        Node n3 = j.createSlave(%22n3%22, %22label2%22, null);%0A        Label l = j.jenkins.getLabel(%22label%22);%0A        Label l2 = j.jenkins.getLabel(%22label2%22);%0A        Label l3 = j.jenkins.getLabel(%22label3%22);%0A        assertThat(l.getNodes().size(), is(2));%0A        assertThat(l.getNodes(), containsInAnyOrder(n1,n2));%0A        assertThat(l2.getNodes().size(), is(2));%0A        assertThat(l2.getNodes(), containsInAnyOrder(n3,n2));%0A        assertThat(l3.getNodes(), is(empty()));%0A    %7D%0A%0A    @Test%0A    public void getClouds() %7B%0A        Cloud test = new TestCloud(%22test%22, %22label%22);%0A        j.jenkins.clouds.add(test);%0A        Label l = new LabelAtom(%22label%22);%0A        Label l2 = new LabelAtom(%22label2%22);%0A        assertThat(l.getClouds().size(), is(1));%0A        assertThat(l.getClouds(), containsInAnyOrder(test));%0A        assertThat(l2.getClouds(), is(empty()));%0A    %7D%0A%0A    private static class TestCloud extends Cloud %7B%0A%0A        private final List%3CLabel%3E labels;%0A%0A        public TestCloud(String name, String labelString) %7B%0A            super(name);%0A            labels = new ArrayList%3C%3E();%0A            for (String l : labelString.split(%22 %22)) %7B%0A                labels.add(new LabelAtom(l));%0A            %7D%0A        %7D%0A%0A        @Override%0A        public boolean canProvision(CloudState s) %7B%0A            Label stateLabel = s.getLabel();%0A            for (Label l : labels) %7B%0A                if (stateLabel.equals(l)) %7B%0A                    return true;%0A                %7D%0A            %7D%0A            return false;%0A        %7D%0A
     %7D%0A%7D%0A

Improve tests for Labels (#5007)