// Path: src/main/java/com/github/mlk/junit/matchers/HadoopMatchers.java
// public static Matcher<HadoopDFSRule> exists(String file) {
//   return new HadoopPathExists(file);
// }
// 
// Path: src/main/java/com/github/mlk/junit/rules/HadoopDFSRule.java
// public class HadoopDFSRule extends ExternalResource {
// 
//   private HdfsConfiguration conf;
//   private MiniDFSCluster cluster;
// 
//   private FileSystem mfs;
//   private FileContext mfc;
// 
//   protected HdfsConfiguration createConfiguration() {
//     return new HdfsConfiguration();
//   }
// 
//   public HdfsConfiguration getConfiguration() {
//     return conf;
//   }
// 
//   @Override
//   protected void before() throws Throwable {
//     conf = createConfiguration();
//     cluster = new MiniDFSCluster.Builder(conf).numDataNodes(3).build();
//     cluster.waitActive();
//     mfs = cluster.getFileSystem();
//     mfc = FileContext.getFileContext();
//   }
// 
//   @Override
//   protected void after() {
//     cluster.shutdown(true);
//   }
// 
//   /**
//    * @return Returns the file system on the Hadoop mini-cluster.
//    */
//   public FileSystem getMfs() {
//     return mfs;
//   }
// 
//   /**
//    * @return Returns the port of the name node in the mini-cluster.
//    */
//   public int getNameNodePort() {
//     return cluster.getNameNodePort();
//   }
// 
//   /**
//    * Writes the following content to the Hadoop cluster.
//    *
//    * @param filename File to be created
//    * @param content The content to write
//    * @throws IOException Anything.
//    */
//   public void write(String filename, String content) throws IOException {
//     FSDataOutputStream s = getMfs().create(new Path(filename));
//     s.writeBytes(content);
//     s.close();
//   }
// 
//   /**
//    * Copies the content of the given resource into Hadoop.
//    *
//    * @param filename File to be created
//    * @param resource Resource to copy
//    * @throws IOException Anything
//    */
//   public void copyResource(String filename, String resource) throws IOException {
//     write(filename, IOUtils.toByteArray(getClass().getResource(resource)));
//   }
// 
//   /**
//    * Writes the following content to the Hadoop cluster.
//    *
//    * @param filename File to be created
//    * @param content The content to write
//    * @throws IOException Anything
//    */
//   public void write(String filename, byte[] content) throws IOException {
//     FSDataOutputStream s = getMfs().create(new Path(filename));
//     s.write(content);
//     s.close();
//   }
// 
//   /**
//    * Fully reads the content of the given file.
//    *
//    * @param filename File to read
//    * @return Content of the file
//    * @throws IOException Anything
//    */
//   public String read(String filename) throws IOException {
//     Path p = new Path(filename);
//     int size = (int) getMfs().getFileStatus(p).getLen();
//     FSDataInputStream is = getMfs().open(p);
//     byte[] content = new byte[size];
//     is.readFully(content);
//     return new String(content);
//   }
// 
//   /**
//    * Checks if the given path exists on Hadoop.
//    *
//    * @param filename Filename to check
//    * @return true if the file exists
//    * @throws IOException Anything
//    * @deprecated Badly named, use exists instead
//    */
//   @Deprecated
//   public boolean exist(String filename) throws IOException {
//     return exists(filename);
//   }
// 
//   /**
//    * Checks if the given path exists on Hadoop.
//    *
//    * @param filename Filename to check
//    * @throws IOException Anything
//    * @return true if the file exists
//    */
//   public boolean exists(String filename) throws IOException {
//     return exists(new Path(filename));
//   }
// 
//   /**
//    * Checks if the given path exists on Hadoop.
//    *
//    * @param filename Filename to check
//    * @throws IOException Anything
//    * @return true if the file exists
//    */
//   public boolean exists(Path filename) throws IOException {
//     try {
//       return getMfs().listFiles(filename, true).hasNext();
//     } catch (FileNotFoundException e) {
//       return false;
//     }
//   }
// }


import static com.github.mlk.junit.matchers.HadoopMatchers.exists;
import static org.hamcrest.core.IsNot.not;
import static org.junit.Assert.assertThat;
import com.github.mlk.junit.rules.HadoopDFSRule;
import java.io.IOException;
import org.junit.Rule;
import org.junit.Test;
package com.github.mlk.junit.matchers;



public class HadoopMatchersTest {

  @Rule
  public HadoopDFSRule hadoop = new HadoopDFSRule();

  @Test
  public void whenFileExistsReturnTrue() throws IOException {
    hadoop.write("/hello.txt", "content");

// Path: src/main/java/com/github/mlk/junit/matchers/HadoopMatchers.java
// public static Matcher<HadoopDFSRule> exists(String file) {
//   return new HadoopPathExists(file);
// }
// 
// Path: src/main/java/com/github/mlk/junit/rules/HadoopDFSRule.java
// public class HadoopDFSRule extends ExternalResource {
// 
//   private HdfsConfiguration conf;
//   private MiniDFSCluster cluster;
// 
//   private FileSystem mfs;
//   private FileContext mfc;
// 
//   protected HdfsConfiguration createConfiguration() {
//     return new HdfsConfiguration();
//   }
// 
//   public HdfsConfiguration getConfiguration() {
//     return conf;
//   }
// 
//   @Override
//   protected void before() throws Throwable {
//     conf = createConfiguration();
//     cluster = new MiniDFSCluster.Builder(conf).numDataNodes(3).build();
//     cluster.waitActive();
//     mfs = cluster.getFileSystem();
//     mfc = FileContext.getFileContext();
//   }
// 
//   @Override
//   protected void after() {
//     cluster.shutdown(true);
//   }
// 
//   /**
//    * @return Returns the file system on the Hadoop mini-cluster.
//    */
//   public FileSystem getMfs() {
//     return mfs;
//   }
// 
//   /**
//    * @return Returns the port of the name node in the mini-cluster.
//    */
//   public int getNameNodePort() {
//     return cluster.getNameNodePort();
//   }
// 
//   /**
//    * Writes the following content to the Hadoop cluster.
//    *
//    * @param filename File to be created
//    * @param content The content to write
//    * @throws IOException Anything.
//    */
//   public void write(String filename, String content) throws IOException {
//     FSDataOutputStream s = getMfs().create(new Path(filename));
//     s.writeBytes(content);
//     s.close();
//   }
// 
//   /**
//    * Copies the content of the given resource into Hadoop.
//    *
//    * @param filename File to be created
//    * @param resource Resource to copy
//    * @throws IOException Anything
//    */
//   public void copyResource(String filename, String resource) throws IOException {
//     write(filename, IOUtils.toByteArray(getClass().getResource(resource)));
//   }
// 
//   /**
//    * Writes the following content to the Hadoop cluster.
//    *
//    * @param filename File to be created
//    * @param content The content to write
//    * @throws IOException Anything
//    */
//   public void write(String filename, byte[] content) throws IOException {
//     FSDataOutputStream s = getMfs().create(new Path(filename));
//     s.write(content);
//     s.close();
//   }
// 
//   /**
//    * Fully reads the content of the given file.
//    *
//    * @param filename File to read
//    * @return Content of the file
//    * @throws IOException Anything
//    */
//   public String read(String filename) throws IOException {
//     Path p = new Path(filename);
//     int size = (int) getMfs().getFileStatus(p).getLen();
//     FSDataInputStream is = getMfs().open(p);
//     byte[] content = new byte[size];
//     is.readFully(content);
//     return new String(content);
//   }
// 
//   /**
//    * Checks if the given path exists on Hadoop.
//    *
//    * @param filename Filename to check
//    * @return true if the file exists
//    * @throws IOException Anything
//    * @deprecated Badly named, use exists instead
//    */
//   @Deprecated
//   public boolean exist(String filename) throws IOException {
//     return exists(filename);
//   }
// 
//   /**
//    * Checks if the given path exists on Hadoop.
//    *
//    * @param filename Filename to check
//    * @throws IOException Anything
//    * @return true if the file exists
//    */
//   public boolean exists(String filename) throws IOException {
//     return exists(new Path(filename));
//   }
// 
//   /**
//    * Checks if the given path exists on Hadoop.
//    *
//    * @param filename Filename to check
//    * @throws IOException Anything
//    * @return true if the file exists
//    */
//   public boolean exists(Path filename) throws IOException {
//     try {
//       return getMfs().listFiles(filename, true).hasNext();
//     } catch (FileNotFoundException e) {
//       return false;
//     }
//   }
// }


// Path: src/test/java/com/github/mlk/junit/matchers/HadoopMatchersTest.java
import static com.github.mlk.junit.matchers.HadoopMatchers.exists;
import static org.hamcrest.core.IsNot.not;
import static org.junit.Assert.assertThat;
import com.github.mlk.junit.rules.HadoopDFSRule;
import java.io.IOException;
import org.junit.Rule;
import org.junit.Test;

package com.github.mlk.junit.matchers;



public class HadoopMatchersTest {

  @Rule
  public HadoopDFSRule hadoop = new HadoopDFSRule();

  @Test
  public void whenFileExistsReturnTrue() throws IOException {
    hadoop.write("/hello.txt", "content");

    assertThat(hadoop, exists("/hello.txt"));