org.junit.platform.commons.util.Preconditions Java Examples

The following examples show how to use org.junit.platform.commons.util.Preconditions. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EnabledIfPropertyCondition.java    From camel-quarkus with Apache License 2.0 6 votes vote down vote up
private ConditionEvaluationResult map(EnabledIfProperty annotation) {
    final String name = annotation.named().trim();
    final 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);

    return ConfigProviderResolver.instance().getConfig().getOptionalValue(name, String.class)
            .map(actual -> {
                return actual.matches(regex)
                        ? enabled(
                                format("Config property [%s] with value [%s] matches regular expression [%s]",
                                        name, actual, regex))
                        : disabled(
                                format("Config property [%s] with value [%s] does not match regular expression [%s]",
                                        name, actual, regex));
            })
            .orElseGet(() -> {
                return disabled(
                        format("Config property [%s] does not exist", name));
            });
}
 
Example #2
Source File: ClassScanning.java    From weld-junit with Apache License 2.0 5 votes vote down vote up
private static List<Field> findAllFieldsInHierarchy(Class<?> clazz) {
    Preconditions.notNull(clazz, "Class must not be null");
    List<Field> localFields = getDeclaredFields(clazz).stream().
            filter((field) -> !field.isSynthetic())
            .collect(Collectors.toList());
    List<Field> superclassFields = getSuperclassFields(clazz).stream()
            .filter((field) -> !isMethodShadowedByLocalFields(field, localFields))
            .collect(Collectors.toList());
    List<Field> methods = new ArrayList<>();
    methods.addAll(superclassFields);
    methods.addAll(localFields);

    return methods;
}
 
Example #3
Source File: TestcontainersExtension.java    From testcontainers-java with MIT License 5 votes vote down vote up
private static StoreAdapter getContainerInstance(final Object testInstance, final Field field) {
    try {
        field.setAccessible(true);
        Startable containerInstance = Preconditions.notNull((Startable) field.get(testInstance), "Container " + field.getName() + " needs to be initialized");
        return new StoreAdapter(field.getDeclaringClass(), field.getName(), containerInstance);
    } catch (IllegalAccessException e) {
        throw new ExtensionConfigurationException("Can not access container defined in field " + field.getName());
    }
}
 
Example #4
Source File: FileSourceProvider.java    From gocd with Apache License 2.0 5 votes vote down vote up
private String readFile(String file, ExtensionContext context) {
    Preconditions.notBlank(file, "Classpath resource [" + file + "] must not be null or blank");
    try {
        Class<?> testClass = context.getRequiredTestClass();
        return FileUtils.readFileToString(new File(testClass.getResource(file).getFile()), StandardCharsets.UTF_8);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
 
Example #5
Source File: JsonFileArgumentsProvider.java    From junit-json-params with Apache License 2.0 4 votes vote down vote up
private InputStream openInputStream(ExtensionContext context, String resource) {
    Class<?> testClass = context.getRequiredTestClass();
    InputStream inputStream = inputStreamProvider.apply(testClass, resource);
    return Preconditions.notNull(inputStream,
            () -> "Classpath resource does not exist: " + resource);
}