org.sonatype.sisu.litmus.testsupport.hamcrest
Class FileMatchers

java.lang.Object
  extended by org.sonatype.sisu.litmus.testsupport.hamcrest.FileMatchers

public class FileMatchers
extends Object

Some ideas copied freely from http://www.time4tea.net/wiki/display/MAIN/Testing+Files+with+Hamcrest

Converted to pure Hamcrest

Author:
time4tea technology ltd 2007, plynch

Constructor Summary
FileMatchers()
           
 
Method Summary
static org.hamcrest.Matcher<File> contains(String... entries)
           
static org.hamcrest.Matcher<ZipFile> containsEntry(String entryName)
           
static org.hamcrest.Matcher<File> containsOnly(String content)
          Assert a file contains only the specified string content
static org.hamcrest.Matcher<File> doesNotContain(String... entries)
           
static org.hamcrest.Matcher<File> exists()
           
static org.hamcrest.Matcher<File> isDirectory()
           
static org.hamcrest.Matcher<? super File> isEmpty()
           
static org.hamcrest.Matcher<File> isFile()
           
static org.hamcrest.Matcher<File> named(String name)
           
static org.hamcrest.Matcher<File> readable()
           
static String readFully(File file)
          Read from file till EOF.
static String readFully(Reader rdr)
          Read from reader till EOF.
static String readFully(Reader rdr, int bufferSize)
          Read from reader till EOF.
static org.hamcrest.Matcher<File> sized(Long size)
           
static org.hamcrest.Matcher<File> sized(org.hamcrest.Matcher<Long> size)
           
static org.hamcrest.Matcher<File> withAbsolutePath(String path)
           
static org.hamcrest.Matcher<File> withCanonicalPath(String path)
           
static org.hamcrest.Matcher<File> writable()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileMatchers

public FileMatchers()
Method Detail

isDirectory

public static org.hamcrest.Matcher<File> isDirectory()

exists

public static org.hamcrest.Matcher<File> exists()

isFile

public static org.hamcrest.Matcher<File> isFile()

readable

public static org.hamcrest.Matcher<File> readable()

writable

public static org.hamcrest.Matcher<File> writable()

sized

public static org.hamcrest.Matcher<File> sized(Long size)

sized

public static org.hamcrest.Matcher<File> sized(org.hamcrest.Matcher<Long> size)

named

public static org.hamcrest.Matcher<File> named(String name)

withCanonicalPath

public static org.hamcrest.Matcher<File> withCanonicalPath(String path)

withAbsolutePath

public static org.hamcrest.Matcher<File> withAbsolutePath(String path)

contains

public static org.hamcrest.Matcher<File> contains(String... entries)

containsOnly

public static org.hamcrest.Matcher<File> containsOnly(String content)
Assert a file contains only the specified string content


doesNotContain

public static org.hamcrest.Matcher<File> doesNotContain(String... entries)

containsEntry

public static org.hamcrest.Matcher<ZipFile> containsEntry(String entryName)

readFully

public static String readFully(File file)
                        throws IOException
Read from file till EOF. FIXME: why is this here? move to util class, this class for Matchers only

Parameters:
file - the file from which to read
Returns:
the contents read out of the given file
Throws:
IOException - if the contents could not be read out from the reader.

readFully

public static String readFully(Reader rdr)
                        throws IOException
Read from reader till EOF. FIXME: why is this here? move to util class, this class for Matchers only

Parameters:
rdr - the reader from which to read.
Returns:
the contents read out of the given reader.
Throws:
IOException - if the contents could not be read out from the reader.

readFully

public static String readFully(Reader rdr,
                               int bufferSize)
                        throws IOException
Read from reader till EOF. FIXME: why is this here? move to util class, this class for Matchers only

Parameters:
rdr - the reader from which to read.
bufferSize - the buffer size to use when reading.
Returns:
the contents read out of the given reader.
Throws:
IOException - if the contents could not be read out from the reader.

isEmpty

public static org.hamcrest.Matcher<? super File> isEmpty()
Returns:
a matcher that checks if a File (directory) is empty!


Copyright © 2008-2012 Sonatype, Inc.. All Rights Reserved.