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

Create GreenBallFilter.java #18

Open
wants to merge 2 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
6 changes: 3 additions & 3 deletions src/main/java/hudson/plugins/greenballs/GreenBallFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,11 @@ private String mapImage(String uri) {
ColorBlindProperty colorBlindProperty = user.getProperty(ColorBlindProperty.class);
if (colorBlindProperty != null && colorBlindProperty.isEnabledColorBlindSupport()) {
if ((m = patternBlue.matcher(uri)).find()) {
return basePath + "colorblind" + m.group(1) + "/green" + m.group(2) + ".gif";
return basePath + "colorblind" + "/" + m.group(1) + "/green" + m.group(2) + ".gif";
} else if ((m = patternRed.matcher(uri)).find()) {
return basePath + "colorblind" + m.group(1) + "/red" + m.group(2) + ".gif";
return basePath + "colorblind" + "/" + m.group(1) + "/red" + m.group(2) + ".gif";
} else if ((m = patternYellow.matcher(uri)).find()) {
return basePath + "colorblind" + m.group(1) + "/yellow" + m.group(2) + ".gif";
return basePath + "colorblind" + "/" + m.group(1) + "/yellow" + m.group(2) + ".gif";
}
return null;
}
Expand Down
34 changes: 33 additions & 1 deletion src/test/java/hudson/plugins/greenballs/GreenBallFilterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,18 @@ static void patternMatchAnime(Matcher m) {
assertThat(m.group(2), equalTo("_anime"));
}

static void patternMatchColorblind(Matcher m) {
assertThat(m.find(), is(true));
assertThat(m.group(1), equalTo("48x48"));
assertThat(m.group(2), equalTo(""));
}

static void patternMatchColorblindAnime(Matcher m) {
assertThat(m.find(), is(true));
assertThat(m.group(1), equalTo("48x48"));
assertThat(m.group(2), equalTo("_anime"));
}

@Test
public void patternShouldMatch() {
final Matcher m = GreenBallFilter.patternBlue.matcher("/nocacheImages/48x48/blue.gif");
Expand Down Expand Up @@ -69,4 +81,24 @@ public void patternShouldNotMatch() {
final Matcher m3 = GreenBallFilter.patternRed.matcher("/nocacheImages/48x48/yello_anime.gif");
assertThat(m3.find(), is(false));
}
}

@Test
public void patternShouldMatchColorblind() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As test I mean a request done to the filter to load blue.gif image returns a correct URL to the green gif image
create a variable JenkinsRule and than you can navigate rule.createWebClient().goTo("/nocacheImages/colorblind/48x48/blue.gif") for example and the URL it returns

final Matcher m = GreenBallFilter.patternBlue.matcher("/nocacheImages/colorblind/48x48/blue.gif");
final Matcher m2 = GreenBallFilter.patternYellow.matcher("/nocacheImages/colorblind/48x48/yellow.gif");
final Matcher m3 = GreenBallFilter.patternRed.matcher("/nocacheImages/colorblind/48x48/red.gif");
patternMatchColorblind(m);
patternMatchColorblind(m2);
patternMatchColorblind(m3);
}

@Test
public void patternShouldMatchColorblindAnime() {
final Matcher m = GreenBallFilter.patternBlue.matcher("/nocacheImages/colorblind/48x48/blue_anime.gif");
final Matcher m2 = GreenBallFilter.patternYellow.matcher("/nocacheImages/colorblind/48x48/yellow_anime.gif");
final Matcher m3 = GreenBallFilter.patternRed.matcher("/nocacheImages/colorblind/48x48/red_anime.gif");
patternMatchColorblindAnime(m);
patternMatchColorblindAnime(m2);
patternMatchColorblindAnime(m3);
}
}