-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Added convenience RepeatTestRule.
- Loading branch information
Showing
2 changed files
with
40 additions
and
0 deletions.
There are no files selected for viewing
12 changes: 12 additions & 0 deletions
12
subprojects-internal/test-jtrim-utils/src/main/java/org/jtrim2/testutils/RepeatTest.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,12 @@ | ||
package org.jtrim2.testutils; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target(ElementType.METHOD) | ||
public @interface RepeatTest { | ||
public int value(); | ||
} |
28 changes: 28 additions & 0 deletions
28
subprojects-internal/test-jtrim-utils/src/main/java/org/jtrim2/testutils/RepeatTestRule.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,28 @@ | ||
package org.jtrim2.testutils; | ||
|
||
import org.junit.rules.TestRule; | ||
import org.junit.runner.Description; | ||
import org.junit.runners.model.Statement; | ||
|
||
public final class RepeatTestRule implements TestRule { | ||
@Override | ||
public Statement apply(Statement base, Description description) { | ||
RepeatTest annotation = description.getAnnotation(RepeatTest.class); | ||
if (annotation == null) { | ||
return base; | ||
} | ||
int repeatCount = annotation.value(); | ||
if (repeatCount <= 0) { | ||
throw new IllegalStateException("Unexpected repeat count " + repeatCount | ||
+ " on " + description.getDisplayName()); | ||
} | ||
return new Statement() { | ||
@Override | ||
public void evaluate() throws Throwable { | ||
for (int i = repeatCount; i > 0; i--) { | ||
base.evaluate(); | ||
} | ||
} | ||
}; | ||
} | ||
} |