Skip to content

Commit

Permalink
Add test for FolderPropertyLoader class
Browse files Browse the repository at this point in the history
  • Loading branch information
yashpal2104 committed Dec 27, 2024
1 parent 7a9621e commit 5066d89
Showing 1 changed file with 69 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package jenkins.advancedqueue.jobinclusion.strategy;

import static org.junit.Assert.*;

import com.cloudbees.hudson.plugins.folder.Folder;
import hudson.model.FreeStyleProject;
import jenkins.advancedqueue.DecisionLogger;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.JenkinsRule;

public class FolderPropertyLoaderTest {

@Rule
public JenkinsRule jenkinsRule = new JenkinsRule();

private Folder folder;
private FreeStyleProject project;
private DecisionLogger decisionLogger;

@Before
public void setUp() throws Exception {
folder = jenkinsRule.createProject(com.cloudbees.hudson.plugins.folder.Folder.class, "testFolder");
project = folder.createProject(FreeStyleProject.class, "testProject");
decisionLogger = new DecisionLogger() {
@Override
public DecisionLogger addDecisionLog(int indent, String log) {
return null;
}
};
}

@Test
public void getJobGroupName_returnsGroupName_whenJobGroupIsEnabled() throws Exception {
JobInclusionFolderProperty property = new JobInclusionFolderProperty(true, "TestGroup");
folder.getProperties().add(property);

String result = FolderPropertyLoader.getJobGroupName(decisionLogger, project);

assertEquals("TestGroup", result);
}

@Test
public void getJobGroupName_returnsNull_whenNoJobGroupProperty() throws Exception {
String result = FolderPropertyLoader.getJobGroupName(decisionLogger, project);

assertNull(result);
}

@Test
public void getJobGroupName_returnsNull_whenJobGroupIsDisabled() throws Exception {
JobInclusionFolderProperty property = new JobInclusionFolderProperty(false, "TestGroup");
folder.getProperties().add(property);

String result = FolderPropertyLoader.getJobGroupName(decisionLogger, project);

assertNull(result);
}

@Test
public void getJobGroupName_returnsNull_whenParentIsNotFolder() throws Exception {
FreeStyleProject standaloneProject = jenkinsRule.createFreeStyleProject("standaloneProject");

String result = FolderPropertyLoader.getJobGroupName(decisionLogger, standaloneProject);

assertNull(result);
}
}

0 comments on commit 5066d89

Please sign in to comment.