SonarQubeTask extends Task { @SuppressWarnings("unchecked") @Override public void execute() { log(Main.getAntVersion()); log("SonarQube Ant Task version: " + SonarQubeTaskUtils.getTaskVersion()); log("Loaded from: " + SonarQubeTaskUtils.getJarPath()); Map<String, String> allProps = new HashMap<>(); allProps.put(PROJECT_BASEDIR_PROPERTY, getProject().getBaseDir().getAbsolutePath()); if (SonarQubeTaskUtils.getAntLoggerLever(getProject()) >= 3) { allProps.put(VERBOSE_PROPERTY, "true"); } putAll(Utils.loadEnvironmentProperties(getEnv()), allProps); allProps.putAll(getProject().getProperties()); if ("true".equalsIgnoreCase(allProps.get(ScanProperties.SKIP))) { log("SonarQube Scanner analysis skipped"); return; } launchAnalysis(allProps); }  @SuppressWarnings("unchecked") @Override void execute();  }
@Test public void simulationMode() throws IOException { project = mock(Project.class); Properties props = new Properties(); File out = folder.newFile(); props.put("sonar.scanner.dumpToFile", out.getAbsolutePath()); when(project.getProperties()).thenReturn(props); task = new SonarQubeTask(); File baseDir = folder.newFolder(); when(project.getBaseDir()).thenReturn(baseDir); task.setProject(project); task.execute(); Properties outProps = new Properties(); try (BufferedReader reader = Files.newBufferedReader(out.toPath(), StandardCharsets.UTF_8)) { outProps.load(reader); } assertThat(outProps.entrySet()).extracting(Map.Entry::getKey, Map.Entry::getValue) .contains( tuple("sonar.projectBaseDir", baseDir.getAbsolutePath()), tuple("sonar.scanner.app", "Ant")); }