Skip to content

Commit 1b17611

Browse files
strangelookingnerdhypery2k
authored andcommitted
Migrate tests to JUnit5
* Migrate annotations and imports * Migrate assertions * Remove public visibility for test classes and methods * Minor code cleanup
1 parent d8b8a27 commit 1b17611

4 files changed

Lines changed: 39 additions & 40 deletions

File tree

src/test/java/hudson/plugins/logparser/LineToStatusTest.java

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

3-
import org.junit.Before;
4-
import org.junit.Test;
3+
import org.junit.jupiter.api.BeforeEach;
4+
import org.junit.jupiter.api.Test;
55

66
import java.util.Arrays;
77
import java.util.regex.Pattern;
88

99
import static org.assertj.core.api.Assertions.assertThat;
1010

11-
public class LineToStatusTest {
11+
class LineToStatusTest {
1212
private LineToStatus toStatus;
1313

14-
@Before
15-
public void setUp() {
14+
@BeforeEach
15+
void setUp() {
1616
toStatus = new LineToStatus(Arrays.asList(
1717
new ParsingRulePattern("my-rule", Pattern.compile("abc")),
1818
new ParsingRulePattern("my-second-rule", Pattern.compile("bc")),
@@ -21,19 +21,19 @@ public void setUp() {
2121
}
2222

2323
@Test
24-
public void shouldHandleEmpty() {
24+
void shouldHandleEmpty() {
2525
String actual = toStatus.apply("");
2626
assertThat(actual).isEqualTo(LogParserConsts.NONE);
2727
}
2828

2929
@Test
30-
public void shouldSkipCommentedRule() {
30+
void shouldSkipCommentedRule() {
3131
String actual = toStatus.apply("xyz");
3232
assertThat(actual).isEqualTo(LogParserConsts.NONE);
3333
}
3434

3535
@Test
36-
public void shouldFindOnlyFirstMatchingRule() {
36+
void shouldFindOnlyFirstMatchingRule() {
3737
String actual = toStatus.apply("abc");
3838
assertThat(actual).isEqualTo("my-rule");
3939
}

src/test/java/hudson/plugins/logparser/ParsingStrategyLocatorTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
package hudson.plugins.logparser;
22

3-
import org.junit.Test;
3+
import org.junit.jupiter.api.Test;
44

55
import java.util.HashMap;
66
import java.util.Map;
77

88
import static org.assertj.core.api.Assertions.assertThat;
99

10-
public class ParsingStrategyLocatorTest {
10+
class ParsingStrategyLocatorTest {
1111

1212
@Test
13-
public void shouldDefaultToClassic() {
13+
void shouldDefaultToClassic() {
1414
Map<String, String> systemProperties = new HashMap<>();
1515
ParsingStrategyLocator locator = new ParsingStrategyLocator(systemProperties);
1616

@@ -20,7 +20,7 @@ public void shouldDefaultToClassic() {
2020
}
2121

2222
@Test
23-
public void shouldAllowOverridingToStream() {
23+
void shouldAllowOverridingToStream() {
2424
Map<String, String> systemProperties = new HashMap<>();
2525
systemProperties.put(ParsingStrategy.class.getName(), StreamParsingStrategy.class.getName());
2626
ParsingStrategyLocator locator = new ParsingStrategyLocator(systemProperties);
@@ -31,7 +31,7 @@ public void shouldAllowOverridingToStream() {
3131
}
3232

3333
@Test
34-
public void shouldFallbackToClassic() {
34+
void shouldFallbackToClassic() {
3535
Map<String, String> systemProperties = new HashMap<>();
3636
systemProperties.put(ParsingStrategy.class.getName(), "does.not.match");
3737
ParsingStrategyLocator locator = new ParsingStrategyLocator(systemProperties);

src/test/java/org/jenkinsci/plugins/logparser/ConfigurationAsCodeTest.java

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,29 @@
33
import jenkins.model.Jenkins;
44
import hudson.plugins.logparser.LogParserPublisher;
55
import hudson.plugins.logparser.ParserRuleFile;
6-
import org.junit.Rule;
7-
import org.junit.Test;
6+
import org.junit.jupiter.api.Disabled;
7+
import org.junit.jupiter.api.Test;
88
import org.jvnet.hudson.test.JenkinsRule;
99
import io.jenkins.plugins.casc.ConfigurationAsCode;
10-
11-
import static org.junit.Assert.assertEquals;
12-
13-
import org.junit.Ignore;
10+
import org.jvnet.hudson.test.junit.jupiter.WithJenkins;
1411

1512
import java.util.List;
1613

17-
public class ConfigurationAsCodeTest {
14+
import static org.junit.jupiter.api.Assertions.assertEquals;
15+
import static org.junit.jupiter.api.Assertions.assertTrue;
1816

19-
@Rule
20-
public JenkinsRule r = new JenkinsRule();
17+
@WithJenkins
18+
class ConfigurationAsCodeTest {
2119

2220
@Test
23-
public void LegacyFormattingTest() throws Exception {
21+
void legacyFormattingTest(JenkinsRule r) {
2422
final LogParserPublisher.DescriptorImpl descriptor = (LogParserPublisher.DescriptorImpl) Jenkins.get().getDescriptor(LogParserPublisher.class);
2523
ConfigurationAsCode.get().configure(ConfigurationAsCodeTest.class.getResource("configuration-as-code-legacy-formatting.yaml").toString());
26-
assertEquals(true, descriptor.getLegacyFormatting());
24+
assertTrue(descriptor.getLegacyFormatting());
2725
}
2826

2927
@Test
30-
public void ParsingRulesTest() throws Exception {
28+
void parsingRulesTest(JenkinsRule r) {
3129
final LogParserPublisher.DescriptorImpl descriptor = (LogParserPublisher.DescriptorImpl) Jenkins.get().getDescriptor(LogParserPublisher.class);
3230
ConfigurationAsCode.get().configure(ConfigurationAsCodeTest.class.getResource("configuration-as-code-parsing-rules.yaml").toString());
3331
List<ParserRuleFile> parseRuleFiles = descriptor.getParsingRulesGlobal();
@@ -37,9 +35,9 @@ public void ParsingRulesTest() throws Exception {
3735
assertEquals("./maven-project1.zip", parseRuleFiles.get(0).getPath());
3836
}
3937

40-
@Ignore("Not finished")
38+
@Disabled("Not finished")
4139
@Test
42-
public void export_configuration() throws Exception {
40+
void export_configuration(JenkinsRule r) throws Exception {
4341
ConfigurationAsCode.get().configure(ConfigurationAsCodeTest.class.getResource("configuration-as-code.yaml").toString());
4442
ConfigurationAsCode.get().export(System.out);
4543
}

src/test/java/org/jenkinsci/plugins/logparser/LogParserWorkflowTest.java

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,31 +8,32 @@
88
import hudson.tasks.Maven;
99
import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition;
1010
import org.jenkinsci.plugins.workflow.job.WorkflowJob;
11-
import org.junit.BeforeClass;
12-
import org.junit.ClassRule;
13-
import org.junit.Test;
11+
import org.junit.jupiter.api.BeforeAll;
12+
import org.junit.jupiter.api.Test;
1413
import org.jvnet.hudson.test.JenkinsRule;
1514
import org.jvnet.hudson.test.ToolInstallations;
15+
import org.jvnet.hudson.test.junit.jupiter.WithJenkins;
1616

1717
import java.io.File;
1818
import java.net.URL;
1919

20-
import static org.junit.Assert.assertEquals;
21-
import static org.junit.Assert.assertNotNull;
20+
import static org.junit.jupiter.api.Assertions.assertEquals;
21+
import static org.junit.jupiter.api.Assertions.assertNotNull;
2222

2323
/**
2424
* In this test suite we initialize the Job workspaces with a resource (maven-project1.zip) that contains a Maven
2525
* project.
2626
*/
27-
public class LogParserWorkflowTest {
27+
@WithJenkins
28+
class LogParserWorkflowTest {
2829

29-
@ClassRule
30-
public static JenkinsRule jenkinsRule = new JenkinsRule();
30+
private static JenkinsRule jenkinsRule;
3131

3232
private static LogParserAction result;
3333

34-
@BeforeClass
35-
public static void init() throws Exception {
34+
@BeforeAll
35+
static void init(JenkinsRule rule) throws Exception {
36+
jenkinsRule = rule;
3637
Maven.MavenInstallation mavenInstallation = ToolInstallations.configureMaven35();
3738
WorkflowJob job = jenkinsRule.jenkins.createProject(WorkflowJob.class, "logParserPublisherWorkflowStep");
3839
DumbSlave agent = jenkinsRule.createOnlineSlave();
@@ -56,7 +57,7 @@ public static void init() throws Exception {
5657
* Run a workflow job using {@link LogParserPublisher} and check for success.
5758
*/
5859
@Test
59-
public void logParserPublisherWorkflowStep() throws Exception {
60+
void logParserPublisherWorkflowStep() {
6061
assertEquals(0, result.getResult().getTotalErrors());
6162
assertEquals(2, result.getResult().getTotalWarnings());
6263
assertEquals(0, result.getResult().getTotalInfos());
@@ -66,15 +67,15 @@ public void logParserPublisherWorkflowStep() throws Exception {
6667
* Run a workflow job using {@link LogParserPublisher} and check for number of debug tags
6768
*/
6869
@Test
69-
public void logParserPublisherWorkflowStepDebugTags() throws Exception {
70+
void logParserPublisherWorkflowStepDebugTags() {
7071
assertEquals(0, result.getResult().getTotalDebugs());
7172
}
7273

7374
/**
7475
* Run a workflow job using {@link LogParserPublisher} and check for number of example arbitrary tags
7576
*/
7677
@Test
77-
public void logParserPublisherWorkflowStepArbitraryTags() throws Exception {
78+
void logParserPublisherWorkflowStepArbitraryTags() {
7879
assertEquals(0, result.getResult().getTotalCountsByExtraTag("jenkins"));
7980
assertEquals(1, result.getResult().getTotalCountsByExtraTag("logParserPublisherWorkflowStep"));
8081
}

0 commit comments

Comments
 (0)