Skip to content

Commit

Permalink
Add test for JobInclusionJobProperty class (#423)
Browse files Browse the repository at this point in the history
* Add test for JobInclusionJobProperty class

* Remove unused code from test

* Add static methods to manage and add job groups in JobInclusionJobProperty for extensive tests

- Introduce `addJobGroup` method to add job groups with display name and value.
- Introduce `getJobGroups` method to retrieve the list of job groups.

* Add static methods to manage and add job groups in JobInclusionJobProperty for extensive tests

- Introduce `addJobGroup` method to add job groups with display name and value.
- Introduce `getJobGroups` method to retrieve the list of job groups.

* Add extensive test assertions

- Introduce `addJobGroup` method to add job groups with display name and value.
- Introduce `getJobGroups` method to retrieve the list of job groups.

* Add extensive test assertions

- Introduce `addJobGroup` method to add job groups with display name and value.
- Introduce `getJobGroups` method to retrieve the list of job groups.

* Removed getRequiredMonitorService method since not able to deepen assertions

* Added necessary changes made by review

* Added necessary changes made by review

* Reduce diffs to master branch

* Reduce diffs to master branch

---------

Co-authored-by: Mark Waite <mark.earl.waite@gmail.com>
  • Loading branch information
yashpal2104 and MarkEWaite authored Jan 1, 2025
1 parent 3f3fe0b commit 5bad03a
Showing 1 changed file with 80 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,112 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;

import hudson.model.FreeStyleProject;
import org.junit.After;
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TestName;
import org.jvnet.hudson.test.JenkinsRule;

public class JobInclusionJobPropertyTest {
private JobInclusionJobProperty jobProperty;
private JobInclusionJobProperty.DescriptorImpl descriptor;

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

@Rule
public JenkinsRule jenkinsRule = new JenkinsRule();
public TestName testName = new TestName();

private JobInclusionJobProperty jobProperty;
private FreeStyleProject jobProject;
private JobInclusionJobProperty.DescriptorImpl descriptor;

@Before
public void setup() {
public void setUp() throws Exception {
jobProperty = new JobInclusionJobProperty(true, "TestJobGroup");
descriptor = new JobInclusionJobProperty.DescriptorImpl();
descriptor = jobProperty.getDescriptor();
jobProject = j.createFreeStyleProject("testFolder_" + testName.getMethodName());
}

@After
public void deleteProject() throws Exception {
jobProject.delete();
}

@Test
public void getJobGroupNameTest() {
assertEquals("TestJobGroup", jobProperty.getJobGroupName());
}

@Test
public void getJobGroupNameReturnsNullWhenNotSetAndFalse() {
// Create a JobInclusionJobProperty with useJobGroup set to false and jobGroupName set to null
jobProperty = new JobInclusionJobProperty(false, null);
assertFalse(jobProperty.isUseJobGroup());
assertNull(jobProperty.getJobGroupName());
}

@Test
public void getJobGroupNameReturnsNullWhenNotSetAndTrue() {
// Create a JobInclusionJobProperty with useJobGroup set to true and jobGroupName set to null
jobProperty = new JobInclusionJobProperty(true, null);
assertTrue(jobProperty.isUseJobGroup());
assertNull(jobProperty.getJobGroupName());
}

@Test
public void isUseJobGroupReturnsCorrectValue() {
// Create a JobInclusionJobProperty with useJobGroup set to true
jobProperty = new JobInclusionJobProperty(true, "groupName");
assertTrue(jobProperty.isUseJobGroup());
assertEquals("groupName", jobProperty.getJobGroupName());

// Create a JobInclusionJobProperty with useJobGroup set to false
JobInclusionJobProperty jobPropertyFalse = new JobInclusionJobProperty(false, "groupName");
assertFalse(jobPropertyFalse.isUseJobGroup());
assertEquals("groupName", jobPropertyFalse.getJobGroupName());

// Create a JobInclusionJobProperty with null jobGroupName
JobInclusionJobProperty jobPropertyNull = new JobInclusionJobProperty(true, null);
assertTrue(jobPropertyNull.isUseJobGroup());
assertNull(jobPropertyNull.getJobGroupName());
}

@Test
public void isUseJobGroupTest() {
assertTrue(jobProperty.isUseJobGroup());

// Create a JobInclusionJobProperty with useJobGroup set to false
JobInclusionJobProperty jobPropertyFalse = new JobInclusionJobProperty(false, "groupName2");
assertFalse(jobPropertyFalse.isUseJobGroup());
assertEquals("groupName2", jobPropertyFalse.getJobGroupName());

// Create a JobInclusionJobProperty with null jobGroupName
JobInclusionJobProperty jobPropertyNull = new JobInclusionJobProperty(true, null);
assertTrue(jobPropertyNull.isUseJobGroup());
assertNull(jobPropertyNull.getJobGroupName());
}

@Test
public void getDescriptorTest() {
assertNotNull(jobProperty.getDescriptor());
public void getJobGroupNameReturnsNullWhenJobGroupNameNotSet() {
// Create a JobInclusionJobProperty with useJobGroup set to true and jobGroupName set to null
JobInclusionJobProperty jobProperty = new JobInclusionJobProperty(true, null);
assertTrue(jobProperty.isUseJobGroup());
assertNull(jobProperty.getJobGroupName());

// Create a JobInclusionJobProperty with useJobGroup set to false and jobGroupName set to null
JobInclusionJobProperty jobPropertyFalse = new JobInclusionJobProperty(false, null);
assertFalse(jobPropertyFalse.isUseJobGroup());
assertNull(jobPropertyFalse.getJobGroupName());

// Create a JobInclusionJobProperty with useJobGroup set to true and jobGroupName set to a non-null value
JobInclusionJobProperty jobPropertyWithGroupName = new JobInclusionJobProperty(true, "testJobGroupName");
assertTrue(jobPropertyWithGroupName.isUseJobGroup());
assertEquals("testJobGroupName", jobPropertyWithGroupName.getJobGroupName());
}

@Test
Expand Down

0 comments on commit 5bad03a

Please sign in to comment.