Skip to content
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

Upgrade tests to JUnit5 #279

Open
wants to merge 1 commit 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
118 changes: 72 additions & 46 deletions src/test/java/jenkins/scm/api/SCMCategoryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@

package jenkins.scm.api;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.is;

import edu.umd.cs.findbugs.annotations.NonNull;
import java.util.Arrays;
import java.util.Collections;
Expand All @@ -38,65 +42,79 @@
import jenkins.scm.impl.UncategorizedSCMHeadCategory;
import jenkins.util.NonLocalizable;
import org.hamcrest.Matchers;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.jvnet.localizer.Localizable;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.is;
class SCMCategoryTest {

public class SCMCategoryTest {
@Test
public void toDisplayName() throws Exception {
assertThat(SCMCategory.toDisplayName(UncategorizedSCMHeadCategory.DEFAULT, ChangeRequestSCMHeadCategory.DEFAULT,
TagSCMHeadCategory.DEFAULT).toString(
Locale.ENGLISH), is("Branches / Change requests / Tags"));
assertThat(SCMCategory.toDisplayName(UncategorizedSCMHeadCategory.DEFAULT,
TagSCMHeadCategory.DEFAULT).toString(
Locale.ENGLISH), is("Branches / Tags"));
assertThat(SCMCategory.toDisplayName(UncategorizedSCMHeadCategory.DEFAULT).toString(
Locale.ENGLISH), is("Branches"));
void toDisplayName() {
assertThat(
SCMCategory.toDisplayName(
UncategorizedSCMHeadCategory.DEFAULT,
ChangeRequestSCMHeadCategory.DEFAULT,
TagSCMHeadCategory.DEFAULT)
.toString(Locale.ENGLISH),
is("Branches / Change requests / Tags"));
assertThat(
SCMCategory.toDisplayName(UncategorizedSCMHeadCategory.DEFAULT, TagSCMHeadCategory.DEFAULT)
.toString(Locale.ENGLISH),
is("Branches / Tags"));
assertThat(
SCMCategory.toDisplayName(UncategorizedSCMHeadCategory.DEFAULT).toString(Locale.ENGLISH),
is("Branches"));
}

@Test
public void toDisplayName1() throws Exception {
assertThat(SCMCategory.toDisplayName(Arrays.asList(ChangeRequestSCMHeadCategory.DEFAULT,
TagSCMHeadCategory.DEFAULT, UncategorizedSCMHeadCategory.DEFAULT)).toString(
Locale.ENGLISH), is("Branches / Change requests / Tags"));

void toDisplayName1() {
assertThat(
SCMCategory.toDisplayName(Arrays.asList(
ChangeRequestSCMHeadCategory.DEFAULT,
TagSCMHeadCategory.DEFAULT,
UncategorizedSCMHeadCategory.DEFAULT))
.toString(Locale.ENGLISH),
is("Branches / Change requests / Tags"));
}

@Test
public void toShortUrl() throws Exception {
assertThat(SCMCategory.toShortUrl(UncategorizedSCMHeadCategory.DEFAULT, ChangeRequestSCMHeadCategory.DEFAULT,
TagSCMHeadCategory.DEFAULT), is("change-requests_default_tags"));

void toShortUrl() {
assertThat(
SCMCategory.toShortUrl(
UncategorizedSCMHeadCategory.DEFAULT,
ChangeRequestSCMHeadCategory.DEFAULT,
TagSCMHeadCategory.DEFAULT),
is("change-requests_default_tags"));
}

@Test
public void toShortUrl1() throws Exception {
assertThat(SCMCategory.toShortUrl(Arrays.asList(ChangeRequestSCMHeadCategory.DEFAULT,
TagSCMHeadCategory.DEFAULT, UncategorizedSCMHeadCategory.DEFAULT)), is("change-requests_default_tags"));
assertThat(SCMCategory.toShortUrl(Arrays.asList(TagSCMHeadCategory.DEFAULT, UncategorizedSCMHeadCategory.DEFAULT)), is("default_tags"));
void toShortUrl1() {
assertThat(
SCMCategory.toShortUrl(Arrays.asList(
ChangeRequestSCMHeadCategory.DEFAULT,
TagSCMHeadCategory.DEFAULT,
UncategorizedSCMHeadCategory.DEFAULT)),
is("change-requests_default_tags"));
assertThat(
SCMCategory.toShortUrl(Arrays.asList(TagSCMHeadCategory.DEFAULT, UncategorizedSCMHeadCategory.DEFAULT)),
is("default_tags"));
assertThat(SCMCategory.toShortUrl(Collections.singletonList(TagSCMHeadCategory.DEFAULT)), is("tags"));

}

@Test
public void group() throws Exception {
void group() {
UncategorizedSCMHeadCategory u1 = UncategorizedSCMHeadCategory.DEFAULT;
UncategorizedSCMHeadCategory u2 = new UncategorizedSCMHeadCategory(new NonLocalizable("foo"));
ChangeRequestSCMHeadCategory c1 = ChangeRequestSCMHeadCategory.DEFAULT;
ChangeRequestSCMHeadCategory c2 = new ChangeRequestSCMHeadCategory(new NonLocalizable("bar"));
ChangeRequestSCMHeadCategory c3 = new ChangeRequestSCMHeadCategory(new NonLocalizable("manchu"));
Map<String, List<SCMHeadCategory>> result = SCMCategory.group(u1, c1, c2, c3, u2);
assertThat(result.entrySet(), hasSize(2));
assertThat(result.get("default"), Matchers.<SCMCategory>containsInAnyOrder(u1, u2));
assertThat(result.get("change-requests"), Matchers.<SCMCategory>containsInAnyOrder(c1, c2, c3));
assertThat(result.get("default"), Matchers.containsInAnyOrder(u1, u2));
assertThat(result.get("change-requests"), Matchers.containsInAnyOrder(c1, c2, c3));
}

@Test
public void group1() throws Exception {
void group1() {
UncategorizedSCMHeadCategory u1 = UncategorizedSCMHeadCategory.DEFAULT;
UncategorizedSCMHeadCategory u2 = new UncategorizedSCMHeadCategory(new NonLocalizable("foo"));
ChangeRequestSCMHeadCategory c1 = ChangeRequestSCMHeadCategory.DEFAULT;
Expand All @@ -105,30 +123,39 @@ public void group1() throws Exception {
TagSCMHeadCategory t1 = new TagSCMHeadCategory(new NonLocalizable("foomanchu"));
Map<String, List<SCMHeadCategory>> result = SCMCategory.group(Arrays.asList(u1, c1, t1, c2, c3, u2));
assertThat(result.entrySet(), hasSize(3));
assertThat(result.get("default"), Matchers.<SCMCategory>containsInAnyOrder(u1, u2));
assertThat(result.get("change-requests"), Matchers.<SCMCategory>containsInAnyOrder(c1, c2, c3));
assertThat(result.get("tags"), Matchers.<SCMCategory>contains(t1));

assertThat(result.get("default"), Matchers.containsInAnyOrder(u1, u2));
assertThat(result.get("change-requests"), Matchers.containsInAnyOrder(c1, c2, c3));
assertThat(result.get("tags"), Matchers.contains(t1));
}

@Test
public void getName() throws Exception {
assertThat(new MySCMCategory("foomanchu", new NonLocalizable("Fu Manchu"), new NonLocalizable("Fu Manchu")).getName(), is("foomanchu"));
void getName() {
assertThat(
new MySCMCategory("foomanchu", new NonLocalizable("Fu Manchu"), new NonLocalizable("Fu Manchu"))
.getName(),
is("foomanchu"));
}

@Test
public void getDisplayName() throws Exception {
assertThat(new MySCMCategory("foomanchu", new NonLocalizable("Fu Manchu"), new NonLocalizable("Fu Manchu")).getDisplayName().toString(Locale.ENGLISH), is("Fu Manchu"));
void getDisplayName() {
assertThat(
new MySCMCategory("foomanchu", new NonLocalizable("Fu Manchu"), new NonLocalizable("Fu Manchu"))
.getDisplayName()
.toString(Locale.ENGLISH),
is("Fu Manchu"));
}

@Test
public void defaultDisplayName() throws Exception {
assertThat(new MySCMCategory("foomanchu", null, new NonLocalizable("Fu Manchu"))
.getDisplayName().toString(Locale.ENGLISH), is("Fu Manchu"));
void defaultDisplayName() {
assertThat(
new MySCMCategory("foomanchu", null, new NonLocalizable("Fu Manchu"))
.getDisplayName()
.toString(Locale.ENGLISH),
is("Fu Manchu"));
}

@Test
public void isMatch() throws Exception {
void isMatch() {
UncategorizedSCMHeadCategory u = UncategorizedSCMHeadCategory.DEFAULT;
ChangeRequestSCMHeadCategory c = ChangeRequestSCMHeadCategory.DEFAULT;
TagSCMHeadCategory t = TagSCMHeadCategory.DEFAULT;
Expand Down Expand Up @@ -173,12 +200,11 @@ public SCMHead getTarget() {
assertThat(t.isMatch(mh, Arrays.asList(u, c, t)), is(false));
assertThat(t.isMatch(ch, Arrays.asList(c, u, t)), is(false));
assertThat(t.isMatch(th, Arrays.asList(c, u, t)), is(true));

}

private static class MySCMCategory extends SCMCategory<Object> {

private NonLocalizable defaultDisplayName;
private final NonLocalizable defaultDisplayName;

public MySCMCategory(String name, NonLocalizable displayName, NonLocalizable defaultDisplayName) {
super(name, displayName);
Expand Down
Loading