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

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

public class StreamsEqualContentAs
     
     
extends AbstractEqualContentAs< InputStream>

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

 
   
   

Add Import

import static de.smartics.util.test.matcher.io.StreamsEqualContentAs.streamsEqualContentAs;

In the following examples expected and actual are InputStreams:

 
   
   

Assert Example

import static org.hamcrest.MatcherAssert.assertThat;

assertThat(actual, streamsEqualContentAs(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 stream

verify(spy).pass(
    (InputStream) argThat(streamsEqualContentAs(expected)));


Constructor Summary
StreamsEqualContentAs(InputStream expected, String encoding)
          Default constructor.
StreamsEqualContentAs(String expected, String encoding)
          Convenience constructor if the content is served as a String.
 
Method Summary
static org.hamcrest.Matcher<? super InputStream> streamsEqualContentAs(InputStream expected)
          Factory method to create the matcher defaulting to UTF-8.
static org.hamcrest.Matcher<? super InputStream> streamsEqualContentAs(InputStream expected, String encoding)
          Factory method to create the matcher.
static org.hamcrest.Matcher<? super InputStream> streamsEqualContentAs(String expected)
          Factory method to create the matcher for a preconfigured String with UTF-8 encoding.
static org.hamcrest.Matcher<? super InputStream> streamsEqualContentAs(String expected, String encoding)
          Factory method to create the matcher for a preconfigured String.
protected  String toString(InputStream 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

StreamsEqualContentAs

public StreamsEqualContentAs(InputStream expected,
                             String encoding)
                      throws IllegalArgumentException
Default constructor.

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

StreamsEqualContentAs

public StreamsEqualContentAs(String expected,
                             String encoding)
Convenience constructor if the content is served as a String.

Parameters:
expected - the expected content.
encoding - the encoding expected on both streams.
Method Detail

toString

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

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

streamsEqualContentAs

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

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

streamsEqualContentAs

public static org.hamcrest.Matcher<? super InputStream> streamsEqualContentAs(InputStream expected)
                                                                       throws IllegalArgumentException
Factory method to create the matcher defaulting to UTF-8.

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

streamsEqualContentAs

public static org.hamcrest.Matcher<? super InputStream> streamsEqualContentAs(String expected,
                                                                              String encoding)
Factory method to create the matcher for a preconfigured String.

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

streamsEqualContentAs

public static org.hamcrest.Matcher<? super InputStream> streamsEqualContentAs(String expected)
Factory method to create the matcher for a preconfigured String with UTF-8 encoding.

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


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