OxalisHomeDirectory { public File detect() { File directory = homeDetectors.stream() .sequential() .map(HomeDetector::detect) .filter(Objects::nonNull) .findFirst() .orElseThrow(() -> new OxalisLoadingException( "Unable to detect Oxalis home folder.")); try { validateOxalisHomeDirectory(directory); } catch (OxalisLoadingException ex) { log.error(ex.getMessage()); throw ex; } return directory; } OxalisHomeDirectory(List<HomeDetector> homeDetectors); @SuppressWarnings("unused")  OxalisHomeDirectory(); File detect();  }
@Test public void mockingFound() { OxalisHomeDirectory oxalisHomeDirectory = new OxalisHomeDirectory( Collections.singletonList(() -> fakeHome.toFile())); Assert.assertNotNull(oxalisHomeDirectory.detect()); }
@Test(expectedExceptions = OxalisLoadingException.class) public void mockingNotFound() { OxalisHomeDirectory oxalisHomeDirectory = new OxalisHomeDirectory( Collections.singletonList(() -> null)); oxalisHomeDirectory.detect(); }
@Test(expectedExceptions = OxalisLoadingException.class) public void mockingInvalid() { OxalisHomeDirectory oxalisHomeDirectory = new OxalisHomeDirectory( Collections.singletonList(() -> new File("/invalid"))); oxalisHomeDirectory.detect(); }
@Test(expectedExceptions = OxalisLoadingException.class) public void mockingFile() { OxalisHomeDirectory oxalisHomeDirectory = new OxalisHomeDirectory( Collections.singletonList(() -> fakeHome.resolve("fake-oxalis.conf").toFile())); oxalisHomeDirectory.detect(); }