Skip to content

Commit

Permalink
Merge pull request #645 from thesam/issue15380
Browse files Browse the repository at this point in the history
[FIXED JENKINS-15380]. Add some length checking before trying to substring names in ClassResult.
  • Loading branch information
kutzi committed Jun 15, 2013
2 parents 3431a7c + 65c98e0 commit 029701c
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 7 deletions.
12 changes: 5 additions & 7 deletions core/src/main/java/hudson/tasks/junit/ClassResult.java
Expand Up @@ -80,20 +80,18 @@ public ClassResult getPreviousResult() {
@Override
public hudson.tasks.test.TestResult findCorrespondingResult(String id) {
String myID = safe(getName());
String caseName = id;
int base = id.indexOf(myID);
String caseName;
if (base > 0) {
int caseNameStart = base + myID.length() + 1;
caseName = id.substring(caseNameStart);
} else {
caseName = id;
}

if (id.length() > caseNameStart) {
caseName = id.substring(caseNameStart);
}
}
CaseResult child = getCaseResult(caseName);
if (child != null) {
return child;
}

return null;
}

Expand Down
41 changes: 41 additions & 0 deletions core/src/test/java/hudson/tasks/junit/ClassResultTest.java
@@ -0,0 +1,41 @@
package hudson.tasks.junit;

import hudson.tasks.test.TestResult;
import junit.framework.TestCase;

public class ClassResultTest extends TestCase {

public void testFindCorrespondingResult() {
ClassResult classResult = new ClassResult(null, "com.example.ExampleTest");

CaseResult caseResult = new CaseResult(null, "testCase", null);

classResult.add(caseResult);

TestResult result = classResult.findCorrespondingResult("extraprefix.com.example.ExampleTest.testCase");
assertEquals(caseResult, result);
}

public void testFindCorrespondingResultWhereClassResultNameIsNotSubstring() {
ClassResult classResult = new ClassResult(null, "aaaa");

CaseResult caseResult = new CaseResult(null, "tc_bbbb", null);

classResult.add(caseResult);

TestResult result = classResult.findCorrespondingResult("tc_bbbb");
assertEquals(caseResult, result);
}

public void testFindCorrespondingResultWhereClassResultNameIsLastInCaseResultName() {
ClassResult classResult = new ClassResult(null, "aaaa");

CaseResult caseResult = new CaseResult(null, "tc_aaaa", null);

classResult.add(caseResult);

TestResult result = classResult.findCorrespondingResult("tc_aaaa");
assertEquals(caseResult, result);
}

}

0 comments on commit 029701c

Please sign in to comment.