@Test public void when_retrieve_a_file_it_should_give_the_good_content() throws IOException { filer.store(new ByteArrayInputStream(fakeContent), filename); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); filer.retrieve(outputStream, filename); assertThat(outputStream.toByteArray()).isEqualTo(expectedContent); }
@Test public void when_getting_the_content_lenght_of_the_file_it_should_the_expected_one() throws IOException { filer.store(new ByteArrayInputStream(fakeContent), filename); long actualLenght = filer.getContentLength(filename); assertThat(actualLenght).isEqualTo(rawContent.length); }
@Test public void when_delete_file_it_should_not_be_available_on_disk() throws IOException { filer.store(new ByteArrayInputStream(fakeContent), filename); File file = this.getFile(filename); assertThat(file).isNotNull(); assertThat(file.isFile()).isTrue(); filer.delete(filename); assertThat(file.isFile()).isFalse(); }
@Test public void when_store_a_file_it_should_be_available_on_disk_and_have_the_good_content() throws IOException { filer.store(new ByteArrayInputStream(fakeContent), filename); File file = this.getFile(filename); assertThat(file).isNotNull(); assertThat(file.isFile()).isTrue(); byte[] content = Files.toByteArray(file); assertThat(content).isEqualTo(rawContent); }
@Test public void when_retrieve_with_original_stream_a_file_it_should_give_the_good_content() throws IOException { filer.store(new ByteArrayInputStream(fakeContent), filename); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); InputStream dumpFileInputStream = filer.retrieveWithOriginalStream(filename); assertThat(dumpFileInputStream).isNotNull(); ByteStreams.copy(dumpFileInputStream, outputStream); outputStream.flush(); dumpFileInputStream.close(); outputStream.close(); assertThat(outputStream.toByteArray()).isEqualTo(rawContent); }