QAvalidator { @SuppressWarnings({"squid:S2221","squid:S1166"}) public QAvalidatorResult runAnalysis(QAvalidatorConfig config) { QAvalidatorResult result = new QAvalidatorResult(); try { String analysisFilename = selectAnalysisFilename(config); QavAnalysisReader qavAnalysisReader = new QavAnalysisReader(analysisFilename); qavAnalysisReader.setInputDirs(config.getInputDirs()); qavAnalysisReader.setOutputDir(config.getOutputDir()); qavAnalysisReader.read(); @SuppressWarnings("unchecked") List<String> failedSteps = (List<String>) qavAnalysisReader.getContext().getProperty("failedSteps"); result.setFailedSteps(failedSteps); } catch (Exception e) { result.setFailedWithException(true); result.setExceptionMessage(e.getMessage()); } return result; }  @SuppressWarnings({"squid:S2221","squid:S1166"}) // catching Exception (instead of specific subtypes) because there could also be runtime exceptions. // Their messages will all be properly logged. QAvalidatorResult runAnalysis(QAvalidatorConfig config);  }
@Test public void testRunAnalysis() { QAvalidatorConfig config = new QAvalidatorConfig(); config.setAnalysisFilename("classpath:/default_analysis.groovy"); config.setInputDirs(Lists.newArrayList("./build/classes/java/main")); config.setOutputDir("./build/result-default-architecture"); QAvalidatorResult result = new QAvalidator().runAnalysis(config); assertThat(result, notNullValue()); assertThat(result.getFailedSteps(), hasSize(0)); assertThat(result.isFailedWithException(), is(false)); assertThat(result.getExceptionMessage(), nullValue()); }
@Test public void testWithNotExistingFile() { QAvalidatorConfig config = new QAvalidatorConfig(); config.setAnalysisFilename("not/existing/file"); QAvalidatorResult result = new QAvalidator().runAnalysis(config); assertThat(result, notNullValue()); assertThat(result.getFailedSteps(), hasSize(0)); assertThat(result.isFailedWithException(), is(true)); assertThat(result.getExceptionMessage(), startsWith("Can not find analysis file")); assertThat(result.getExceptionMessage().replaceAll("\\\\", "/"), endsWith("not/existing/file")); }