### Question:
RxFiles { @Nonnull public Completable writeBytesToFile(@Nonnull final byte[] data, @Nonnull final File file) { checkNotNull(file, "\'file\' must not be null."); checkNotNull(data, "\'data\' must not be null."); return exists(file) .flatMapCompletable(exists -> exists ? Completable.complete() : Completable.error(new IOException("File does not exist."))) .andThen(Completable.fromAction(() -> FileUtils.writeByteArrayToFile(file, data))); }  @Nonnull Completable createDirectory(@Nonnull final File directory); @Nonnull Completable createNewFile(@Nonnull final File file); @Nonnull Completable delete(@Nonnull final File file); @Nonnull Observable<File> getFilesInDirectory(@Nonnull final File directory); @Nonnull Single<String> readStringFromFile(@Nonnull final File file, @Nonnull final Charset charset); @Nonnull Completable writeStringToFile(
      @Nonnull final String data,
      @Nonnull final File file,
      @Nonnull final Charset charset); @Nonnull Single<byte[]> readBytesFromFile(@Nonnull final File file); @Nonnull Completable writeBytesToFile(@Nonnull final byte[] data, @Nonnull final File file); @Nonnull Single<Boolean> exists(@Nonnull final File file); @Nonnull Single<Long> sizeInBytes(@Nonnull final File file); @Nonnull Single<Boolean> isFile(@Nonnull final File file); @Nonnull Single<Boolean> isDirectory(@Nonnull final File directory);  }### Answer:
@Test(expected = IllegalArgumentException.class) public void testWriteBytesToFile_nullFile() { rxFiles.writeBytesToFile(new byte[0], null); }
@Test(expected = IllegalArgumentException.class) public void testWriteBytesToFile_nullData() { rxFiles.writeBytesToFile(null, new File(testDirectory, "")); }
@Test public void testWriteBytesToFile_fileDoesNotExist() { final File file = new File(testDirectory, "test.txt"); rxFiles .writeBytesToFile(new byte[0], file) .test() .awaitDone(200, MILLISECONDS) .assertError(IOException.class) .assertNotComplete(); }
@Test public void testWriteBytesToFile_fileIsActuallyADirectory() throws IOException { final File file = new File(testDirectory, "test"); FileUtils.forceMkdir(file); rxFiles .writeBytesToFile(new byte[0], file) .test() .awaitDone(200, MILLISECONDS) .assertError(IOException.class) .assertNotComplete(); }