Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #769 from dnadolny/master
[FIXED JENKINS-17478] Add extension point to rewrite JUnit test names
- Loading branch information
Showing
11 changed files
with
94 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
core/src/main/java/hudson/tasks/junit/TestNameTransformer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package hudson.tasks.junit; | ||
|
||
import hudson.ExtensionList; | ||
import hudson.ExtensionPoint; | ||
import jenkins.model.Jenkins; | ||
|
||
/** | ||
* Allow extensions to transform the class/package/method name for JUnit test | ||
* cases which will be displayed on the test result page. | ||
* | ||
* This is useful for alternative JVM languages like Scala that allow | ||
* identifiers with invalid characters by encoding them: an extension can | ||
* decode the identifier so it is displayed correctly. | ||
* | ||
* @since 1.515 | ||
*/ | ||
|
||
public abstract class TestNameTransformer implements ExtensionPoint { | ||
/** | ||
* Transform the class/package/method name. | ||
* | ||
* @param name | ||
* Class name (may be simple or fully qualified), package name, or | ||
* method name from a JUnit test. | ||
* @return | ||
* The transformed name, or the name that was passed in if it doesn't | ||
* need to be changed. | ||
*/ | ||
public abstract String transformName(String name); | ||
|
||
public static String getTransformedName(String name) { | ||
String transformedName = name; | ||
for (TestNameTransformer transformer : all()) { | ||
transformedName = transformer.transformName(transformedName); | ||
} | ||
return transformedName; | ||
} | ||
|
||
public static ExtensionList<TestNameTransformer> all() { | ||
return Jenkins.getInstance().getExtensionList(TestNameTransformer.class); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
test/src/test/java/hudson/tasks/junit/TestNameTransformerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package hudson.tasks.junit; | ||
|
||
import hudson.Extension; | ||
|
||
import org.jvnet.hudson.test.HudsonTestCase; | ||
|
||
public class TestNameTransformerTest extends HudsonTestCase { | ||
|
||
private static final String UniqueNameForTest = "unique-name-to-test-name-transformer"; | ||
|
||
@Extension | ||
public static class TestTransformer extends TestNameTransformer { | ||
@Override | ||
public String transformName(String name) { | ||
if (UniqueNameForTest.equals(name)) { | ||
return name + "-transformed"; | ||
} | ||
return name; | ||
} | ||
} | ||
|
||
public void testNameIsTransformed() { | ||
assertEquals(UniqueNameForTest + "-transformed", TestNameTransformer.getTransformedName(UniqueNameForTest)); | ||
} | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters