### Question:
PersistenceOperations { @Nonnull public Single<Share> loadShareFromFile(@Nonnull final File file) { checkNotNull(file, "\'file\' cannot be null."); return rxFiles .readStringFromFile(file, CharsetConstants.SHARE_FILE_CHARSET) .flatMap(shareSerialiser::deserialise); } PersistenceOperations(
      @Nonnull final ShareSerialiser shareSerialiser,
      @Nonnull final RecoverySchemeSerialiser recoverySchemeSerialiser,
      @Nonnull final RxFiles rxFiles); @Nonnull Single<Share> loadShareFromFile(@Nonnull final File file); @Nonnull Single<Boolean> fileContainsShare(@Nonnull final File file); @Nonnull Single<RecoveryScheme> loadRecoverySchemeFromFile(@Nonnull final File file); @Nonnull Single<Boolean> fileContainsRecoveryScheme(@Nonnull final File file); @Nonnull Single<File> defineNewRecoveredSecretFile(@Nonnull final File directory); @Nonnull Single<Boolean> directoryContainsRecoveredSecretFile(@Nonnull final File directory);  }### Answer:
@Test(expected = IllegalArgumentException.class) public void testLoadShareFromFile_nullFile() { persistenceOperations.loadShareFromFile(null); }
@Test public void testLoadShareFromFile_fileDoesNotExist() { when(rxFiles.exists(file)).thenReturn(Single.just(false)); when(rxFiles.isFile(file)).thenReturn(Single.error(new IOException())); when(rxFiles.isDirectory(file)).thenReturn(Single.error(new IOException())); when(rxFiles.createNewFile(file)).thenReturn(Completable.complete()); when(rxFiles.createDirectory(file)).thenReturn(Completable.complete()); when(rxFiles.writeStringToFile(any(), eq(file), any())).thenReturn(Completable.error(new IOException())); when(rxFiles.readStringFromFile(eq(file), any())).thenReturn(Single.error(new IOException())); when(rxFiles.getFilesInDirectory(file)).thenReturn(Observable.error(new IOException())); persistenceOperations .loadShareFromFile(file) .test() .awaitDone(200, MILLISECONDS) .assertError(IOException.class); }
@Test public void testLoadShareFromFile_fileIsActuallyADirectory() { persistenceOperations .loadShareFromFile(directory) .test() .awaitDone(200, MILLISECONDS) .assertError(IOException.class); }
@Test public void testLoadShareFromFile_fileDoesNotContainAValidShare() { when(rxFiles.readStringFromFile(eq(file), any())).thenReturn(Single.just(SERIALISED_SHARE)); when(shareSerialiser.deserialise(SERIALISED_SHARE)) .thenReturn(Single.error(new DeserialisationException())); persistenceOperations .loadShareFromFile(file) .test() .awaitDone(200, MILLISECONDS) .assertError(DeserialisationException.class); }
@Test public void testLoadShareFromFile_readFails() { when(rxFiles.readStringFromFile(eq(file), any())).thenReturn(Single.error(new IOException())); persistenceOperations .loadShareFromFile(file) .test() .awaitDone(200, MILLISECONDS) .assertError(IOException.class); }
@Test public void testLoadShareFromFile_readSucceedsAndFileContainsAValidShare() { when(rxFiles.readStringFromFile(eq(file), any())).thenReturn(Single.just(SERIALISED_SHARE)); when(shareSerialiser.deserialise(SERIALISED_SHARE)).thenReturn(Single.just(SHARE)); persistenceOperations .loadShareFromFile(file) .test() .awaitDone(200, MILLISECONDS) .assertNoErrors() .assertValue(SHARE); }