Skip to content

Commit

Permalink
Merge pull request #232 from strangelookingnerd/migrate_to_junit5
Browse files Browse the repository at this point in the history
Migrate tests to JUnit5
  • Loading branch information
TobiX authored Jan 28, 2025
2 parents 6367d3d + 4904fcf commit fde72d4
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 30 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>5.5</version>
<version>5.6</version>
<relativePath />
</parent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,29 @@
import static org.hamcrest.Matchers.hasProperty;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNotNull;

import hudson.ExtensionList;
import io.jenkins.plugins.casc.ConfigurationContext;
import io.jenkins.plugins.casc.ConfiguratorRegistry;
import io.jenkins.plugins.casc.impl.configurators.GlobalConfigurationCategoryConfigurator;
import io.jenkins.plugins.casc.misc.ConfiguredWithCode;
import io.jenkins.plugins.casc.misc.JenkinsConfiguredWithCodeRule;
import io.jenkins.plugins.casc.misc.junit.jupiter.WithJenkinsConfiguredWithCode;
import io.jenkins.plugins.casc.model.CNode;
import io.jenkins.plugins.casc.model.Mapping;
import java.util.Objects;
import jenkins.appearance.AppearanceCategory;
import jenkins.model.GlobalConfigurationCategory;
import org.codefirst.SimpleThemeDecorator;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.jupiter.api.Test;

public class ConfigurationAsCodeTest {

@ClassRule
@ConfiguredWithCode("ConfigurationAsCode.yml")
public static JenkinsConfiguredWithCodeRule j = new JenkinsConfiguredWithCodeRule();
@WithJenkinsConfiguredWithCode
class ConfigurationAsCodeTest {

@Test
public void testConfig() {
@ConfiguredWithCode("ConfigurationAsCode.yml")
void testConfig(JenkinsConfiguredWithCodeRule j) {
SimpleThemeDecorator decorator = j.jenkins.getDescriptorByType(SimpleThemeDecorator.class);

assertNotNull(decorator.getElements());
Expand All @@ -47,7 +45,8 @@ public void testConfig() {
}

@Test
public void testExport() throws Exception {
@ConfiguredWithCode("ConfigurationAsCode.yml")
void testExport(JenkinsConfiguredWithCodeRule j) throws Exception {
ConfigurationContext context = new ConfigurationContext(ConfiguratorRegistry.get());
CNode yourAttribute = getAppearanceRoot(context).get("simpleTheme");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,17 @@
import static org.hamcrest.Matchers.hasSize;

import org.codefirst.SimpleThemeDecorator;
import org.junit.Rule;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.jvnet.hudson.test.JenkinsRule;
import org.jvnet.hudson.test.junit.jupiter.WithJenkins;
import org.jvnet.hudson.test.recipes.LocalData;

public class ConfigurationMigrationTest {

@Rule
public JenkinsRule j = new JenkinsRule();
@WithJenkins
class ConfigurationMigrationTest {

@Test
@LocalData
public void testFrom04() throws Exception {
void testFrom04(JenkinsRule j) throws Exception {
j.configRoundtrip();
j.waitUntilNoActivity();

Expand All @@ -38,7 +36,7 @@ public void testFrom04() throws Exception {

@Test
@LocalData
public void testFrom04Empty() throws Exception {
void testFrom04Empty(JenkinsRule j) throws Exception {
j.configRoundtrip();
j.waitUntilNoActivity();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.hasSize;
import static org.htmlunit.WebAssert.assertElementPresentByXPath;
import static org.junit.Assert.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNotNull;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -13,34 +13,32 @@
import org.htmlunit.html.HtmlInput;
import org.htmlunit.html.HtmlPage;
import org.htmlunit.html.HtmlTextArea;
import org.junit.Rule;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.jvnet.hudson.test.JenkinsRule;
import org.jvnet.hudson.test.junit.jupiter.WithJenkins;

public class SimpleThemeConfigurationTest {

@Rule
public JenkinsRule j = new JenkinsRule();
@WithJenkins
class SimpleThemeConfigurationTest {

@Test
public void testConfigRoundTrip() throws Exception {
void testConfigRoundTrip(JenkinsRule j) throws Exception {
SimpleThemeDecorator decorator = j.jenkins.getDescriptorByType(SimpleThemeDecorator.class);
fill(decorator);

configRoundTrip();
configRoundTrip(j);

decorator = j.jenkins.getDescriptorByType(SimpleThemeDecorator.class);

assertNotNull(decorator.getElements());
assertThat(decorator.getElements(), hasSize(4));
}

private void configRoundTrip() throws Exception {
private void configRoundTrip(JenkinsRule j) throws Exception {
j.submit(j.createWebClient().goTo("manage/appearance").getFormByName("config"));
}

@Test
public void testConfigCreatesHtml() throws Exception {
void testConfigCreatesHtml(JenkinsRule j) throws Exception {
SimpleThemeDecorator decorator = j.jenkins.getDescriptorByType(SimpleThemeDecorator.class);
fill(decorator);

Expand Down

0 comments on commit fde72d4

Please sign in to comment.