DynamicNode(String displayName, URI testSourceUri) { this.displayName = Preconditions.notBlank(displayName, "displayName must not be null or blank"); this.testSourceUri = testSourceUri; }
private RepeatedTestDisplayNameFormatter displayNameFormatter(RepeatedTest repeatedTest, Method method, String displayName) { String pattern = Preconditions.notBlank(repeatedTest.name().trim(), () -> String.format( "Configuration error: @RepeatedTest on method [%s] must be declared with a non-empty name.", method)); return new RepeatedTestDisplayNameFormatter(pattern, displayName); }
private InputStream openInputStream(ExtensionContext context, String resource) { Preconditions.notBlank(resource, "Classpath resource [" + resource + "] must not be null or blank"); Class<?> testClass = context.getRequiredTestClass(); return Preconditions.notNull(inputStreamProvider.apply(testClass, resource), () -> "Classpath resource [" + resource + "] does not exist"); }
private ParameterizedTestNameFormatter createNameFormatter(Method templateMethod, String displayName) { ParameterizedTest parameterizedTest = findAnnotation(templateMethod, ParameterizedTest.class).get(); String pattern = Preconditions.notBlank(parameterizedTest.name().trim(), () -> String.format( "Configuration error: @ParameterizedTest on method [%s] must be declared with a non-empty name.", templateMethod)); return new ParameterizedTestNameFormatter(pattern, displayName); }
public Script(Class<? extends Annotation> annotationType, String annotationAsString, String engine, String source, String reason) { Preconditions.notNull(annotationType, "annotationType must not be null"); Preconditions.notNull(annotationAsString, "annotationAsString must not be null"); Preconditions.notBlank(engine, "engine must not be blank"); Preconditions.notBlank(source, "source must not be blank"); Preconditions.notNull(reason, "reason must not be null"); this.annotationType = annotationType; this.annotationAsString = annotationAsString; this.engine = engine; this.source = source; this.reason = reason; this.hashCode = computeHashCode(); }
@Override public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) { Optional<EnabledIfSystemProperty> optional = findAnnotation(context.getElement(), EnabledIfSystemProperty.class); if (!optional.isPresent()) { return ENABLED_BY_DEFAULT; } EnabledIfSystemProperty annotation = optional.get(); String name = annotation.named().trim(); String regex = annotation.matches(); Preconditions.notBlank(name, () -> "The 'named' attribute must not be blank in " + annotation); Preconditions.notBlank(regex, () -> "The 'matches' attribute must not be blank in " + annotation); String actual = System.getProperty(name); // Nothing to match against? if (actual == null) { return disabled(format("System property [%s] does not exist", name)); } if (actual.matches(regex)) { return enabled( format("System property [%s] with value [%s] matches regular expression [%s]", name, actual, regex)); } return disabled( format("System property [%s] with value [%s] does not match regular expression [%s]", name, actual, regex)); }
@Override public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) { Optional<DisabledIfSystemProperty> optional = findAnnotation(context.getElement(), DisabledIfSystemProperty.class); if (!optional.isPresent()) { return ENABLED_BY_DEFAULT; } DisabledIfSystemProperty annotation = optional.get(); String name = annotation.named().trim(); String regex = annotation.matches(); Preconditions.notBlank(name, () -> "The 'named' attribute must not be blank in " + annotation); Preconditions.notBlank(regex, () -> "The 'matches' attribute must not be blank in " + annotation); String actual = System.getProperty(name); // Nothing to match against? if (actual == null) { return enabled(format("System property [%s] does not exist", name)); } if (actual.matches(regex)) { return disabled( format("System property [%s] with value [%s] matches regular expression [%s]", name, actual, regex)); } // else return enabled( format("System property [%s] with value [%s] does not match regular expression [%s]", name, actual, regex)); }
@Override public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) { Optional<EnabledIfEnvironmentVariable> optional = findAnnotation(context.getElement(), EnabledIfEnvironmentVariable.class); if (!optional.isPresent()) { return ENABLED_BY_DEFAULT; } EnabledIfEnvironmentVariable annotation = optional.get(); String name = annotation.named().trim(); String regex = annotation.matches(); Preconditions.notBlank(name, () -> "The 'named' attribute must not be blank in " + annotation); Preconditions.notBlank(regex, () -> "The 'matches' attribute must not be blank in " + annotation); String actual = getEnvironmentVariable(name); // Nothing to match against? if (actual == null) { return disabled(format("Environment variable [%s] does not exist", name)); } if (actual.matches(regex)) { return enabled(format("Environment variable [%s] with value [%s] matches regular expression [%s]", name, actual, regex)); } return disabled(format("Environment variable [%s] with value [%s] does not match regular expression [%s]", name, actual, regex)); }
@Override public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) { Optional<DisabledIfEnvironmentVariable> optional = findAnnotation(context.getElement(), DisabledIfEnvironmentVariable.class); if (!optional.isPresent()) { return ENABLED_BY_DEFAULT; } DisabledIfEnvironmentVariable annotation = optional.get(); String name = annotation.named().trim(); String regex = annotation.matches(); Preconditions.notBlank(name, () -> "The 'named' attribute must not be blank in " + annotation); Preconditions.notBlank(regex, () -> "The 'matches' attribute must not be blank in " + annotation); String actual = getEnvironmentVariable(name); // Nothing to match against? if (actual == null) { return enabled(format("Environment variable [%s] does not exist", name)); } if (actual.matches(regex)) { return disabled(format("Environment variable [%s] with value [%s] matches regular expression [%s]", name, actual, regex)); } // else return enabled(format("Environment variable [%s] with value [%s] does not match regular expression [%s]", name, actual, regex)); }
private MethodSource(String className, String methodName, String methodParameterTypes) { Preconditions.notBlank(className, "Class name must not be null or blank"); Preconditions.notBlank(methodName, "Method name must not be null or blank"); this.className = className; this.methodName = methodName; this.methodParameterTypes = methodParameterTypes; }
private ClasspathResourceSource(String classpathResourceName, FilePosition filePosition) { Preconditions.notBlank(classpathResourceName, "Classpath resource name must not be null or blank"); boolean startsWithSlash = classpathResourceName.startsWith("/"); this.classpathResourceName = (startsWithSlash ? classpathResourceName.substring(1) : classpathResourceName); this.filePosition = filePosition; }
/** * Create a {@code MethodSelector} for the supplied class name and method name. * * @param className the fully qualified name of the class in which the method * is declared, or a subclass thereof; never {@code null} or blank * @param methodName the name of the method to select; never {@code null} or blank * @see MethodSelector */ public static MethodSelector selectMethod(String className, String methodName) { Preconditions.notBlank(className, "Class name must not be null or blank"); Preconditions.notBlank(methodName, "Method name must not be null or blank"); return new MethodSelector(className, methodName); }
/** * Create a {@code ClassSelector} for the supplied class name. * * @param className the fully qualified name of the class to select; * never {@code null} or blank * @see ClassSelector */ public static ClassSelector selectClass(String className) { Preconditions.notBlank(className, "Class name must not be null or blank"); return new ClassSelector(className); }
/** * Create a new {@code ExclusiveResource}. * * @param key the identifier of the resource; never {@code null} or blank * @param lockMode the lock mode to use to synchronize access to the * resource; never {@code null} */ public ExclusiveResource(String key, LockMode lockMode) { this.key = Preconditions.notBlank(key, "key must not be blank"); this.lockMode = Preconditions.notNull(lockMode, "lockMode must not be null"); }
/** * Create a new view of the supplied {@link ConfigurationParameters} that * applies the supplied prefix to all queries. * * @param delegate the {@link ConfigurationParameters} to delegate to; never * {@code null} * @param prefix the prefix to apply to all queries; never {@code null} or * blank */ public PrefixedConfigurationParameters(ConfigurationParameters delegate, String prefix) { this.delegate = Preconditions.notNull(delegate, "delegate must not be null"); this.prefix = Preconditions.notBlank(prefix, "prefix must not be null or blank"); }
/** * Create a {@code ModuleSelector} for the supplied module name. * * <p>The unnamed module is not supported. * * @param moduleName the module name to select; never {@code null} or blank * @since 1.1 * @see ModuleSelector */ @API(status = EXPERIMENTAL, since = "1.1") public static ModuleSelector selectModule(String moduleName) { Preconditions.notBlank(moduleName, "Module name must not be null or blank"); return new ModuleSelector(moduleName.trim()); }
/** * Parse a {@code UniqueId} from the supplied string representation using the * default format. * * @param uniqueId the string representation to parse; never {@code null} or blank * @return a properly constructed {@code UniqueId} * @throws JUnitException if the string cannot be parsed */ public static UniqueId parse(String uniqueId) throws JUnitException { Preconditions.notBlank(uniqueId, "Unique ID string must not be null or blank"); return UniqueIdFormat.getDefault().parse(uniqueId); }
/** * Create a {@code UniqueIdSelector} for the supplied unique ID. * * @param uniqueId the unique ID to select; never {@code null} or blank * @see UniqueIdSelector */ public static UniqueIdSelector selectUniqueId(String uniqueId) { Preconditions.notBlank(uniqueId, "Unique ID must not be null or blank"); return new UniqueIdSelector(UniqueId.parse(uniqueId)); }
/** * Create a {@code MethodSelector} for the supplied {@link Class} and method name. * * @param javaClass the class in which the method is declared, or a subclass thereof; * never {@code null} * @param methodName the name of the method to select; never {@code null} or blank * @see MethodSelector */ public static MethodSelector selectMethod(Class<?> javaClass, String methodName) { Preconditions.notNull(javaClass, "Class must not be null"); Preconditions.notBlank(methodName, "Method name must not be null or blank"); return new MethodSelector(javaClass, methodName); }