### Question:
FileSystemFileStorageService extends AbstractDaoFileStorageService { public String getDirectory() { return directory; } @Autowired  FileSystemFileStorageService(FileDAO fileDAO); @Override InputStream getFileAsInputStream(String name); String getDirectory(); void setDirectory(String directory);  }### Answer:
@Test public void shouldSaveFileWithoutNameProvided() throws Exception { InputStream inputStream = new ReaderInputStream(new StringReader(CONTENT)); when(fileDAO.saveOrUpdate(ArgumentMatchers.any(File.class))).thenAnswer(invocation -> invocation.getArgument(0)); File result = fileSystemFileStorageService.saveFile(inputStream, CONTENT_TYPE); verify(fileDAO).saveOrUpdate(ArgumentMatchers.any(File.class)); assertThat(result.getName()).isNotBlank(); assertThat(result.getContentType()).isEqualTo(CONTENT_TYPE); Path savedFilePath = Paths.get(fileSystemFileStorageService.getDirectory(), result.getName()); assertThat(savedFilePath).hasContent(CONTENT); }
@Test public void shouldSaveFileWithNameProvided() throws Exception { InputStream inputStream = new ReaderInputStream(new StringReader(CONTENT)); when(fileDAO.saveOrUpdate(ArgumentMatchers.any(File.class))).thenAnswer(invocation -> invocation.getArgument(0)); File result = fileSystemFileStorageService.saveFile(inputStream, FILE_NAME, CONTENT_TYPE); verify(fileDAO).saveOrUpdate(ArgumentMatchers.any(File.class)); assertThat(result.getName()).isEqualTo(FILE_NAME); assertThat(result.getContentType()).isEqualTo(CONTENT_TYPE); Path savedFilePath = Paths.get(fileSystemFileStorageService.getDirectory(), FILE_NAME); assertThat(savedFilePath).hasContent(CONTENT); }