-
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.
Add simple API to plugin test-framework specific behavior
Closes #60
- Loading branch information
Showing
11 changed files
with
158 additions
and
94 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
66 changes: 0 additions & 66 deletions
66
...-tests-core/src/main/java/de/skuzzle/test/snapshots/impl/AssumptionExceptionDetector.java
This file was deleted.
Oops, something went wrong.
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
37 changes: 37 additions & 0 deletions
37
snapshot-tests-core/src/main/java/de/skuzzle/test/snapshots/impl/TestFrameworkSupport.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,37 @@ | ||
package de.skuzzle.test.snapshots.impl; | ||
|
||
import org.apiguardian.api.API; | ||
|
||
import java.lang.reflect.Method; | ||
|
||
/** | ||
* Abstraction to provide test framework specific behavior to the snapshot-test core | ||
* | ||
* @since 1.10.0 | ||
*/ | ||
@API(status = API.Status.INTERNAL, since = "1.10.0") | ||
public interface TestFrameworkSupport { | ||
|
||
/** | ||
* Tries to determine whether the given method is (still) a snapshot test. This is used during static orphan | ||
* detection in order to determine whether the method mentioned in an existing snapshot's header pertains to an | ||
* existing snapshot test method. | ||
* <p> | ||
* It might not always be possible to statically determine whether a test method uses snapshot assertions. In this | ||
* case the method should return true in order to prevent false positives during orphan detection. | ||
* </p> | ||
* | ||
* @param testClass The test class. | ||
* @param testMethod The test method. | ||
* @return Whether the given test method uses snapshot assertions. | ||
*/ | ||
boolean isSnapshotTest(Class<?> testClass, Method testMethod); | ||
|
||
/** | ||
* Creates a throwable that will mark the repsective test as skipped. | ||
* | ||
* @param message The message for the throwable. | ||
* @return The throwable. | ||
*/ | ||
Throwable assumptionFailed(String message); | ||
} |
31 changes: 31 additions & 0 deletions
31
...tests-core/src/main/java/de/skuzzle/test/snapshots/junit5/JUnit5TestFrameworkSupport.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,31 @@ | ||
package de.skuzzle.test.snapshots.junit5; | ||
|
||
import java.lang.reflect.Method; | ||
import java.lang.reflect.Modifier; | ||
import java.util.Arrays; | ||
|
||
import de.skuzzle.test.snapshots.Snapshot; | ||
import de.skuzzle.test.snapshots.impl.TestFrameworkSupport; | ||
|
||
import org.opentest4j.TestAbortedException; | ||
|
||
final class JUnit5TestFrameworkSupport implements TestFrameworkSupport { | ||
|
||
static final TestFrameworkSupport INSTANCE = new JUnit5TestFrameworkSupport(); | ||
|
||
private JUnit5TestFrameworkSupport() { | ||
// hidden | ||
} | ||
|
||
@Override | ||
public boolean isSnapshotTest(Class<?> testClass, Method testMethod) { | ||
return !Modifier.isStatic(testMethod.getModifiers()) | ||
&& !Modifier.isPrivate(testMethod.getModifiers()) | ||
&& Arrays.stream(testMethod.getParameterTypes()).anyMatch(Snapshot.class::isAssignableFrom); | ||
} | ||
|
||
@Override | ||
public Throwable assumptionFailed(String message) { | ||
return new TestAbortedException(message); | ||
} | ||
} |
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
...sts-junit4/src/main/java/de/skuzzle/test/snapshots/junit4/JUnit4TestFrameworkSupport.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 de.skuzzle.test.snapshots.junit4; | ||
|
||
import java.lang.reflect.Method; | ||
import java.lang.reflect.Modifier; | ||
|
||
import de.skuzzle.test.snapshots.impl.TestFrameworkSupport; | ||
|
||
import org.junit.AssumptionViolatedException; | ||
|
||
final class JUnit4TestFrameworkSupport implements TestFrameworkSupport { | ||
static final TestFrameworkSupport INSTANCE = new JUnit4TestFrameworkSupport(); | ||
|
||
private JUnit4TestFrameworkSupport() { | ||
// hidden | ||
} | ||
|
||
@Override | ||
public boolean isSnapshotTest(Class<?> testClass, Method testMethod) { | ||
return !Modifier.isStatic(testMethod.getModifiers()) | ||
&& !Modifier.isPrivate(testMethod.getModifiers()); | ||
} | ||
|
||
@Override | ||
public Throwable assumptionFailed(String message) { | ||
return new AssumptionViolatedException(message); | ||
} | ||
} |
Oops, something went wrong.