Skip to content

Commit

Permalink
Fix JENKINS-24395
Browse files Browse the repository at this point in the history
Change to using getAction instead of getTestResultAction
  • Loading branch information
Alex Earl committed Aug 26, 2014
1 parent 628b7d5 commit 64c5d6f
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 19 deletions.
Expand Up @@ -136,7 +136,7 @@ protected EmailType createMailType(StaplerRequest req, JSONObject formData) {
* results aren't available yet, but those of the previous build may be.
*/
protected int getNumFailures(AbstractBuild<?, ?> build) {
AbstractTestResultAction a = build.getTestResultAction();
AbstractTestResultAction a = build.getAction(AbstractTestResultAction.class);
if (a instanceof AggregatedTestResultAction) {
int result = 0;
AggregatedTestResultAction action = (AggregatedTestResultAction) a;
Expand Down
Expand Up @@ -44,7 +44,7 @@ public String evaluate(AbstractBuild<?, ?> build, TaskListener listener, String
throws MacroEvaluationException, IOException, InterruptedException {

StringBuilder buffer = new StringBuilder();
AbstractTestResultAction<?> testResult = build.getTestResultAction();
AbstractTestResultAction<?> testResult = build.getAction(AbstractTestResultAction.class);

if (null == testResult) {
return "No tests ran.";
Expand Down
Expand Up @@ -47,7 +47,7 @@ public String getHelpText() {
public String evaluate(AbstractBuild<?, ?> build, TaskListener listener, String macroName)
throws MacroEvaluationException, IOException, InterruptedException {

AbstractTestResultAction<?> action = build.getTestResultAction();
AbstractTestResultAction<?> action = build.getAction(AbstractTestResultAction.class);
if (action == null) {
return "";
}
Expand Down
Expand Up @@ -11,6 +11,7 @@
import hudson.plugins.emailext.plugins.recipients.ListRecipientProvider;
import java.util.List;

import hudson.tasks.test.AbstractTestResultAction;
import org.kohsuke.stapler.DataBoundConstructor;

public class ImprovementTrigger extends EmailTrigger {
Expand All @@ -33,16 +34,16 @@ public boolean trigger(AbstractBuild<?, ?> build, TaskListener listener) {

if (previousBuild == null)
return false;
if (build.getTestResultAction() == null) return false;
if (previousBuild.getTestResultAction() == null)
if (build.getAction(AbstractTestResultAction.class) == null) return false;
if (previousBuild.getAction(AbstractTestResultAction.class) == null)
return false;

int numCurrFailures = getNumFailures(build);

// The first part of the condition avoids accidental triggering for
// builds that aggregate downstream test results before those test
// results are available...
return build.getTestResultAction().getTotalCount() > 0
return build.getAction(AbstractTestResultAction.class).getTotalCount() > 0
&& numCurrFailures < getNumFailures(previousBuild)
&& numCurrFailures > 0;
}
Expand Down
Expand Up @@ -12,6 +12,7 @@
import hudson.plugins.emailext.plugins.recipients.ListRecipientProvider;
import java.util.List;

import hudson.tasks.test.AbstractTestResultAction;
import org.kohsuke.stapler.DataBoundConstructor;


Expand All @@ -34,12 +35,12 @@ public boolean trigger(AbstractBuild<?, ?> build, TaskListener listener) {
AbstractBuild<?,?> previousBuild = ExtendedEmailPublisher.getPreviousBuild(build, listener);
if (previousBuild == null)
return build.getResult() == Result.FAILURE;
if (build.getTestResultAction() == null) return false;
if (previousBuild.getTestResultAction() == null)
return build.getTestResultAction().getFailCount() > 0;
if (build.getAction(AbstractTestResultAction.class) == null) return false;
if (previousBuild.getAction(AbstractTestResultAction.class) == null)
return build.getAction(AbstractTestResultAction.class).getFailCount() > 0;

return build.getTestResultAction().getFailCount() >
previousBuild.getTestResultAction().getFailCount();
return build.getAction(AbstractTestResultAction.class).getFailCount() >
previousBuild.getAction(AbstractTestResultAction.class).getFailCount();
}

@Extension
Expand Down
Expand Up @@ -53,7 +53,7 @@ public void testGetContent_whenAllTestsPassedShouldGiveMeaningfulMessage()
AbstractTestResultAction testResults = mock( AbstractTestResultAction.class );
when( testResults.getFailCount() ).thenReturn( 0 );

when( build.getTestResultAction() ).thenReturn( testResults );
when( build.getAction(AbstractTestResultAction.class) ).thenReturn( testResults );

String content = failedTestContent.evaluate( build, listener, FailedTestsContent.MACRO_NAME );

Expand All @@ -66,7 +66,7 @@ public void testGetContent_whenSomeTestsFailedShouldGiveMeaningfulMessage()
AbstractTestResultAction<?> testResults = mock( AbstractTestResultAction.class );
when( testResults.getFailCount() ).thenReturn( 123 );

when( build.getTestResultAction() ).thenReturn( testResults );
when( build.getAction(AbstractTestResultAction.class) ).thenReturn( testResults );

failedTestContent.maxTests = 0;
String content = failedTestContent.evaluate( build, listener, FailedTestsContent.MACRO_NAME );
Expand All @@ -91,7 +91,7 @@ public void testGetContent_withMessage_withStack()
failedTests.add(result);
}
when( testResults.getFailedTests() ).thenReturn( failedTests );
when( build.getTestResultAction() ).thenReturn( testResults );
when( build.getAction(AbstractTestResultAction.class) ).thenReturn( testResults );

failedTestContent.maxTests = 2;
failedTestContent.showMessage = true;
Expand Down Expand Up @@ -122,7 +122,7 @@ public void testGetContent_noMessage_withStack()
failedTests.add(result);
}
when( testResults.getFailedTests() ).thenReturn( failedTests );
when( build.getTestResultAction() ).thenReturn( testResults );
when( build.getAction(AbstractTestResultAction.class) ).thenReturn( testResults );

failedTestContent.maxTests = 2;
failedTestContent.showMessage = false;
Expand Down Expand Up @@ -153,7 +153,7 @@ public void testGetContent_withMessage_noStack()
failedTests.add(result);
}
when( testResults.getFailedTests() ).thenReturn( failedTests );
when( build.getTestResultAction() ).thenReturn( testResults );
when( build.getAction(AbstractTestResultAction.class) ).thenReturn( testResults );

failedTestContent.maxTests = 2;
failedTestContent.showMessage = true;
Expand Down Expand Up @@ -184,7 +184,7 @@ public void testGetContent_noMessage_noStack()
failedTests.add(result);
}
when( testResults.getFailedTests() ).thenReturn( failedTests );
when( build.getTestResultAction() ).thenReturn( testResults );
when( build.getAction(AbstractTestResultAction.class) ).thenReturn( testResults );

failedTestContent.maxTests = 2;
failedTestContent.showMessage = false;
Expand Down Expand Up @@ -215,7 +215,7 @@ public void testGetContent_whenContentLargerThanMaxLengthShouldTruncate()
failedTests.add(result);
}
when( testResults.getFailedTests() ).thenReturn( failedTests );
when( build.getTestResultAction() ).thenReturn( testResults );
when( build.getAction(AbstractTestResultAction.class) ).thenReturn( testResults );

failedTestContent.maxLength = 10;
String content = failedTestContent.evaluate( build, listener, FailedTestsContent.MACRO_NAME );
Expand Down
Expand Up @@ -47,7 +47,7 @@ public void testGetContent() throws Exception {
when(results.getTotalCount() - results.getFailCount() - results.getSkipCount()).thenReturn(2);
when(results.getFailCount()).thenReturn(2);
when(results.getSkipCount()).thenReturn(1);
when(build.getTestResultAction()).thenReturn(results);
when(build.getAction(AbstractTestResultAction.class)).thenReturn(results);

assertEquals("5", target.evaluate(build, listener, TestCountsContent.MACRO_NAME));
target.var = "total";
Expand Down

0 comments on commit 64c5d6f

Please sign in to comment.