de.smartics.util.test.matcher.io
Class ReadsEqualContentAs

Package class diagram package ReadsEqualContentAs
java.lang.Object
  extended by org.hamcrest.BaseMatcher<T>
      extended by org.hamcrest.TypeSafeDiagnosingMatcher<T>
          extended by de.smartics.util.test.matcher.io.AbstractEqualContentAs<Reader>
              extended by de.smartics.util.test.matcher.io.ReadsEqualContentAs
All Implemented Interfaces:
org.hamcrest.Matcher< Reader>, org.hamcrest.SelfDescribing

public class ReadsEqualContentAs
     
     
extends AbstractEqualContentAs< Reader>

A matcher to check that the contents of two stream contain the identical information.

 
   
   

Add Import

import static de.smartics.util.test.matcher.io.ReadsEqualContentAs.readsEqualContentAs;

In the following examples expected and actual are Readers:

 
   
   

Assert Example

import static org.hamcrest.MatcherAssert.assertThat;

assertThat(actual, readsEqualContentAs(expected));

The following example shows a test spy and the verification of the expected stream argument:

 
   
   

Verify Example

import static org.mockito.Matchers.argThat;
import static org.mockito.Mockito.verify;

spy.pass(actual); // Test spy that expects a reader

verify(spy).pass(
    (Reader) argThat(readsEqualContentAs(expected)));


Constructor Summary
ReadsEqualContentAs(Reader expected)
          Default constructor.
ReadsEqualContentAs(String expectedContent)
          Convenience constructor if the content is served as a String.
 
Method Summary
static org.hamcrest.Matcher<? super Reader> readsEqualContentAs(InputStream expected, String encoding)
          Factory method to create the matcher.
static org.hamcrest.Matcher<? super Reader> readsEqualContentAs(Reader expected)
          Factory method to create the matcher.
static org.hamcrest.Matcher<? super Reader> readsEqualContentAs(String expected)
          Factory method to create the matcher.
protected  String toString(Reader actual)
          Turns the instance to its string representation.
 
Methods inherited from class de.smartics.util.test.matcher.io.AbstractEqualContentAs
describeTo, getActualContent, matchesSafely
 
Methods inherited from class org.hamcrest.TypeSafeDiagnosingMatcher
describeMismatch, matches
 
Methods inherited from class org.hamcrest.BaseMatcher
_dont_implement_Matcher___instead_extend_BaseMatcher_, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ReadsEqualContentAs

public ReadsEqualContentAs(Reader expected)
                    throws IllegalArgumentException
Default constructor.

Parameters:
expected - the other stream to compare to.
Throws:
IllegalArgumentException - on any problem reading from the stream.

ReadsEqualContentAs

public ReadsEqualContentAs(String expectedContent)
Convenience constructor if the content is served as a String.

Parameters:
expectedContent - the expected content.
Method Detail

toString

protected final String toString(Reader actual)
                         throws IllegalArgumentException
Turns the instance to its string representation.

Specified by:
toString in class AbstractEqualContentAs<Reader>
Parameters:
actual - the instance whose string representation is requested.
Returns:
the string representation of actual.
Throws:
IllegalArgumentException - if no string representation can be created.
See Also:
AbstractEqualContentAs.toString(java.lang.Object)

readsEqualContentAs

public static org.hamcrest.Matcher<? super Reader> readsEqualContentAs(Reader expected)
                                                                throws IllegalArgumentException
Factory method to create the matcher.

Parameters:
expected - the expected stream content.
Returns:
the created matcher.
Throws:
IllegalArgumentException - on any problem reading from the stream.

readsEqualContentAs

public static org.hamcrest.Matcher<? super Reader> readsEqualContentAs(InputStream expected,
                                                                       String encoding)
                                                                throws IllegalArgumentException
Factory method to create the matcher.

Parameters:
expected - the expected stream content.
encoding - the encoding used on the stream.
Returns:
the created matcher.
Throws:
IllegalArgumentException - on any problem reading from the stream.

readsEqualContentAs

public static org.hamcrest.Matcher<? super Reader> readsEqualContentAs(String expected)
Factory method to create the matcher.

Parameters:
expected - the expected stream content.
Returns:
the created matcher.


Copyright © 2008-2012 Kronseder & Reiner GmbH - smartics. All Rights Reserved.