package org.jenkins.ci.plugins.jenkinslint.check;

import hudson.slaves.DumbSlave;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.JenkinsRule;

import static org.junit.Assert.assertTrue;

/**
 * SlaveDescriptionChecker Test Case.
 *
 * @author Victor Martinez
 */
public class SlaveLabelCheckerTestCase {
    private SlaveDescriptionChecker checker = new SlaveDescriptionChecker();

    @Rule public JenkinsRule j = new JenkinsRule();
    @Test public void testDefaultSlave() throws Exception {
        DumbSlave slave = j.createSlave();
        assertTrue(checker.executeCheck(slave));
    }
    @Test public void testEmptySlaveName() throws Exception {
        DumbSlave slave = j.createSlave();
        slave.setNodeName("");
        assertTrue(checker.executeCheck(slave));
    }
    @Test public void testSlaveDescription() throws Exception {
        DumbSlave slave = j.createSlave();
        slave.setNodeName("blablabla");
        assertTrue(checker.executeCheck(slave));
    }
    /**
    @Test public void testControlComment() throws Exception {
        DumbSlave slave = j.createSlave();
        assertFalse(checker.isIgnored(project.getDescription()));
        project.setDescription("#lint:ignore:" + checker.getClass().getSimpleName());
        assertTrue(checker.isIgnored(project.getDescription()));
    }*/
}

package org.jenkins.ci.plugins.jenkinslint.check;

import hudson.model.Node;
import hudson.model.Slave;
import hudson.slaves.DumbSlave;
import hudson.slaves.JNLPLauncher;
import hudson.slaves.NodeProperty;
import hudson.slaves.RetentionStrategy;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.JenkinsRule;

import java.util.Collections;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

/**
 * SlaveLabelCheckerTestCase Test Case.
 *
 * @author Victor Martinez
 */
public class SlaveLabelCheckerTestCase {
    private SlaveLabelChecker checker = new SlaveLabelChecker();

    @Rule public JenkinsRule j = new JenkinsRule();
    @Test public void testDefaultSlave() throws Exception {
        Slave slave = createSlave("default", "", "");
        assertTrue(checker.executeCheck(slave));
    }
    @Test public void testSlaveLabel() throws Exception {
        Slave slave = createSlave("default", "", "somelabel");
        assertFalse(checker.executeCheck(slave));
    }

    @Test public void testControlComment() throws Exception {
        Slave slave = createSlave("default", "", "");
        assertFalse(checker.isIgnored(slave.getNodeDescription()));
        slave = createSlave("default", "#lint:ignore:" + checker.getClass().getSimpleName(), "");
        assertTrue(checker.isIgnored(slave.getNodeDescription()));
    }

    private Slave createSlave(String name, String description, String label) throws Exception {
        return new DumbSlave(name, description, "/wherever", "1", Node.Mode.NORMAL, label, new JNLPLauncher(), RetentionStrategy.NOOP, Collections.<NodeProperty<?>>emptyList());
    }
}

Test cases for slavelabel check
Test cases for slavelabel check
