-
-
Notifications
You must be signed in to change notification settings - Fork 682
/
AbstractInputStreamAssert.java
81 lines (73 loc) · 3.54 KB
/
AbstractInputStreamAssert.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/**
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*
* Copyright 2012-2015 the original author or authors.
*/
package org.assertj.core.api;
import java.io.InputStream;
import org.assertj.core.internal.InputStreams;
import org.assertj.core.internal.InputStreamsException;
import org.assertj.core.util.VisibleForTesting;
/**
* Base class for all implementations of assertions for {@link InputStream}s.
* @param <S> the "self" type of this assertion class. Please read "<a href="http://bit.ly/1IZIRcY"
* target="_blank">Emulating 'self types' using Java Generics to simplify fluent API implementation</a>"
* for more details.
* @param <A> the type of the "actual" value.
*
* @author Matthieu Baechler
* @author Mikhail Mazursky
*/
public abstract class AbstractInputStreamAssert<S extends AbstractInputStreamAssert<S, A>, A extends InputStream> extends AbstractAssert<S, A> {
@VisibleForTesting
InputStreams inputStreams = InputStreams.instance();
protected AbstractInputStreamAssert(A actual, Class<?> selfType) {
super(actual, selfType);
}
/**
* Verifies that the content of the actual {@code InputStream} is equal to the content of the given one.
*
* @param expected the given {@code InputStream} to compare the actual {@code InputStream} to.
* @return {@code this} assertion object.
* @throws NullPointerException if the given {@code InputStream} is {@code null}.
* @throws AssertionError if the actual {@code InputStream} is {@code null}.
* @throws AssertionError if the content of the actual {@code InputStream} is not equal to the content of the given one.
* @throws InputStreamsException if an I/O error occurs.
*
* @deprecated use hasSameContentAs
*/
@Deprecated
public S hasContentEqualTo(InputStream expected) {
inputStreams.assertSameContentAs(info, actual, expected);
return myself;
}
/**
* Verifies that the content of the actual {@code InputStream} is equal to the content of the given one.
* <p/>
* Example:
* <pre><code class='java'> // assertion will pass
* assertThat(new ByteArrayInputStream(new byte[] {0xa})).hasSameContentAs(new ByteArrayInputStream(new byte[] {0xa}));
*
* // assertions will fail
* assertThat(new ByteArrayInputStream(new byte[] {0xa})).hasSameContentAs(new ByteArrayInputStream(new byte[] {}));
* assertThat(new ByteArrayInputStream(new byte[] {0xa})).hasSameContentAs(new ByteArrayInputStream(new byte[] {0xa, 0xc, 0xd}));</code></pre>
*
* @param expected the given {@code InputStream} to compare the actual {@code InputStream} to.
* @return {@code this} assertion object.
* @throws NullPointerException if the given {@code InputStream} is {@code null}.
* @throws AssertionError if the actual {@code InputStream} is {@code null}.
* @throws AssertionError if the content of the actual {@code InputStream} is not equal to the content of the given one.
* @throws InputStreamsException if an I/O error occurs.
*/
public S hasSameContentAs(InputStream expected) {
inputStreams.assertSameContentAs(info, actual, expected);
return myself;
}
}