@Test public void loadAllShouldRethrowException(@Mocked Files unused) { try { new Expectations() { { Files.walk((Path) any, anyInt); result = new IOException("testException123"); } }; } catch (IOException e) { fail("Unexpected exception creating Expectations: " + e); } try { new FileSystemStorageService(mockOdeProperties).loadAll(); fail("Expected StorageException"); } catch (Exception e) { assertEquals("Incorrect exception thrown", StorageException.class, e.getClass()); assertTrue("Incorrect message received", e.getMessage().startsWith("Failed to read files stored in")); } new Verifications() { { EventLogger.logger.info("Failed to read files stored in {}", (Path) any); } }; }
@Override public Stream<Path> loadAll() { try { return Files.walk(this.rootLocation, 1).filter(path -> !path.equals(this.rootLocation)) .map(path -> this.rootLocation.relativize(path)); } catch (IOException e) { EventLogger.logger.info("Failed to read files stored in {}", this.rootLocation); throw new StorageException("Failed to read files stored in " + this.rootLocation, e); } }
FileSystemStorageService implements StorageService { @Override public Stream<Path> loadAll() { try { return Files.walk(this.rootLocation, 1).filter(path -> !path.equals(this.rootLocation)) .map(path -> this.rootLocation.relativize(path)); } catch (IOException e) { EventLogger.logger.info("Failed to read files stored in {}", this.rootLocation); throw new StorageException("Failed to read files stored in " + this.rootLocation, e); } } }
FileSystemStorageService implements StorageService { @Override public Stream<Path> loadAll() { try { return Files.walk(this.rootLocation, 1).filter(path -> !path.equals(this.rootLocation)) .map(path -> this.rootLocation.relativize(path)); } catch (IOException e) { EventLogger.logger.info("Failed to read files stored in {}", this.rootLocation); throw new StorageException("Failed to read files stored in " + this.rootLocation, e); } } @Autowired  FileSystemStorageService(OdeProperties properties); }
FileSystemStorageService implements StorageService { @Override public Stream<Path> loadAll() { try { return Files.walk(this.rootLocation, 1).filter(path -> !path.equals(this.rootLocation)) .map(path -> this.rootLocation.relativize(path)); } catch (IOException e) { EventLogger.logger.info("Failed to read files stored in {}", this.rootLocation); throw new StorageException("Failed to read files stored in " + this.rootLocation, e); } } @Autowired  FileSystemStorageService(OdeProperties properties); @Override void store(MultipartFile file, String type); @Override Stream<Path> loadAll(); @Override Path load(String filename); @Override Resource loadAsResource(String filename); @Override void deleteAll(); @Override void init(); Path getRootLocation(); void setRootLocation(Path rootLocation); }
FileSystemStorageService implements StorageService { @Override public Stream<Path> loadAll() { try { return Files.walk(this.rootLocation, 1).filter(path -> !path.equals(this.rootLocation)) .map(path -> this.rootLocation.relativize(path)); } catch (IOException e) { EventLogger.logger.info("Failed to read files stored in {}", this.rootLocation); throw new StorageException("Failed to read files stored in " + this.rootLocation, e); } } @Autowired  FileSystemStorageService(OdeProperties properties); @Override void store(MultipartFile file, String type); @Override Stream<Path> loadAll(); @Override Path load(String filename); @Override Resource loadAsResource(String filename); @Override void deleteAll(); @Override void init(); Path getRootLocation(); void setRootLocation(Path rootLocation);  }