Skip to content

Commit

Permalink
Merge pull request #37 from ikedam/feature/JENKINS-52043_ReproduceRem…
Browse files Browse the repository at this point in the history
…oveBadgeIssue

[JENKINS-52043] Add tests to reproduce issues of removeBadge / removeBadges
  • Loading branch information
ikedam authored Aug 11, 2018
2 parents 0d5a125 + a13b784 commit 29b7463
Showing 1 changed file with 56 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@
import org.jvnet.hudson.test.UnstableBuilder;
import org.jvnet.hudson.test.recipes.LocalData;

import com.google.common.base.Function;
import com.google.common.collect.Lists;
import com.jenkinsci.plugins.badge.action.BadgeAction;
import com.jenkinsci.plugins.badge.action.BadgeSummaryAction;

Expand Down Expand Up @@ -487,4 +489,58 @@ public void testBadgeMigration() throws Exception {
assertEquals("<b>summaryText</b>", badgeSummaryAction.getText());
}
}

@Test
public void testRemoveBadge() throws Exception {
FreeStyleProject p = j.createFreeStyleProject();

p.getPublishersList().add(new GroovyPostbuildRecorder(
new SecureGroovyScript(
"manager.addShortText('test1');\n"
+ "manager.addShortText('test2');\n"
+ "manager.removeBadge(0);",
true, // sandbox
Collections.<ClasspathEntry>emptyList()
),
2, // behavior
false // runForMatrixParent
));

FreeStyleBuild b = j.assertBuildStatusSuccess(p.scheduleBuild2(0));
assertEquals(
Arrays.asList("test2"),
Lists.transform(
b.getActions(BadgeAction.class),
new Function<BadgeAction, String>() {
@Override
public String apply(BadgeAction badge) {
return badge.getText();
}
}
)
);
}

@Test
public void testRemoveBadges() throws Exception {
FreeStyleProject p = j.createFreeStyleProject();

p.getPublishersList().add(new GroovyPostbuildRecorder(
new SecureGroovyScript(
"manager.addShortText('test1');\n"
+ "manager.addShortText('test2');\n"
+ "manager.removeBadges();",
true, // sandbox
Collections.<ClasspathEntry>emptyList()
),
2, // behavior
false // runForMatrixParent
));

FreeStyleBuild b = j.assertBuildStatusSuccess(p.scheduleBuild2(0));
assertEquals(
Collections.emptyList(),
b.getActions(BadgeAction.class)
);
}
}

0 comments on commit 29b7463

Please sign in to comment.