### Question:
PersistenceOperations { @Nonnull public Single<RecoveryScheme> loadRecoverySchemeFromFile(@Nonnull final File file) { checkNotNull(file, "\'directory\' cannot be null."); return rxFiles .readStringFromFile(file, CharsetConstants.RECOVERY_SCHEME_CHARSET) .flatMap(recoverySchemeSerialiser::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 testLoadRecoverySchemeFromFile_nullFile() { persistenceOperations.loadRecoverySchemeFromFile(null); }
@Test public void testLoadRecoverySchemeFromFile_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 .loadRecoverySchemeFromFile(file) .test() .awaitDone(200, MILLISECONDS) .assertError(IOException.class); }
@Test public void testLoadRecoverySchemeFromFile_fileIsActuallyADirectory() { persistenceOperations .loadRecoverySchemeFromFile(directory) .test() .awaitDone(200, MILLISECONDS) .assertError(IOException.class); }
@Test public void testLoadRecoverySchemeFromFile_fileDoesNotContainAValidRecoveryScheme() { when(rxFiles.readStringFromFile(eq(file), any())).thenReturn(Single.just(SERIALISED_RECOVERY_SCHEME)); when(recoverySchemeSerialiser.deserialise(SERIALISED_RECOVERY_SCHEME)) .thenReturn(Single.error(new DeserialisationException())); persistenceOperations .loadRecoverySchemeFromFile(file) .test() .awaitDone(200, MILLISECONDS) .assertError(DeserialisationException.class); }
@Test public void testLoadRecoverySchemeFromFile_readFails() { when(rxFiles.readStringFromFile(eq(file), any())).thenReturn(Single.error(new IOException())); persistenceOperations .loadRecoverySchemeFromFile(file) .test() .awaitDone(200, MILLISECONDS) .assertError(IOException.class); }
@Test public void testLoadRecoverySchemeFromFile_readSucceedsAndFileContainsAValidRecoveryScheme() { when(rxFiles.readStringFromFile(eq(file), any())).thenReturn(Single.just(SERIALISED_RECOVERY_SCHEME)); when(recoverySchemeSerialiser.deserialise(SERIALISED_RECOVERY_SCHEME)).thenReturn(Single.just(RECOVERY_SCHEME)); persistenceOperations .loadRecoverySchemeFromFile(file) .test() .awaitDone(200, MILLISECONDS) .assertNoErrors() .assertValue(RECOVERY_SCHEME); }