Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -61,40 +61,43 @@ public class DeflakeAction implements Action {
private static final String PLUS = "+";

private static final Function<Map.Entry<String, Set<String>>, String>
CLASS_METHOD_MAP_TO_MAVEN_TESTS_LIST = new Function<Entry<String, Set<String>>, String>() {
CLASS_METHOD_MAP_TO_MAVEN_TESTS_LIST = new Function<>() {

@Override
@Nonnull
public String apply(@Nonnull Entry<String, Set<String>> entry) {
return entry.getKey() + SHARP + Joiner.on(PLUS).join(entry.getValue());
}
@Override
@Nonnull
public String apply(@Nonnull Entry<String, Set<String>> entry) {
return entry.getKey() + SHARP + Joiner.on(PLUS).join(entry.getValue());
}
};

private final Map<String, Set<String>> failingClassMethodMap;

public DeflakeAction(Map<String, Set<String>> failingClassMethodMap) {
private final Run run;

public DeflakeAction(Run run, Map<String, Set<String>> failingClassMethodMap) {
this.run = run;
this.failingClassMethodMap = failingClassMethodMap;
}

@Override
public String getIconFileName() {
if (Jenkins.get().hasPermission(Item.BUILD)) {
if (Jenkins.get().hasPermission(Item.BUILD) || run.getParent().hasPermission(Item.BUILD)) {
return "clock.png";
}
return null;
}

@Override
public String getDisplayName() {
if (Jenkins.get().hasPermission(Item.BUILD)) {
if (Jenkins.get().hasPermission(Item.BUILD) || run.getParent().hasPermission(Item.BUILD)) {
return "Deflake this build";
}
return null;
}

@Override
public String getUrlName() {
if (Jenkins.get().hasPermission(Item.BUILD)) {
if (Jenkins.get().hasPermission(Item.BUILD) || run.getParent().hasPermission(Item.BUILD)) {
return "deflake";
}
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public void onCompleted(Run run, TaskListener listener) {
if (testResultAction != null && testResultAction.getFailCount() > 0) {
// Only add deflake action if there are test failures
run.addAction(
new DeflakeAction(getFailingTestClassMethodMap(testResultAction.getFailedTests())));
new DeflakeAction(run, getFailingTestClassMethodMap(testResultAction.getFailedTests())));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@

import com.google.common.collect.Sets;

import hudson.model.FreeStyleBuild;
import hudson.model.FreeStyleProject;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.JenkinsRule;

import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;
import java.io.IOException;
import java.util.*;

public class DeflakeActionTest {

Expand All @@ -34,16 +36,19 @@ public class DeflakeActionTest {
private final static String TEST_METHOD_TWO = "methodTwo";
private final static String TEST_METHOD_THREE = "methodThree";

@Rule
public JenkinsRule jenkins = new JenkinsRule();

@Test
public void testGenerateMavenTestParamsForSingleTest() {
public void testGenerateMavenTestParamsForSingleTest() throws IOException {
Map<String, Set<String>> classMethodMap = new LinkedHashMap<String, Set<String>>();
classMethodMap.put(TEST_CLASS_TWO, Sets.newHashSet(TEST_METHOD_THREE));
testGenerateMavenTestParams(classMethodMap, "classTwo#methodThree",
"Wrong test parameters for single test class");
}

@Test
public void testGenerateMavenTestParamsForMultipleTests() {
public void testGenerateMavenTestParamsForMultipleTests() throws IOException {
Map<String, Set<String>> classMethodMap = new LinkedHashMap<String, Set<String>>();
classMethodMap.put(TEST_CLASS_ONE,
Sets.newLinkedHashSet(Arrays.asList(TEST_METHOD_ONE, TEST_METHOD_TWO)));
Expand All @@ -53,8 +58,10 @@ public void testGenerateMavenTestParamsForMultipleTests() {
}

private void testGenerateMavenTestParams(Map<String, Set<String>> classMethodMap,
String expectedTestParam, String errorMsg) {
DeflakeAction action = new DeflakeAction(classMethodMap);
String expectedTestParam, String errorMsg) throws IOException {
FreeStyleProject project = jenkins.createFreeStyleProject("project");
FreeStyleBuild build = new FreeStyleBuild(project);
DeflakeAction action = new DeflakeAction(build, classMethodMap);
assertEquals(errorMsg, expectedTestParam,
action.generateMavenTestParams());
}
Expand Down