-
Notifications
You must be signed in to change notification settings - Fork 75
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
Changes from 4 commits
36c051b
1907f53
435a167
95a20a7
b342fc1
d161d4d
b1d8e33
fbaa413
a3de303
7c9da76
e414328
66d4611
fa8f326
f574e59
0171109
d9bb6b6
6dc0488
97489d8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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; | ||||||
private FreeStyleProject project; | ||||||
private FreeStyleBuild build; | ||||||
private StreamBuildListener listener; | ||||||
private Launcher launcher; | ||||||
|
||||||
@Before | ||||||
public void setUp() throws Exception { | ||||||
property = new JobInclusionJobProperty(true, "testGroup"); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
|
||||||
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()); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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)); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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)); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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()); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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)); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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()); | ||||||
} | ||||||
} |
There was a problem hiding this comment.
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.