Skip to content

Instantly share code, notes, and snippets.

Created November 14, 2016 16:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/821bbdc77e9ea746800fce1c9c31713c to your computer and use it in GitHub Desktop.
Save anonymous/821bbdc77e9ea746800fce1c9c31713c to your computer and use it in GitHub Desktop.
@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