-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
provide name of test class to re-run in failure reproduction info, if…
… test class hierarchy of failed test contains Lifecycle PER_CLASS Signed-off-by: Jonas Höf <jonas.hoef@tngtech.com>
- Loading branch information
Showing
5 changed files
with
211 additions
and
45 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
32 changes: 23 additions & 9 deletions
32
core/src/main/java/com/tngtech/valueprovider/ValueProviderException.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 |
---|---|---|
@@ -1,29 +1,43 @@ | ||
package com.tngtech.valueprovider; | ||
|
||
import static com.tngtech.valueprovider.InitializationCreator.VALUE_PROVIDER_FACTORY_REFERENCE_DATE_TIME_PROPERTY; | ||
import static com.tngtech.valueprovider.InitializationCreator.VALUE_PROVIDER_FACTORY_TEST_CLASS_SEED_PROPERTY; | ||
import static com.tngtech.valueprovider.InitializationCreator.VALUE_PROVIDER_FACTORY_TEST_METHOD_SEED_PROPERTY; | ||
import static com.tngtech.valueprovider.ValueProviderFactory.getFormattedReferenceDateTime; | ||
import static com.tngtech.valueprovider.ValueProviderFactory.getTestClassSeed; | ||
import static com.tngtech.valueprovider.ValueProviderFactory.getTestMethodSeed; | ||
import java.util.Optional; | ||
|
||
import com.google.common.annotations.VisibleForTesting; | ||
|
||
import static com.tngtech.valueprovider.InitializationCreator.*; | ||
import static com.tngtech.valueprovider.ValueProviderFactory.*; | ||
import static java.lang.String.format; | ||
import static java.util.Optional.empty; | ||
|
||
@SuppressWarnings("OptionalUsedAsFieldOrParameterType") | ||
public class ValueProviderException extends RuntimeException { | ||
ValueProviderException() { | ||
super(provideFailureReproductionInfo()); | ||
this(empty()); | ||
} | ||
|
||
ValueProviderException(Optional<Class<?>> testClassToReRunForReproduction) { | ||
super(provideFailureReproductionInfo(testClassToReRunForReproduction)); | ||
} | ||
|
||
static String provideFailureReproductionInfo() { | ||
@VisibleForTesting | ||
static String provideFailureReproductionInfo(Optional<Class<?>> testClassToReRunForReproduction) { | ||
long testClassSeed = getTestClassSeed(); | ||
long testMethodSeed = getTestMethodSeed(); | ||
String referenceDateTime = getFormattedReferenceDateTime(); | ||
return format( | ||
"If the failure is related to random ValueProviders, specify the following system properties for the JVM to reproduce:%n" + | ||
"If the failure is related to random ValueProviders, %sspecify the following system properties for the JVM to reproduce:%n" + | ||
"-D%s=%d%n" + | ||
"-D%s=%d%n" + | ||
"-D%s=%s", | ||
formatReRunMessageFor(testClassToReRunForReproduction), | ||
VALUE_PROVIDER_FACTORY_TEST_CLASS_SEED_PROPERTY, testClassSeed, | ||
VALUE_PROVIDER_FACTORY_TEST_METHOD_SEED_PROPERTY, testMethodSeed, | ||
VALUE_PROVIDER_FACTORY_REFERENCE_DATE_TIME_PROPERTY, referenceDateTime); | ||
} | ||
|
||
private static String formatReRunMessageFor(Optional<Class<?>> testClassToReRunForReproduction) { | ||
return testClassToReRunForReproduction.map(testClass -> | ||
format("re-run all tests of '%s' and ", testClass.getName())) | ||
.orElse(""); | ||
} | ||
} |
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
Oops, something went wrong.