org.assertj.core.api
Class AbstractFileAssert<S extends AbstractFileAssert<S>>

java.lang.Object
  extended by org.assertj.core.api.AbstractAssert<S,File>
      extended by org.assertj.core.api.AbstractFileAssert<S>
Type Parameters:
S - the "self" type of this assertion class. Please read "Emulating 'self types' using Java Generics to simplify fluent API implementation" for more details.
All Implemented Interfaces:
Assert<S,File>, Descriptable<S>, ExtensionPoints<S,File>
Direct Known Subclasses:
FileAssert

public abstract class AbstractFileAssert<S extends AbstractFileAssert<S>>
extends AbstractAssert<S,File>

Base class for all implementations of assertions for Files.

Author:
David DIDIER, Yvonne Wang, Alex Ruiz, Olivier Michallat, Olivier Demeijer, Mikhail Mazursky, Jean-Christophe Gay

Field Summary
 
Fields inherited from class org.assertj.core.api.AbstractAssert
actual, info, myself
 
Constructor Summary
protected AbstractFileAssert(File actual, Class<?> selfType)
           
 
Method Summary
 S canRead()
          Verifies that the actual File can be read by the application.
 S canWrite()
          Verifies that the actual File can be modified by the application.
 S doesNotExist()
          Verifies that the actual File does not exist.
 S exists()
          Verifies that the actual File exists, regardless it's a file or directory.
 S hasBinaryContent(byte[] expected)
          Verifies that the binary content of the actual File is exactly equal to the given one.
 S hasContent(String expected)
          Verifies that the text content of the actual File is exactly equal to the given one.
The charset to use when reading the file should be provided with usingCharset(Charset) or usingCharset(String) prior to calling this method; if not, the platform's default charset (as returned by Charset.defaultCharset()) will be used.
 S hasContentEqualTo(File expected)
          Verifies that the content of the actual File is equal to the content of the given one.
 S hasExtension(String expected)
          Verifies that the actual File has given extension.
 S hasName(String expected)
          Verifies that the actual File has given name.
 S hasNoParent()
          Verifies that the actual File does not have a parent.
 S hasParent(File expected)
          Verifies that the actual File has given parent.
 S hasParent(String expected)
          Same as hasParent(java.io.File) but takes care of converting given String as File for you
 S isAbsolute()
          Verifies that the actual File is an absolute path.
 S isDirectory()
          Verifies that the actual File is an existing directory.
 S isFile()
          Verifies that the actual File is an existing file.
 S isRelative()
          Verifies that the actual File is a relative path.
 S usingCharset(Charset charset)
          Specifies the charset to use for text-based assertions on the file's contents.
 S usingCharset(String charsetName)
          Specifies the name of the charset to use for text-based assertions on the file's contents.
 
Methods inherited from class org.assertj.core.api.AbstractAssert
as, as, describedAs, describedAs, descriptionText, doesNotHave, doesNotHaveSameClassAs, equals, failWithMessage, getWritableAssertionInfo, has, hashCode, hasSameClassAs, inBinary, inHexadecimal, is, isEqualTo, isExactlyInstanceOf, isIn, isIn, isInstanceOf, isInstanceOfAny, isNot, isNotEqualTo, isNotExactlyInstanceOf, isNotIn, isNotIn, isNotInstanceOf, isNotInstanceOfAny, isNotNull, isNotOfAnyClassIn, isNotSameAs, isNull, isOfAnyClassIn, isSameAs, overridingErrorMessage, usingComparator, usingDefaultComparator
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractFileAssert

protected AbstractFileAssert(File actual,
                             Class<?> selfType)
Method Detail

exists

public S exists()
Verifies that the actual File exists, regardless it's a file or directory.

Returns:
this assertion object.
Throws:
AssertionError - if the actual File is null.
AssertionError - if the actual File does not exist.

doesNotExist

public S doesNotExist()
Verifies that the actual File does not exist.

Returns:
this assertion object.
Throws:
AssertionError - if the actual File is null.
AssertionError - if the actual File exists.

isFile

public S isFile()
Verifies that the actual File is an existing file.

Returns:
this assertion object.
Throws:
AssertionError - if the actual File is null.
AssertionError - if the actual File is not an existing file.

isDirectory

public S isDirectory()
Verifies that the actual File is an existing directory.

Returns:
this assertion object.
Throws:
AssertionError - if the actual File is null.
AssertionError - if the actual File is not an existing file.

isAbsolute

public S isAbsolute()
Verifies that the actual File is an absolute path.

Returns:
this assertion object.
Throws:
AssertionError - if the actual File is null.
AssertionError - if the actual File is not an absolute path.

isRelative

public S isRelative()
Verifies that the actual File is a relative path.

Returns:
this assertion object.
Throws:
AssertionError - if the actual File is null.
AssertionError - if the actual File is not a relative path.

hasContentEqualTo

public S hasContentEqualTo(File expected)
Verifies that the content of the actual File is equal to the content of the given one.

Parameters:
expected - the given File to compare the actual File to.
Returns:
this assertion object.
Throws:
NullPointerException - if the given File is null.
IllegalArgumentException - if the given File is not an existing file.
AssertionError - if the actual File is null.
AssertionError - if the actual File is not an existing file.
FilesException - if an I/O error occurs.
AssertionError - if the content of the actual File is not equal to the content of the given one.

hasBinaryContent

public S hasBinaryContent(byte[] expected)
Verifies that the binary content of the actual File is exactly equal to the given one.

Parameters:
expected - the expected binary content to compare the actual File's content to.
Returns:
this assertion object.
Throws:
NullPointerException - if the given content is null.
AssertionError - if the actual File is null.
AssertionError - if the actual File is not an existing file.
FilesException - if an I/O error occurs.
AssertionError - if the content of the actual File is not equal to the given binary content.

usingCharset

public S usingCharset(String charsetName)
Specifies the name of the charset to use for text-based assertions on the file's contents.

Parameters:
charsetName - the name of the charset to use.
Returns:
this assertion object.
Throws:
IllegalArgumentException - if the given encoding is not supported on this platform.

usingCharset

public S usingCharset(Charset charset)
Specifies the charset to use for text-based assertions on the file's contents.

Parameters:
charset - the charset to use.
Returns:
this assertion object.
Throws:
NullPointerException - if the given charset is null.

hasContent

public S hasContent(String expected)
Verifies that the text content of the actual File is exactly equal to the given one.
The charset to use when reading the file should be provided with usingCharset(Charset) or usingCharset(String) prior to calling this method; if not, the platform's default charset (as returned by Charset.defaultCharset()) will be used.

Parameters:
expected - the expected text content to compare the actual File's content to.
Returns:
this assertion object.
Throws:
NullPointerException - if the given content is null.
AssertionError - if the actual File is null.
AssertionError - if the actual File is not an existing file.
FilesException - if an I/O error occurs.
AssertionError - if the content of the actual File is not equal to the given binary content.

canWrite

public S canWrite()
Verifies that the actual File can be modified by the application.

Returns:
this assertion object.
Throws:
AssertionError - if the actual File is null.
AssertionError - if the actual File can not be modified by the application.

canRead

public S canRead()
Verifies that the actual File can be read by the application.

Returns:
this assertion object.
Throws:
AssertionError - if the actual File is null.
AssertionError - if the actual File can not be read by the application.

hasParent

public S hasParent(File expected)
Verifies that the actual File has given parent.

Example:

 File xFile = new File("mulder/xFile");
 
 // assertion will pass
 assertThat(xFile).hasParent(new File("mulder"));

 // assertion will fail
 assertThat(xFile).hasParent(new File("scully"));
 

Parameters:
expected - the expected parent File.
Returns:
this assertion object.
Throws:
NullPointerException - if the expected parent File is null.
FilesException - if an I/O error occurs.
AssertionError - if the actual File is null.
AssertionError - if the actual File parent is not equal to the expected one.
See Also:
parent definition.

hasParent

public S hasParent(String expected)
Same as hasParent(java.io.File) but takes care of converting given String as File for you

Example:

 File xFile = new File("mulder/xFile");
 
 // assertion will pass
 assertThat(xFile).hasParent("mulder");

 // assertion will fail
 assertThat(xFile).hasParent("scully");
 


hasExtension

public S hasExtension(String expected)
Verifies that the actual File has given extension.

Example:

 File xFile = new File("xFile.java");
 
 // assertion will pass
 assertThat(xFile).hasExtension("java");
 
 // assertion will fail
 assertThat(xFile).hasExtension("png");
 

Parameters:
expected - the expected extension, it does not contains the '.'
Returns:
this assertion object.
Throws:
NullPointerException - if the expected extension is null.
AssertionError - if the actual File is null.
AssertionError - if the actual File is not a file (ie a directory).
AssertionError - if the actual File does not have the expected extension.
See Also:
Filename extension

hasName

public S hasName(String expected)
Verifies that the actual File has given name.

Example:

 File xFile = new File("somewhere/xFile.java");
 File xDirectory = new File("somewhere/xDirectory");
 
 // assertion will pass
 assertThat(xFile).hasName("xFile.java");
 assertThat(xDirectory).hasName("xDirectory");
 
 // assertion will fail
 assertThat(xFile).hasName("xFile");
 assertThat(xDirectory).hasName("somewhere");
 

Parameters:
expected - the expected File name.
Returns:
this assertion object.
Throws:
NullPointerException - if the expected name is null.
AssertionError - if the actual File is null.
AssertionError - if the actual File does not have the expected name.
See Also:
name definition.

hasNoParent

public S hasNoParent()
Verifies that the actual File does not have a parent.

Example:

 File xFile = new File("somewhere/xFile.java");
 File xDirectory = new File("xDirectory");
 
 // assertion will pass
 assertThat(xDirectory).hasNoParent();
 
 // assertion will fail
 assertThat(xFile).hasNoParent();
 

Returns:
this assertion object.
Throws:
AssertionError - if the actual File is null.
AssertionError - if the actual File has a parent.


Copyright © 2013–2015 AssertJ. All rights reserved.