Create a gist now

Instantly share code, notes, and snippets.

anonymous /test.java
Created Nov 14, 2016

@Test
public void testJobConfigurationValidity() {
final Reflections reflections = new Reflections(JobConfigurationBase.class.getPackage().getName());
final Set<Class<? extends JobConfigurationBase>> configs = reflections.getSubTypesOf(JobConfigurationBase.class);
final List<String> errorList = new ArrayList<>();
configs.stream()
.filter(config -> !Modifier.isAbstract(config.getModifiers()) && !config.isAnonymousClass())
.forEach(config -> {
try {
final JobConfigurationBase jobConfig = config.newInstance();
if (jobConfig.getRetries() < 0) {
errorList.add(String.format("Retries must be non negative for %s", jobConfig));
}
if (jobConfig.getRunCommand() == null || jobConfig.getRunCommand().isEmpty()) {
errorList.add(String.format("Command must exist for %s", jobConfig));
}
} catch (InstantiationException | IllegalAccessException e) {
errorList.add(String.format("%s cannot be instantiated", config));
}
});
assertTrue(errorList.stream().collect(Collectors.joining("\n")), errorList.isEmpty());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment