Skip to content

Commit

Permalink
MidpointTestMixin now provides also getTestNumber()
Browse files Browse the repository at this point in the history
  • Loading branch information
virgo47 committed Mar 8, 2020
1 parent d4cdd34 commit aa1dbfc
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
4 changes: 4 additions & 0 deletions tools/test-ng/pom.xml
Expand Up @@ -37,5 +37,9 @@
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
</dependencies>
</project>
Expand Up @@ -8,6 +8,7 @@

import java.util.Objects;

import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger;
Expand Down Expand Up @@ -69,6 +70,24 @@ default String getTestNameLong() {
return testContext().getTestNameLong();
}

/**
* Returns the number of the test derived from the method name in form "testXxxDescription".
* Number is returned as a string with all leading zeroes preserved.
* Fails if the method name does not conform to the "testXxx" prefix to prevent invalid usage.
* Also fails if test-method context is not available.
*/
default String getTestNumber() {
String methodName = testContext().getTestMethodName();
if (methodName.startsWith("test") && methodName.length() >= 7) {
String testNumber = methodName.substring(4, 7);
if (StringUtils.isNumeric(testNumber)) {
return testNumber;
}
}
throw new IllegalArgumentException(
"Test method name doesn't start with \"testXxx\" (Xxx = test number).");
}

/**
* Returns test class logger.
*/
Expand Down

0 comments on commit aa1dbfc

Please sign in to comment.