Skip to content

Migrate tests to JUnit5 #509

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
11 changes: 0 additions & 11 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,6 @@
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>pl.pragmatists</groupId>
<artifactId>JUnitParams</artifactId>
<version>1.1.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>scm-api</artifactId>
Expand All @@ -139,11 +133,6 @@
<classifier>tests</classifier>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<repositories>
Expand Down
81 changes: 44 additions & 37 deletions src/test/java/integration/BrandingTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@

package integration;

import org.htmlunit.html.HtmlAnchor;
import org.htmlunit.html.HtmlPage;
import edu.umd.cs.findbugs.annotations.NonNull;
import hudson.Extension;
import hudson.model.Action;
Expand All @@ -42,11 +40,6 @@
import hudson.views.WeatherColumn;
import integration.harness.BasicMultiBranchProject;
import integration.harness.BasicMultiBranchProjectFactory;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import jenkins.branch.Branch;
import jenkins.branch.BranchIndexingCause;
import jenkins.branch.BranchSource;
Expand All @@ -65,11 +58,20 @@
import jenkins.scm.impl.mock.MockSCMNavigator;
import jenkins.scm.impl.mock.MockSCMSource;
import jenkins.scm.impl.mock.MockSCMSourceEvent;
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Test;
import org.htmlunit.html.HtmlAnchor;
import org.htmlunit.html.HtmlPage;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.jvnet.hudson.test.Issue;
import org.jvnet.hudson.test.JenkinsRule;
import org.jvnet.hudson.test.junit.jupiter.WithJenkins;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.allOf;
Expand All @@ -82,24 +84,29 @@
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.nullValue;

public class BrandingTest {
@WithJenkins
class BrandingTest {

/**
* All tests in this class only create items and do not affect other global configuration, thus we trade test
* execution time for the restriction on only touching items.
*/
@ClassRule
public static JenkinsRule r = new JenkinsRule();
private static JenkinsRule r;

@BeforeAll
static void setUp(JenkinsRule rule) {
r = rule;
}

@Before
public void cleanOutAllItems() throws Exception {
@BeforeEach
void setUp() throws Exception {
for (TopLevelItem i : r.getInstance().getItems()) {
i.delete();
}
}

@Test
public void given_multibranch_when_noSourcesDefined_then_noSourceBrandingPresent() throws Exception {
void given_multibranch_when_noSourcesDefined_then_noSourceBrandingPresent() throws Exception {
try (MockSCMController c = MockSCMController.create()) {
BasicMultiBranchProject prj = r.jenkins.createProject(BasicMultiBranchProject.class, "foo");
prj.setCriteria(null);
Expand All @@ -108,7 +115,7 @@ public void given_multibranch_when_noSourcesDefined_then_noSourceBrandingPresent
}

@Test
public void given_multibranch_when_sourceDefined_then_sourceBrandingPresentAfterIndexing()
void given_multibranch_when_sourceDefined_then_sourceBrandingPresentAfterIndexing()
throws Exception {
try (MockSCMController c = MockSCMController.create()) {
c.createRepository("foo");
Expand All @@ -123,7 +130,7 @@ public void given_multibranch_when_sourceDefined_then_sourceBrandingPresentAfter
}

@Test
public void given_multibranch_when_sourceDefined_then_sourceBrandingPresentAfterSourceEvent()
void given_multibranch_when_sourceDefined_then_sourceBrandingPresentAfterSourceEvent()
throws Exception {
try (MockSCMController c = MockSCMController.create()) {
c.createRepository("foo");
Expand All @@ -138,7 +145,7 @@ public void given_multibranch_when_sourceDefined_then_sourceBrandingPresentAfter
}

@Test
public void given_multibranch_when_branches_then_branchBrandingPresent()
void given_multibranch_when_branches_then_branchBrandingPresent()
throws Exception {
try (MockSCMController c = MockSCMController.create()) {
c.createRepository("foo");
Expand All @@ -152,7 +159,7 @@ public void given_multibranch_when_branches_then_branchBrandingPresent()
}

@Test
public void given_multibranch_when_branches_then_runBrandingPresent()
void given_multibranch_when_branches_then_runBrandingPresent()
throws Exception {
try (MockSCMController c = MockSCMController.create()) {
c.createRepository("foo");
Expand All @@ -169,7 +176,7 @@ public void given_multibranch_when_branches_then_runBrandingPresent()

@Test
@Issue("JENKINS-48090")
public void given_multibranch_when_runBrandingIncludesAdditionalCauses_then_causesMerged() throws Exception {
void given_multibranch_when_runBrandingIncludesAdditionalCauses_then_causesMerged() throws Exception {
try (MockSCMController c = MockSCMController.create()) {
c.createRepository("foo");
BasicMultiBranchProject prj = r.jenkins.createProject(BasicMultiBranchProject.class, "foo");
Expand All @@ -188,15 +195,15 @@ public void given_multibranch_when_runBrandingIncludesAdditionalCauses_then_caus
}

@Test
public void given_orgFolder_when_noNavigatorsDefined_then_noNavigatorBrandingPresent() throws Exception {
void given_orgFolder_when_noNavigatorsDefined_then_noNavigatorBrandingPresent() throws Exception {
try (MockSCMController c = MockSCMController.create()) {
OrganizationFolder prj = r.jenkins.createProject(OrganizationFolder.class, "foo");
assertThat(prj.getAction(MockSCMLink.class), nullValue());
}
}

@Test
public void given_multibranch_when_sourceHasNonSafeNames_then_branchDisplayNameNotMangled() throws Exception {
void given_multibranch_when_sourceHasNonSafeNames_then_branchDisplayNameNotMangled() throws Exception {
try (MockSCMController c = MockSCMController.create()) {
c.createRepository("foo");
c.createBranch("foo", ".");
Expand Down Expand Up @@ -258,7 +265,7 @@ public void given_multibranch_when_sourceHasNonSafeNames_then_branchDisplayNameN
}

@Test
public void given_multibranch_when_sourceHasI18nNames_then_branchDisplayNameNotMangled() throws Exception {
void given_multibranch_when_sourceHasI18nNames_then_branchDisplayNameNotMangled() throws Exception {
try (MockSCMController c = MockSCMController.create()) {
c.createRepository("foo");
c.createBranch("foo","特征/新");
Expand Down Expand Up @@ -347,7 +354,7 @@ public void given_multibranch_when_sourceHasI18nNames_then_branchDisplayNameNotM
}

@Test
public void given_orgFolder_when_navigatorDefined_then_navigatorBrandingPresentAfterIndexing()
void given_orgFolder_when_navigatorDefined_then_navigatorBrandingPresentAfterIndexing()
throws Exception {
try (MockSCMController c = MockSCMController.create()) {
c.createRepository("foo");
Expand All @@ -362,7 +369,7 @@ public void given_orgFolder_when_navigatorDefined_then_navigatorBrandingPresentA
}

@Test
public void given_orgFolderWithI18nRepos_when_indexing_then_repoNamesEncoded()
void given_orgFolderWithI18nRepos_when_indexing_then_repoNamesEncoded()
throws Exception {
try (MockSCMController c = MockSCMController.create()) {
c.createRepository("England");
Expand Down Expand Up @@ -437,7 +444,7 @@ public void given_orgFolderWithI18nRepos_when_indexing_then_repoNamesEncoded()
}

@Test
public void given_orgFolderWithNonSafeRepos_when_indexing_then_repoNamesEncoded()
void given_orgFolderWithNonSafeRepos_when_indexing_then_repoNamesEncoded()
throws Exception {
try (MockSCMController c = MockSCMController.create()) {
c.createRepository("a?");
Expand Down Expand Up @@ -482,7 +489,7 @@ public void given_orgFolderWithNonSafeRepos_when_indexing_then_repoNamesEncoded(
}

@Test
public void given_orgFolder_when_navigatorDefined_then_sourceBrandingPresentAfterIndexing()
void given_orgFolder_when_navigatorDefined_then_sourceBrandingPresentAfterIndexing()
throws Exception {
try (MockSCMController c = MockSCMController.create()) {
c.createRepository("foo");
Expand All @@ -497,7 +504,7 @@ public void given_orgFolder_when_navigatorDefined_then_sourceBrandingPresentAfte
}

@Test
public void given_orgFolder_when_navigatorDefined_then_branchBrandingPresentAfterIndexing()
void given_orgFolder_when_navigatorDefined_then_branchBrandingPresentAfterIndexing()
throws Exception {
try (MockSCMController c = MockSCMController.create()) {
c.createRepository("foo");
Expand All @@ -513,7 +520,7 @@ public void given_orgFolder_when_navigatorDefined_then_branchBrandingPresentAfte
}

@Test
public void given_orgFolder_when_navigatorDefined_then_revisionBrandingPresentAfterIndexing()
void given_orgFolder_when_navigatorDefined_then_revisionBrandingPresentAfterIndexing()
throws Exception {
try (MockSCMController c = MockSCMController.create()) {
c.createRepository("foo");
Expand All @@ -529,7 +536,7 @@ public void given_orgFolder_when_navigatorDefined_then_revisionBrandingPresentAf
}

@Test
public void given_multibranch_when_decoratedSourceDefined_then_descriptionPresentAfterIndexing()
void given_multibranch_when_decoratedSourceDefined_then_descriptionPresentAfterIndexing()
throws Exception {
try (MockSCMController c = MockSCMController.create()) {
c.createRepository("foo");
Expand All @@ -545,7 +552,7 @@ public void given_multibranch_when_decoratedSourceDefined_then_descriptionPresen
}

@Test
public void given_multibranch_when_decoratedSourceDefined_then_displayNamePresentAfterIndexing()
void given_multibranch_when_decoratedSourceDefined_then_displayNamePresentAfterIndexing()
throws Exception {
try (MockSCMController c = MockSCMController.create()) {
c.createRepository("foo");
Expand All @@ -564,7 +571,7 @@ public void given_multibranch_when_decoratedSourceDefined_then_displayNamePresen
}

@Test
public void given_orgFolder_when_decoratedSourceDefined_then_descriptionLinkPresentAfterIndexing()
void given_orgFolder_when_decoratedSourceDefined_then_descriptionLinkPresentAfterIndexing()
throws Exception {
try (MockSCMController c = MockSCMController.create()) {
c.createRepository("foo");
Expand All @@ -588,7 +595,7 @@ public void given_orgFolder_when_decoratedSourceDefined_then_descriptionLinkPres
}

@Test
public void given_multibranch_when_decoratedSourceDefined_then_folderIconPresentAfterIndexing()
void given_multibranch_when_decoratedSourceDefined_then_folderIconPresentAfterIndexing()
throws Exception {
try (MockSCMController c = MockSCMController.create()) {
c.createRepository("foo");
Expand All @@ -604,7 +611,7 @@ public void given_multibranch_when_decoratedSourceDefined_then_folderIconPresent
}

@Test
public void given_orgFolder_when_decoratedOrganizationDefined_then_folderIconPresentAfterIndexing()
void given_orgFolder_when_decoratedOrganizationDefined_then_folderIconPresentAfterIndexing()
throws Exception {
try (MockSCMController c = MockSCMController.create()) {
c.createRepository("foo");
Expand All @@ -620,7 +627,7 @@ public void given_orgFolder_when_decoratedOrganizationDefined_then_folderIconPre
}

@Test
public void given_orgFolder_when_decoratedOrganizationDefined_then_displayNamePresentAfterIndexing()
void given_orgFolder_when_decoratedOrganizationDefined_then_displayNamePresentAfterIndexing()
throws Exception {
try (MockSCMController c = MockSCMController.create()) {
c.createRepository("foo");
Expand All @@ -636,7 +643,7 @@ public void given_orgFolder_when_decoratedOrganizationDefined_then_displayNamePr
}

@Test
public void given_orgFolder_when_decoratedOrganizationDefined_then_descriptionLinkPresentAfterIndexing()
void given_orgFolder_when_decoratedOrganizationDefined_then_descriptionLinkPresentAfterIndexing()
throws Exception {
try (MockSCMController c = MockSCMController.create()) {
c.createRepository("foo");
Expand Down
36 changes: 21 additions & 15 deletions src/test/java/integration/CategorizationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,11 @@
import jenkins.scm.impl.mock.MockSCMDiscoverChangeRequests;
import jenkins.scm.impl.mock.MockSCMDiscoverTags;
import jenkins.scm.impl.mock.MockSCMSource;
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.jvnet.hudson.test.JenkinsRule;
import org.jvnet.hudson.test.junit.jupiter.WithJenkins;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.allOf;
Expand All @@ -54,24 +55,29 @@
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.is;

public class CategorizationTest {
@WithJenkins
class CategorizationTest {

/**
* All tests in this class only create items and do not affect other global configuration, thus we trade test
* execution time for the restriction on only touching items.
*/
@ClassRule
public static JenkinsRule r = new JenkinsRule();
private static JenkinsRule r;

@Before
public void cleanOutAllItems() throws Exception {
@BeforeAll
static void setUp(JenkinsRule rule) {
r = rule;
}

@BeforeEach
void setUp() throws Exception {
for (TopLevelItem i : r.getInstance().getItems()) {
i.delete();
}
}

@Test
public void given_multibranch_when_noSourcesDefined_then_welcomeViewPresent() throws Exception {
void given_multibranch_when_noSourcesDefined_then_welcomeViewPresent() throws Exception {
try (MockSCMController c = MockSCMController.create()) {
BasicMultiBranchProject prj = r.jenkins.createProject(BasicMultiBranchProject.class, "foo");
prj.setCriteria(null);
Expand All @@ -82,7 +88,7 @@ public void given_multibranch_when_noSourcesDefined_then_welcomeViewPresent() th
}

@Test
public void given_multibranch_when_atLeastOneSourceDefinedButNoItems_then_welcomeViewPresent()
void given_multibranch_when_atLeastOneSourceDefinedButNoItems_then_welcomeViewPresent()
throws Exception {
try (MockSCMController c = MockSCMController.create()) {
c.createRepository("foo");
Expand All @@ -96,7 +102,7 @@ public void given_multibranch_when_atLeastOneSourceDefinedButNoItems_then_welcom
}

@Test
public void given_multibranch_when_onlyUncategorizedCategory_then_onlyUncategorizedViewPresent() throws Exception {
void given_multibranch_when_onlyUncategorizedCategory_then_onlyUncategorizedViewPresent() throws Exception {
try (MockSCMController c = MockSCMController.create()) {
c.createRepository("foo");
c.createTag("foo", "master", "master-1.0");
Expand All @@ -122,7 +128,7 @@ public void given_multibranch_when_onlyUncategorizedCategory_then_onlyUncategori
}

@Test
public void given_multibranch_when_changeRequestsWanted_then_onlyUncategorizedAndChangeRequetsViewsPresent()
void given_multibranch_when_changeRequestsWanted_then_onlyUncategorizedAndChangeRequetsViewsPresent()
throws Exception {
try (MockSCMController c = MockSCMController.create()) {
c.createRepository("foo");
Expand Down Expand Up @@ -156,7 +162,7 @@ public void given_multibranch_when_changeRequestsWanted_then_onlyUncategorizedAn
}

@Test
public void given_multibranch_when_tagsWanted_then_onlyUncategorizedAndTagsViewsPresent()
void given_multibranch_when_tagsWanted_then_onlyUncategorizedAndTagsViewsPresent()
throws Exception {
try (MockSCMController c = MockSCMController.create()) {
c.createRepository("foo");
Expand Down Expand Up @@ -190,7 +196,7 @@ public void given_multibranch_when_tagsWanted_then_onlyUncategorizedAndTagsViews
}

@Test
public void given_multibranch_when_noBranchesWanted_then_uncategorizedViewPresentButEmpty()
void given_multibranch_when_noBranchesWanted_then_uncategorizedViewPresentButEmpty()
throws Exception {
try (MockSCMController c = MockSCMController.create()) {
c.createRepository("foo");
Expand Down Expand Up @@ -229,7 +235,7 @@ public void given_multibranch_when_noBranchesWanted_then_uncategorizedViewPresen
}

@Test
public void given_multibranch_when_wantsEverything_then_hasEverything()
void given_multibranch_when_wantsEverything_then_hasEverything()
throws Exception {
try (MockSCMController c = MockSCMController.create()) {
c.createRepository("foo");
Expand Down
Loading
Loading