Skip to content
This repository has been archived by the owner on Apr 6, 2022. It is now read-only.

Commit

Permalink
[JENKINS-14615] Fixed ordering of project actions.
Browse files Browse the repository at this point in the history
  • Loading branch information
uhafner committed Aug 20, 2012
1 parent 687105e commit 9369004
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/main/java/hudson/plugins/warnings/WarningsPublisher.java
Expand Up @@ -253,8 +253,8 @@ public Collection<? extends Action> getProjectActions(final AbstractProject<?, ?
return actions;
}

private Set<String> getParsers() {
Set<String> parsers = Sets.newHashSet();
private List<String> getParsers() {
List<String> parsers = Lists.newArrayList();
for (ConsoleParser configuration : getConsoleParsers()) {
parsers.add(configuration.getParserName());
}
Expand Down
99 changes: 99 additions & 0 deletions src/test/java/hudson/plugins/warnings/WarningsPublisherTest.java
@@ -0,0 +1,99 @@
package hudson.plugins.warnings;

import hudson.model.Action;

import java.util.Collections;
import java.util.List;

import org.junit.Test;
import org.jvnet.hudson.test.HudsonTestCase;

import com.google.common.collect.Lists;

/**
* Tests the class {@link WarningsPublisher}.
*
* @author Ulli Hafner
*/
public class WarningsPublisherTest extends HudsonTestCase {
private static final String SUFFIX_NAME = " Warnings";
private static final String SECOND = "JSLint";
private static final String FIRST = "Maven";
private static final String PATTERN = "Pattern";

/**
* Verifies that the order of warnings is preserved.
*
* @see <a href="http://issues.jenkins-ci.org/browse/JENKINS-14615">Issue 14615</a>
*/
@Test
public void testIssue14615Console() {
List<ConsoleParser> consoleParsers = Lists.newArrayList();
consoleParsers.add(new ConsoleParser(FIRST));
consoleParsers.add(new ConsoleParser(SECOND));

List<String> expected = createExpectedResult();

checkConsoleOrder(consoleParsers, expected);

Collections.reverse(consoleParsers);
Collections.reverse(expected);

checkConsoleOrder(consoleParsers, expected);
}

/**
* Verifies that the order of warnings is preserved.
*
* @see <a href="http://issues.jenkins-ci.org/browse/JENKINS-14615">Issue 14615</a>
*/
@Test
public void testIssue14615File() {
List<ParserConfiguration> fileParsers = Lists.newArrayList();
fileParsers.add(new ParserConfiguration(PATTERN, FIRST));
fileParsers.add(new ParserConfiguration(PATTERN, SECOND));

List<String> expected = createExpectedResult();

checkFileOrder(fileParsers, expected);

Collections.reverse(fileParsers);
Collections.reverse(expected);

checkFileOrder(fileParsers, expected);
}

private List<String> createExpectedResult() {
List<String> expected = Lists.newArrayList();
expected.add(FIRST + SUFFIX_NAME);
expected.add(SECOND + SUFFIX_NAME);
return expected;
}

private void checkFileOrder(final List<ParserConfiguration> fileParsers, final List<String> expected) {
WarningsPublisher publisher = new WarningsPublisher(null, null, null, null, false, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, false, false, false, null, null, false,
fileParsers, null);
checkOrder(expected, publisher);
}

private void checkConsoleOrder(final List<ConsoleParser> consoleParsers, final List<String> expected) {
WarningsPublisher publisher = new WarningsPublisher(null, null, null, null, false, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, false, false, false, null, null, false,
null, consoleParsers);
checkOrder(expected, publisher);
}

private void checkOrder(final List<String> expected, final WarningsPublisher publisher) {
List<Action> ordered = Lists.newArrayList(publisher.getProjectActions(null));

assertEquals("Wrong number of actions.", 2, ordered.size());

for (int position = 0; position < expected.size(); position++) {
assertPosition(ordered, expected, position);
}
}

private void assertPosition(final List<Action> ordered, final List<String> expected, final int position) {
assertEquals("Wrong action at position " + position, expected.get(position), ordered.get(position).getDisplayName());
}
}

0 comments on commit 9369004

Please sign in to comment.