### Question:
PersistenceOperations { @Nonnull public Single<Boolean> directoryContainsShareFiles(@Nonnull final File directory) { checkNotNull(directory, "\'directory\' must not be null."); return rxFiles .getFilesInDirectory(directory) .map(File::getName) .map(name -> name.matches("share-\\d+")) .reduce(true, (noPreviousMatches, thisMatches) -> noPreviousMatches && !thisMatches) .map(noMatches -> !noMatches); } PersistenceOperations(
      @Nonnull final ShareSerialiser shareSerialiser,
      @Nonnull final RecoverySchemeSerialiser recoverySchemeSerialiser,
      @Nonnull final RxFiles rxFiles); @Nonnull Completable saveShareToFile(@Nonnull final Share share, @Nonnull final File file); @Nonnull Completable saveRecoverySchemeToFile(@Nonnull final RecoveryScheme recoveryScheme, @Nonnull final File file); @Nonnull Single<File> defineNewShareFile(@Nonnull final Share share, @Nonnull final File directory); @Nonnull Single<File> defineNewRecoverySchemeFile(@Nonnull final File directory); @Nonnull Single<Boolean> directoryContainsShareFiles(@Nonnull final File directory); @Nonnull Single<Boolean> directoryContainsRecoverySchemeFiles(@Nonnull final File directory);  }### Answer:
@Test(expected = IllegalArgumentException.class) public void testDirectoryContainsShare_nullDirectory() { persistenceOperations.directoryContainsShareFiles(null); }
@Test public void testDirectoryContainsShareFile_directoryContainsNoShareFiles() { final File directory = new File("test"); final List<File> files = ImmutableList.of( new File("shre-1"), new File("share-"), new File("share1"), new File("share-1a1"), new File("share--1"), new File("Share-1"), new File("share 1"), new File("SHARE-1"), new File("Share 1"), new File("-"), new File("-1")); when(rxFiles.getFilesInDirectory(directory)).thenReturn(Observable.fromIterable(files)); persistenceOperations .directoryContainsShareFiles(directory) .test() .awaitDone(200, MILLISECONDS) .assertNoErrors() .assertValue(false); }
@Test public void testDirectoryContainsShareFile_directoryContainsOneShareFile() { final File directory = new File("test"); when(rxFiles.getFilesInDirectory(directory)).thenReturn(Observable.just(new File("share-1"))); persistenceOperations .directoryContainsShareFiles(directory) .test() .awaitDone(200, MILLISECONDS) .assertNoErrors() .assertValue(true); }
@Test public void testDirectoryContainsShareFile_directoryContainsTwoShareFiles() { final File directory = new File("test"); final List<File> files = ImmutableList.of(new File("share-1"), new File("share-2")); when(rxFiles.getFilesInDirectory(directory)).thenReturn(Observable.fromIterable(files)); persistenceOperations .directoryContainsShareFiles(directory) .test() .awaitDone(200, MILLISECONDS) .assertNoErrors() .assertValue(true); }