// Path: src/test/java/bbejeck/nio/files/BaseFileTest.java
// public class BaseFileTest {
//     protected String baseDir = "test-files";
//     protected String dir1 = "dir1";
//     protected String dir2 = "dir2";
//     protected String fileName;
//     protected String fooDir = "foo";
//     protected String copyDir = "copy";
//     protected String tempDir = "temp";
//     protected Path basePath;
//     protected Path dir1Path;
//     protected Path dir2Path;
//     protected Path fooPath;
//     protected Path sourcePath;
//     protected Path copyPath;
//     protected String[] fakeJavaFiles = new String[]{"Code.java", "Foo.java", "Bar.java", "Baz.java"};
//     protected String[] textFileNames = new String[]{"persons.csv", "counts.csv", "CountyTaxes.csv"};
// 
// 
//     @Before
//     public void setUp() throws Exception {
//         createPaths();
//         cleanUp();
//         createDirectories();
//         generateFile(Paths.get(baseDir, fileName), 500);
//         generateFiles(basePath, fakeJavaFiles, textFileNames);
//         generateFiles(dir1Path, fakeJavaFiles);
//         generateFiles(dir2Path, fakeJavaFiles);
//     }
// 
//     protected void createPaths() {
//         basePath = Paths.get(baseDir);
//         dir1Path = basePath.resolve(dir1);
//         dir2Path = basePath.resolve(dir2);
//         fileName = "test.txt";
//         sourcePath = basePath.resolve(fileName);
//         copyPath = basePath.resolve(copyDir);
//         fooPath = basePath.resolve(fooDir);
//     }
// 
//     protected void cleanUp() throws Exception {
//         DirUtils.deleteIfExists(basePath);
//         Files.deleteIfExists(basePath.resolve(Paths.get(copyDir, fooDir)));
//         Files.deleteIfExists(basePath.resolve(Paths.get(copyDir, tempDir)));
//         Files.deleteIfExists(basePath.resolve(tempDir));
//         Files.deleteIfExists(basePath.resolve("tempII"));
//     }
// 
//     protected void createDirectories() throws Exception {
//         Files.createDirectories(dir1Path);
//         Files.createDirectories(dir2Path);
//         Files.createDirectories(copyPath);
//         Files.createDirectories(fooPath);
//     }
// 
//     protected void generateFile(Path path, int numberLines) throws Exception {
//         FileGenerator.generate(path, numberLines);
//     }
// 
//     protected void generateFiles(Path path, String[]... fileNames) throws Exception {
//         for (String[] fileNamesArray : fileNames) {
//             for (String fileName : fileNamesArray) {
//                 generateFile(path.resolve(fileName), 10);
//             }
//         }
//     }
// }
// 
// Path: src/main/java/bbejeck/nio/files/event/PathEventContext.java
// public interface PathEventContext {
// 
//     boolean isValid();
// 
//     Path getWatchedDirectory();
// 
//     List<PathEvent> getEvents();
// 
// }
// 
// Path: src/main/java/bbejeck/nio/files/event/PathEventSubscriber.java
// public interface PathEventSubscriber {
// 
//     void handlePathEvents(PathEventContext pathEventContext);
// }


import bbejeck.nio.files.BaseFileTest;
import bbejeck.nio.files.event.PathEventContext;
import bbejeck.nio.files.event.PathEventSubscriber;
import com.google.common.eventbus.EventBus;
import com.google.common.eventbus.Subscribe;
import com.google.inject.Guice;
import com.google.inject.Injector;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import java.nio.file.Path;
import java.util.*;
import java.util.concurrent.CountDownLatch;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
package bbejeck.nio.files.directory.event;




/**
 * Created by IntelliJ IDEA.
 * User: bbejeck
 * Date: 2/25/12
 */
public class DirectoryEventWatcherGuiceTest extends BaseFileTest {

    private DirectoryEventWatcher directoryEventWatcher;
    private CountDownLatch latch;
    private TestSubscriber subscriber;

    @Before
    public void setUp() throws Exception {
        createPaths();
        cleanUp();
        createDirectories();
        latch = new CountDownLatch(3);
        Injector injector = Guice.createInjector(new DirectoryEventModule());
        directoryEventWatcher = injector.getInstance(DirectoryEventWatcher.class);
        EventBus eventBus = injector.getInstance(EventBus.class);
        subscriber = new TestSubscriber();
        eventBus.register(subscriber);
        directoryEventWatcher.start();
    }

    @Test
    public void testDirectoryForWrittenEvents() throws Exception {
        Map<Path, String> eventResultsMap = new HashMap<>();
        assertThat(directoryEventWatcher.isRunning(), is(true));
        generateFile(dir1Path.resolve("newTextFile.txt"), 10);
        generateFile(basePath.resolve("newTextFileII.txt"), 10);
        generateFile(dir2Path.resolve("newTextFileIII.txt"), 10);
        latch.await();

        assertThat(subscriber.pathEvents.size(), is(3));
// Path: src/test/java/bbejeck/nio/files/BaseFileTest.java
// public class BaseFileTest {
//     protected String baseDir = "test-files";
//     protected String dir1 = "dir1";
//     protected String dir2 = "dir2";
//     protected String fileName;
//     protected String fooDir = "foo";
//     protected String copyDir = "copy";
//     protected String tempDir = "temp";
//     protected Path basePath;
//     protected Path dir1Path;
//     protected Path dir2Path;
//     protected Path fooPath;
//     protected Path sourcePath;
//     protected Path copyPath;
//     protected String[] fakeJavaFiles = new String[]{"Code.java", "Foo.java", "Bar.java", "Baz.java"};
//     protected String[] textFileNames = new String[]{"persons.csv", "counts.csv", "CountyTaxes.csv"};
// 
// 
//     @Before
//     public void setUp() throws Exception {
//         createPaths();
//         cleanUp();
//         createDirectories();
//         generateFile(Paths.get(baseDir, fileName), 500);
//         generateFiles(basePath, fakeJavaFiles, textFileNames);
//         generateFiles(dir1Path, fakeJavaFiles);
//         generateFiles(dir2Path, fakeJavaFiles);
//     }
// 
//     protected void createPaths() {
//         basePath = Paths.get(baseDir);
//         dir1Path = basePath.resolve(dir1);
//         dir2Path = basePath.resolve(dir2);
//         fileName = "test.txt";
//         sourcePath = basePath.resolve(fileName);
//         copyPath = basePath.resolve(copyDir);
//         fooPath = basePath.resolve(fooDir);
//     }
// 
//     protected void cleanUp() throws Exception {
//         DirUtils.deleteIfExists(basePath);
//         Files.deleteIfExists(basePath.resolve(Paths.get(copyDir, fooDir)));
//         Files.deleteIfExists(basePath.resolve(Paths.get(copyDir, tempDir)));
//         Files.deleteIfExists(basePath.resolve(tempDir));
//         Files.deleteIfExists(basePath.resolve("tempII"));
//     }
// 
//     protected void createDirectories() throws Exception {
//         Files.createDirectories(dir1Path);
//         Files.createDirectories(dir2Path);
//         Files.createDirectories(copyPath);
//         Files.createDirectories(fooPath);
//     }
// 
//     protected void generateFile(Path path, int numberLines) throws Exception {
//         FileGenerator.generate(path, numberLines);
//     }
// 
//     protected void generateFiles(Path path, String[]... fileNames) throws Exception {
//         for (String[] fileNamesArray : fileNames) {
//             for (String fileName : fileNamesArray) {
//                 generateFile(path.resolve(fileName), 10);
//             }
//         }
//     }
// }
// 
// Path: src/main/java/bbejeck/nio/files/event/PathEventContext.java
// public interface PathEventContext {
// 
//     boolean isValid();
// 
//     Path getWatchedDirectory();
// 
//     List<PathEvent> getEvents();
// 
// }
// 
// Path: src/main/java/bbejeck/nio/files/event/PathEventSubscriber.java
// public interface PathEventSubscriber {
// 
//     void handlePathEvents(PathEventContext pathEventContext);
// }


// Path: src/test/java/bbejeck/nio/files/directory/event/DirectoryEventWatcherGuiceTest.java
import bbejeck.nio.files.BaseFileTest;
import bbejeck.nio.files.event.PathEventContext;
import bbejeck.nio.files.event.PathEventSubscriber;
import com.google.common.eventbus.EventBus;
import com.google.common.eventbus.Subscribe;
import com.google.inject.Guice;
import com.google.inject.Injector;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import java.nio.file.Path;
import java.util.*;
import java.util.concurrent.CountDownLatch;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;

package bbejeck.nio.files.directory.event;




/**
 * Created by IntelliJ IDEA.
 * User: bbejeck
 * Date: 2/25/12
 */
public class DirectoryEventWatcherGuiceTest extends BaseFileTest {

    private DirectoryEventWatcher directoryEventWatcher;
    private CountDownLatch latch;
    private TestSubscriber subscriber;

    @Before
    public void setUp() throws Exception {
        createPaths();
        cleanUp();
        createDirectories();
        latch = new CountDownLatch(3);
        Injector injector = Guice.createInjector(new DirectoryEventModule());
        directoryEventWatcher = injector.getInstance(DirectoryEventWatcher.class);
        EventBus eventBus = injector.getInstance(EventBus.class);
        subscriber = new TestSubscriber();
        eventBus.register(subscriber);
        directoryEventWatcher.start();
    }

    @Test
    public void testDirectoryForWrittenEvents() throws Exception {
        Map<Path, String> eventResultsMap = new HashMap<>();
        assertThat(directoryEventWatcher.isRunning(), is(true));
        generateFile(dir1Path.resolve("newTextFile.txt"), 10);
        generateFile(basePath.resolve("newTextFileII.txt"), 10);
        generateFile(dir2Path.resolve("newTextFileIII.txt"), 10);
        latch.await();

        assertThat(subscriber.pathEvents.size(), is(3));
        List<PathEventContext> eventContexts = subscriber.pathEvents;