private static OS determineCurrentOs() { String osName = System.getProperty("os.name"); if (StringUtils.isBlank(osName)) { logger.debug( () -> "JVM system property 'os.name' is undefined. It is therefore not possible to detect the current OS."); // null signals that the current OS is "unknown" return null; } osName = osName.toLowerCase(Locale.ENGLISH); if (osName.contains("aix")) { return AIX; } if (osName.contains("linux")) { return LINUX; } if (osName.contains("mac")) { return MAC; } if (osName.contains("sunos") || osName.contains("solaris")) { return SOLARIS; } if (osName.contains("win")) { return WINDOWS; } return OTHER; }
static String determineDisplayName(AnnotatedElement element, Supplier<String> displayNameSupplier) { Preconditions.notNull(element, "Annotated element must not be null"); Optional<DisplayName> displayNameAnnotation = findAnnotation(element, DisplayName.class); if (displayNameAnnotation.isPresent()) { String displayName = displayNameAnnotation.get().value().trim(); // TODO [#242] Replace logging with precondition check once we have a proper mechanism for // handling validation exceptions during the TestEngine discovery phase. if (StringUtils.isBlank(displayName)) { logger.warn(() -> String.format( "Configuration error: @DisplayName on [%s] must be declared with a non-empty value.", element)); } else { return displayName; } } // else let a 'DisplayNameGenerator' generate a display name return displayNameSupplier.get(); }
private static JRE determineCurrentVersion() { String javaVersion = System.getProperty("java.version"); boolean javaVersionIsBlank = StringUtils.isBlank(javaVersion);
private Method getMethodByFullyQualifiedName(String fullyQualifiedMethodName) { String[] methodParts = ReflectionUtils.parseFullyQualifiedMethodName(fullyQualifiedMethodName); String className = methodParts[0]; String methodName = methodParts[1]; String methodParameters = methodParts[2]; Preconditions.condition(StringUtils.isBlank(methodParameters), () -> format("factory method [%s] must not declare formal parameters", fullyQualifiedMethodName)); return getMethod(loadRequiredClass(className), methodName); }
private Optional<List<String>> getPropertiesList( String key ) { String property = parameters.getProviderProperties().get( key ); return isBlank( property ) ? empty() : of( stream( property.split( "[,]+" ) ) .filter( StringUtils::isNotBlank ) .map( String::trim ) .collect( toList() ) ); } }
/** * Strip the {@link URI#getQuery() query} component from the supplied * {@link URI}. * * @param uri the {@code URI} from which to strip the query component * @return a new {@code URI} with the query component removed, or the * original {@code URI} unmodified if it does not have a query component */ static URI stripQueryComponent(URI uri) { Preconditions.notNull(uri, "URI must not be null"); if (StringUtils.isBlank(uri.getQuery())) { return uri; } String uriAsString = uri.toString(); return URI.create(uriAsString.substring(0, uriAsString.indexOf('?'))); }
private void printThrowable(String indent, TestExecutionResult result) { if (!result.getThrowable().isPresent()) { return; } Throwable throwable = result.getThrowable().get(); String message = throwable.getMessage(); if (StringUtils.isBlank(message)) { message = throwable.toString(); } printMessage(FAILED, indent, message); }
/** * Handler for display name * * @param test - RepeatedIfExceptionsTest annotation * @param displayName - Name that will be represent to report * @return RepeatedIfExceptionsDisplayNameFormatter {@link RepeatedIfExceptionsDisplayNameFormatter} */ private RepeatedIfExceptionsDisplayNameFormatter displayNameFormatter(RepeatedIfExceptionsTest test, String displayName) { String pattern = test.name().trim(); if (StringUtils.isBlank(pattern)) { pattern = AnnotationUtils.getDefaultValue(test, "name", String.class) .orElseThrow(() -> new RepeatedIfException("Exception occurred with name parameter of RepeatedIfExceptionsTest annotation")); } return new RepeatedIfExceptionsDisplayNameFormatter(pattern, displayName); }
private String getTechnicalName(TestIdentifier testIdentifier) { Optional<TestSource> optionalSource = testIdentifier.getSource(); if (optionalSource.isPresent()) { TestSource source = optionalSource.get(); if (source instanceof ClassSource) { return ((ClassSource) source).getJavaClass().getName(); } else if (source instanceof MethodSource) { MethodSource methodSource = (MethodSource) source; String methodParameterTypes = methodSource.getMethodParameterTypes(); if (StringUtils.isBlank(methodParameterTypes)) { return methodSource.getMethodName(); } return String.format("%s(%s)", methodSource.getMethodName(), methodParameterTypes); } } // Else fall back to display name return testIdentifier.getDisplayName(); }
@Test void testCreate() { String objectPath = "/org/fedoraproject/FirewallD1"; String busName = "org.fedoraproject.FirewallD1"; boolean ignoreDtd = true; Logger logger = LoggerFactory.getLogger(InterfaceCodeGenerator.class); if (!StringUtils.isBlank(busName)) { String introspectionData = FileIoUtil.readFileToString("src/test/resources/CreateInterface/org.fedoraproject.FirewallD1.xml"); InterfaceCodeGenerator ci2 = new InterfaceCodeGenerator(introspectionData, objectPath, busName); try { Map<File, String> analyze = ci2.analyze(ignoreDtd); assertEquals(20, analyze.size()); // writeToFile(SystemUtil.getTempDir() + File.separator + "CreateInterfaceTest", analyze); } catch (Exception _ex) { logger.error("Error while analyzing introspection data", _ex); } } }