Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: introduced MidpointTestContext and its base implementation
This context also provides basic getTestName* methods based on abstract methods getTestClass() and getTestMethodName().
- Loading branch information
Showing
2 changed files
with
77 additions
and
0 deletions.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
tools/test-ng/src/main/java/com/evolveum/midpoint/tools/testng/MidpointTestContext.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,38 @@ | ||
package com.evolveum.midpoint.tools.testng; | ||
|
||
/** | ||
* Basic contract for test-method context (typically available through thread-local variable). | ||
*/ | ||
public interface MidpointTestContext { | ||
|
||
/** | ||
* Returns the actual instantiated test class. | ||
*/ | ||
Class<?> getTestClass(); | ||
|
||
/** | ||
* Returns the name of the test method. | ||
*/ | ||
String getTestMethodName(); | ||
|
||
/** | ||
* Returns test name in form of "class-simple-name.method". | ||
*/ | ||
default String getTestName() { | ||
return getTestClass().getSimpleName() + "." + getTestMethodName(); | ||
} | ||
|
||
/** | ||
* Returns short test name - currently the same like {@link #getTestMethodName()}. | ||
*/ | ||
default String getTestNameShort() { | ||
return getTestMethodName(); | ||
} | ||
|
||
/** | ||
* Returns long test name in form of "fully.qualified.class-name.method". | ||
*/ | ||
default String getTestNameLong() { | ||
return getTestClass().getName() + "." + getTestMethodName(); | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
...s/test-ng/src/main/java/com/evolveum/midpoint/tools/testng/SimpleMidpointTestContext.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,39 @@ | ||
package com.evolveum.midpoint.tools.testng; | ||
|
||
import org.testng.ITestResult; | ||
|
||
public class SimpleMidpointTestContext implements MidpointTestContext { | ||
|
||
private static final ThreadLocal<SimpleMidpointTestContext> TEST_CONTEXT_THREAD_LOCAL = | ||
new ThreadLocal<>(); | ||
|
||
private final ITestResult testResult; | ||
|
||
public SimpleMidpointTestContext(ITestResult testResult) { | ||
this.testResult = testResult; | ||
} | ||
|
||
@Override | ||
public Class<?> getTestClass() { | ||
return testResult.getMethod().getTestClass().getRealClass(); | ||
} | ||
|
||
@Override | ||
public String getTestMethodName() { | ||
return testResult.getMethod().getMethodName(); | ||
} | ||
|
||
public static SimpleMidpointTestContext create(ITestResult testResult) { | ||
SimpleMidpointTestContext ctx = new SimpleMidpointTestContext(testResult); | ||
TEST_CONTEXT_THREAD_LOCAL.set(ctx); | ||
return ctx; | ||
} | ||
|
||
public static SimpleMidpointTestContext get() { | ||
return TEST_CONTEXT_THREAD_LOCAL.get(); | ||
} | ||
|
||
public static void destroy() { | ||
TEST_CONTEXT_THREAD_LOCAL.remove(); | ||
} | ||
} |