Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test for JobInclusionJobProperty class #423

Merged
Merged
Changes from 4 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
package jenkins.advancedqueue.jobinclusion.strategy;

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.Launcher;
import hudson.model.FreeStyleBuild;
import hudson.model.FreeStyleProject;
import hudson.model.StreamBuildListener;
import hudson.util.StreamTaskListener;
import java.io.IOException;
import java.io.PrintStream;
import java.nio.charset.StandardCharsets;
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 {

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

@Rule
public TestName testName = new TestName();

private JobInclusionJobProperty property;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please reduce the differences to the existing test class by changing this to jobProperty in all its usages.

Suggested change
private JobInclusionJobProperty property;
private JobInclusionJobProperty jobProperty;

private FreeStyleProject project;
private FreeStyleBuild build;
private StreamBuildListener listener;
private Launcher launcher;

@Before
public void setUp() throws Exception {
property = new JobInclusionJobProperty(true, "testGroup");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please reduce this difference to the existing test class, since changing the name of the property does not help the test and it makes the review of differences more difficult.

Suggested change
property = new JobInclusionJobProperty(true, "testGroup");
jobProperty = new JobInclusionJobProperty(true, "TestJobGroup");

project = j.createFreeStyleProject("testFolder_" + testName.getMethodName());
build = j.buildAndAssertSuccess(project);
listener = new StreamBuildListener(new PrintStream(System.out), StandardCharsets.UTF_8);
launcher = new hudson.Launcher.LocalLauncher(StreamTaskListener.fromStdout());
}

@Test
public void getDescriptor() {
assertNotNull(property.getDescriptor());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like a deeper assertion than not null.

}

@Test
public void getJobAction() {
// Assuming getJobAction returns some action
assertNotNull(property.getJobActions(project));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like a deeper assertion than not null.

}

@Test
public void getJobActions() {
// Assuming getJobActions returns a list of actions
assertNotNull(property.getJobActions(project));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like a deeper assertion than not null.

}

@Test
public void prebuild() {
// Assuming prebuild performs some pre-build actions
assertTrue(property.prebuild(build, listener));
}

@Test
public void perform() throws IOException, InterruptedException {
// Assuming perform executes some actions
assertTrue(property.perform(build, launcher, listener));
}

@Test
public void getRequiredMonitorService() {
// Assuming getRequiredMonitorService returns some service
assertNotNull(property.getRequiredMonitorService());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like a deeper assertion than not null.

}

@Test
public void getProjectActions() {
// Assuming getProjectAction returns some project action
assertNotNull(property.getProjectActions(project));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like a deeper assertion than not null.

}

@Test
public void getJobGroupNameReturnsCorrectName() throws Exception {
FreeStyleProject myProject = j.createFreeStyleProject("test-project");
JobInclusionJobProperty jobProperty = new JobInclusionJobProperty(true, "groupName");
myProject.addProperty(jobProperty);
assertEquals("groupName", jobProperty.getJobGroupName());
}

@Test
public void getJobGroupNameReturnsNullWhenNotSet() {
JobInclusionJobProperty jobProperty = new JobInclusionJobProperty(false, null);
assertNull(jobProperty.getJobGroupName());
}

@Test
public void isUseJobGroupReturnsCorrectValue() {
JobInclusionJobProperty jobProperty = new JobInclusionJobProperty(true, "groupName");
assertTrue(jobProperty.isUseJobGroup());
}

@Test
public void getJobGroupNameReturnsNullWhenJobGroupNameNotSet() {
JobInclusionJobProperty jobProperty = new JobInclusionJobProperty(true, null);
assertNull(jobProperty.getJobGroupName());
}

@Test
public void descriptorImplGetDisplayName() {
JobInclusionJobProperty.DescriptorImpl descriptor = new JobInclusionJobProperty.DescriptorImpl();
assertEquals("XXX", descriptor.getDisplayName());
}

@Test
public void descriptorImplIsUsed() {
JobInclusionJobProperty.DescriptorImpl descriptor = new JobInclusionJobProperty.DescriptorImpl();
assertFalse(descriptor.isUsed());
}
}
Loading