Skip to content

Commit

Permalink
Add test for JobInclusionFolderProperty class (#416)
Browse files Browse the repository at this point in the history
* Bump io.jenkins.tools.bom:bom-2.452.x (#415)

* Add test for JobInclusionFolderProperty class and added a constructor in ItemInfo.java"

* Address JENKINS-69757 by adding tests for util class (#417)

* add tests for util class

* Use JUnit 4 assertions with JUnit 4 tests

---------

Co-authored-by: Mark Waite <[email protected]>

* Modified the setup method to  reuse the JobInclusionFolderProperty object

* Justify public constructor with a comment

* Use JenkinsRule name consistent with other tests

* Remove unused ItemInfo and tearDown

* Remove unnecessary changes to ItemInfo

* Create project once for all tests

* Add a few more assertions

* Remove queue related assertions

---------

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Henrique Paes <[email protected]>
Co-authored-by: Mark Waite <[email protected]>
  • Loading branch information
4 people authored Dec 29, 2024
1 parent 4e99a3f commit 003a030
Showing 1 changed file with 61 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package jenkins.advancedqueue.jobinclusion.strategy;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import hudson.model.FreeStyleProject;
import hudson.model.Run;
import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Test;
import org.jvnet.hudson.test.JenkinsRule;

public class JobInclusionFolderPropertyTest {

@ClassRule
public static JenkinsRule j = new JenkinsRule();

private static FreeStyleProject project;
private static JobInclusionFolderProperty property;

@BeforeClass
public static void createProject() throws Exception {
project = j.createFreeStyleProject();
Run r = project.scheduleBuild2(0).get(); // Schedule a build to ensure the queue item is created
j.assertBuildStatusSuccess(r);
property = new JobInclusionFolderProperty(true, "testGroup");
}

@Test
public void testGetJobGroupName() {
assertEquals("testGroup", property.getJobGroupName());
}

@Test
public void testIsUseJobGroup() {
assertTrue(property.isUseJobGroup());
}

@Test
public void testGetDescriptor() {
assertThat(property.getDescriptor().getId(), is(JobInclusionFolderProperty.class.getName()));
}

@Test
public void testDescriptorImpl() {
JobInclusionFolderProperty.DescriptorImpl descriptor = new JobInclusionFolderProperty.DescriptorImpl();
assertThat(descriptor.getDisplayName(), is("XXX"));
assertThat(descriptor.getJobGroups(), is(empty()));
assertFalse(descriptor.isUsed());
}

@Test
public void testAllJobsJobInclusionStrategy() {
AllJobsJobInclusionStrategy strategy = new AllJobsJobInclusionStrategy();
assertTrue(strategy.contains(null, project));
}
}

0 comments on commit 003a030

Please sign in to comment.