-
Notifications
You must be signed in to change notification settings - Fork 8
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 #50 from Xray-App/displaynamegeneration_fix
fixes #49 by adding basic support for DisplayNameGeneration
- Loading branch information
Showing
5 changed files
with
80 additions
and
7 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
52 changes: 52 additions & 0 deletions
52
src/test/java/app/getxray/xray/junit/customjunitxml/XrayEnabledTestCustomDisplayName.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,52 @@ | ||
package app.getxray.xray.junit.customjunitxml; | ||
|
||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.DisplayNameGeneration; | ||
|
||
import java.lang.reflect.Method; | ||
import org.junit.jupiter.api.DisplayNameGenerator.Standard; | ||
|
||
@DisplayNameGeneration(XrayEnabledTestCustomDisplayName.CustomDisplayNameGenerator.class) | ||
public class XrayEnabledTestCustomDisplayName { | ||
|
||
@Test | ||
public void legacyTest() { | ||
} | ||
|
||
public static class CustomDisplayNameGenerator extends Standard { | ||
|
||
@Override | ||
public String generateDisplayNameForClass(Class<?> testClass) { | ||
return replaceCamelCase(replaceUndercoreBySpace(super.generateDisplayNameForClass(testClass))); | ||
} | ||
|
||
@Override | ||
public String generateDisplayNameForNestedClass(Class<?> nestedClass) { | ||
return replaceCamelCase(replaceUndercoreBySpace(super.generateDisplayNameForNestedClass(nestedClass))); | ||
} | ||
|
||
@Override | ||
public String generateDisplayNameForMethod(Class<?> testClass, Method testMethod) { | ||
return this.replaceCamelCase(replaceUndercoreBySpace(testMethod.getName())) + " (custom_name)"; | ||
} | ||
|
||
String replaceUndercoreBySpace(String s) { | ||
return s.replace("_", " "); | ||
} | ||
|
||
String replaceCamelCase(String camelCase) { | ||
StringBuilder result = new StringBuilder(); | ||
result.append(camelCase.charAt(0)); | ||
for (int i=1; i<camelCase.length(); i++) { | ||
if (Character.isUpperCase(camelCase.charAt(i))) { | ||
result.append(' '); | ||
result.append(Character.toLowerCase(camelCase.charAt(i))); | ||
} else { | ||
result.append(camelCase.charAt(i)); | ||
} | ||
} | ||
return result.toString(); | ||
} | ||
} | ||
} |
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