Dirs { void init(Map<String, String> p) { boolean onProject = Utils.taskRequiresProject(p); if (onProject) { initProjectDirs(p); } else { initTaskDirs(p); } } Dirs(Logger logger);   }
@Test public void should_use_parameterized_task_work_dir() throws Exception { p.put("sonar.task", "views"); p.put(ScannerProperties.WORK_DIR, "generated/reports"); new Dirs(mock(Logger.class)).init(p); File workDir = new File(p.get(ScannerProperties.WORK_DIR)); assertThat(workDir).isNotNull(); assertThat(workDir.getCanonicalPath().replace("\\", "/")).contains("generated/reports"); }
@Test public void should_init_default_project_dirs() throws Exception { p.put("sonar.task", "scan"); new Dirs(mock(Logger.class)).init(p); File projectDir = new File(p.get(ScanProperties.PROJECT_BASEDIR)); File workDir = new File(p.get(ScannerProperties.WORK_DIR)); assertThat(projectDir).isNotNull().isDirectory(); assertThat(workDir).isNotNull(); assertThat(projectDir.getCanonicalPath()).isEqualTo(new File(".").getCanonicalPath()); assertThat(workDir.getName()).isEqualTo(".scannerwork"); assertThat(workDir.getParentFile()).isEqualTo(projectDir); }
@Test public void should_set_relative_path_to_project_work_dir() throws Exception { File initialProjectDir = temp.getRoot(); p.put("sonar.task", "scan"); p.put(ScannerProperties.WORK_DIR, "relative/path"); p.put(ScanProperties.PROJECT_BASEDIR, initialProjectDir.getAbsolutePath()); new Dirs(mock(Logger.class)).init(p); File projectDir = new File(p.get(ScanProperties.PROJECT_BASEDIR)); File workDir = new File(p.get(ScannerProperties.WORK_DIR)); assertThat(projectDir).isNotNull().isDirectory(); assertThat(projectDir.getCanonicalPath()).isEqualTo(initialProjectDir.getCanonicalPath()); assertThat(workDir).isNotNull(); assertThat(workDir.getCanonicalPath()).isEqualTo(new File(projectDir, "relative/path").getCanonicalPath()); }
@Test public void should_init_default_task_work_dir() throws Exception { p.put("sonar.task", "views"); new Dirs(mock(Logger.class)).init(p); File workDir = new File(p.get(ScannerProperties.WORK_DIR)); assertThat(workDir).isNotNull().isDirectory(); assertThat(workDir.getCanonicalPath()).isEqualTo(new File(".").getCanonicalPath()); }