Skip to content

Commit 1a58f3d

Browse files
Migrate tests to JUnit5
* Migrate annotations and imports * Migrate assertions * Remove public visibility for test classes and methods * Minor code cleanup
1 parent 5508995 commit 1a58f3d

11 files changed

+389
-510
lines changed

pom.xml

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -125,23 +125,6 @@ THE SOFTWARE.
125125
<groupId>org.jenkins-ci.plugins.workflow</groupId>
126126
<artifactId>workflow-support</artifactId>
127127
</dependency>
128-
<dependency>
129-
<groupId>com.tngtech.jgiven</groupId>
130-
<artifactId>jgiven-junit</artifactId>
131-
<version>2.0.2</version>
132-
<scope>test</scope>
133-
<exclusions>
134-
<!-- Provided by Jenkins core -->
135-
<exclusion>
136-
<groupId>org.fusesource.jansi</groupId>
137-
<artifactId>jansi</artifactId>
138-
</exclusion>
139-
<exclusion>
140-
<groupId>org.slf4j</groupId>
141-
<artifactId>slf4j-api</artifactId>
142-
</exclusion>
143-
</exclusions>
144-
</dependency>
145128

146129
<!-- Dependencies for test -->
147130
<dependency>

src/test/java/hudson/plugins/throttleconcurrents/TestUtil.java

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package hudson.plugins.throttleconcurrents;
22

3-
import static org.junit.Assert.assertEquals;
4-
import static org.junit.Assert.assertNotNull;
5-
import static org.junit.Assert.assertTrue;
3+
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
5+
import static org.junit.jupiter.api.Assertions.assertNotNull;
66

77
import hudson.EnvVars;
88
import hudson.model.Computer;
@@ -11,14 +11,14 @@
1111
import hudson.model.queue.CauseOfBlockage;
1212
import hudson.slaves.DumbSlave;
1313
import hudson.slaves.RetentionStrategy;
14+
import java.io.File;
1415
import java.util.Arrays;
1516
import java.util.Collections;
1617
import java.util.List;
1718
import java.util.Set;
1819
import jenkins.model.queue.CompositeCauseOfBlockage;
1920
import org.jenkinsci.plugins.workflow.job.WorkflowRun;
2021
import org.jenkinsci.plugins.workflow.support.steps.ExecutorStepExecution;
21-
import org.junit.rules.TemporaryFolder;
2222
import org.jvnet.hudson.test.JenkinsRule;
2323

2424
public class TestUtil {
@@ -34,13 +34,15 @@ public class TestUtil {
3434
static final ThrottleJobProperty.ThrottleCategory OTHER_ONE_PER_NODE =
3535
new ThrottleJobProperty.ThrottleCategory("other_one_per_node", 1, 0, null);
3636

37+
private TestUtil() {
38+
// Instantiation is prohibited
39+
}
40+
3741
private static DumbSlave createAgent(
38-
JenkinsRule j, TemporaryFolder temporaryFolder, EnvVars env, int numExecutors, String label)
39-
throws Exception {
42+
JenkinsRule j, File temporaryFolder, EnvVars env, int numExecutors, String label) throws Exception {
4043
synchronized (j.jenkins) {
4144
int sz = j.jenkins.getNodes().size();
42-
DumbSlave agent =
43-
new DumbSlave("agent" + sz, temporaryFolder.getRoot().getPath(), j.createComputerLauncher(env));
45+
DumbSlave agent = new DumbSlave("agent" + sz, temporaryFolder.getPath(), j.createComputerLauncher(env));
4446
agent.setNumExecutors(numExecutors);
4547
agent.setMode(Node.Mode.NORMAL);
4648
agent.setLabelString(label == null ? "" : label);
@@ -54,12 +56,7 @@ private static DumbSlave createAgent(
5456
}
5557

5658
static Node setupAgent(
57-
JenkinsRule j,
58-
TemporaryFolder temporaryFolder,
59-
List<Node> agents,
60-
EnvVars env,
61-
int numExecutors,
62-
String label)
59+
JenkinsRule j, File temporaryFolder, List<Node> agents, EnvVars env, int numExecutors, String label)
6360
throws Exception {
6461
DumbSlave agent = TestUtil.createAgent(j, temporaryFolder, env, numExecutors, label);
6562

@@ -88,8 +85,7 @@ static void setupCategories(ThrottleJobProperty.ThrottleCategory... categories)
8885
}
8986

9087
static Set<String> getBlockageReasons(CauseOfBlockage cob) {
91-
if (cob instanceof CompositeCauseOfBlockage) {
92-
CompositeCauseOfBlockage ccob = (CompositeCauseOfBlockage) cob;
88+
if (cob instanceof CompositeCauseOfBlockage ccob) {
9389
return ccob.uniqueReasons.keySet();
9490
} else {
9591
return Collections.singleton(cob.getShortDescription());
@@ -99,7 +95,9 @@ static Set<String> getBlockageReasons(CauseOfBlockage cob) {
9995
static void hasPlaceholderTaskForRun(Node n, WorkflowRun r) throws Exception {
10096
for (Executor exec : n.toComputer().getExecutors()) {
10197
if (exec.getCurrentExecutable() != null) {
102-
assertTrue(exec.getCurrentExecutable().getParent() instanceof ExecutorStepExecution.PlaceholderTask);
98+
assertInstanceOf(
99+
ExecutorStepExecution.PlaceholderTask.class,
100+
exec.getCurrentExecutable().getParent());
103101
ExecutorStepExecution.PlaceholderTask task = (ExecutorStepExecution.PlaceholderTask)
104102
exec.getCurrentExecutable().getParent();
105103
while (task.run() == null) {

src/test/java/hudson/plugins/throttleconcurrents/ThrottleCategoryTest.java

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,32 +16,30 @@
1616
*/
1717
package hudson.plugins.throttleconcurrents;
1818

19-
import static org.junit.Assert.assertEquals;
20-
import static org.junit.Assert.assertTrue;
19+
import static org.junit.jupiter.api.Assertions.assertEquals;
20+
import static org.junit.jupiter.api.Assertions.assertTrue;
2121

2222
import java.util.List;
23-
import org.junit.Test;
23+
import org.junit.jupiter.api.Test;
2424

2525
/**
2626
* This class initiates the testing of {@link hudson.plugins.throttleconcurrents.ThrottleJobProperty.ThrottleCategory}.<br>
2727
* -Hence this class also testing {@link hudson.plugins.throttleconcurrents.ThrottleJobProperty.NodeLabeledPair}.<br>
2828
* -Test methods for {@link hudson.plugins.throttleconcurrents.ThrottleJobProperty.ThrottleCategory#getNodeLabeledPairs()}.
2929
3030
*/
31-
public class ThrottleCategoryTest {
31+
class ThrottleCategoryTest {
3232
private static final String testCategoryName = "aCategory";
3333

3434
@Test
35-
public void shouldGetEmptyNodeLabeledPairsListUponInitialNull() {
35+
void shouldGetEmptyNodeLabeledPairsListUponInitialNull() {
3636
ThrottleJobProperty.ThrottleCategory category =
3737
new ThrottleJobProperty.ThrottleCategory(testCategoryName, 0, 0, null);
38-
assertTrue(
39-
"nodeLabeledPairs shall be empty",
40-
category.getNodeLabeledPairs().isEmpty());
38+
assertTrue(category.getNodeLabeledPairs().isEmpty(), "nodeLabeledPairs shall be empty");
4139
}
4240

4341
@Test
44-
public void shouldGetNonEmptyNodeLabeledPairsListThatWasSet() {
42+
void shouldGetNonEmptyNodeLabeledPairsListThatWasSet() {
4543
String expectedLabel = "aLabel";
4644
Integer expectedMax = 1;
4745

@@ -54,12 +52,12 @@ public void shouldGetNonEmptyNodeLabeledPairsListThatWasSet() {
5452
Integer actualMax = category.getNodeLabeledPairs().get(0).getMaxConcurrentPerNodeLabeled();
5553

5654
assertEquals(
57-
"throttledNodeLabel " + actualLabel + " does not match expected " + expectedLabel,
5855
expectedLabel,
59-
actualLabel);
56+
actualLabel,
57+
"throttledNodeLabel " + actualLabel + " does not match expected " + expectedLabel);
6058
assertEquals(
61-
"maxConcurrentPerNodeLabeled " + actualMax + " does not match expected " + expectedMax,
6259
expectedMax,
63-
actualMax);
60+
actualMax,
61+
"maxConcurrentPerNodeLabeled " + actualMax + " does not match expected " + expectedMax);
6462
}
6563
}

0 commit comments

Comments
 (0)