Skip to content

Commit 4207e83

Browse files
scordioJessica Hamiltonnith2001
authored
Avoid InputStream manipulation when mark / reset are supported (#3713)
Co-authored-by: Jessica Hamilton <[email protected]> Co-authored-by: nith2001 <[email protected]>
1 parent d692186 commit 4207e83

48 files changed

Lines changed: 1508 additions & 1679 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

assertj-core/src/main/java/org/assertj/core/api/AbstractInputStreamAssert.java

Lines changed: 189 additions & 55 deletions
Large diffs are not rendered by default.

assertj-core/src/main/java/org/assertj/core/api/AbstractThrowableAssert.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import java.util.Arrays;
2020
import java.util.IllegalFormatException;
2121
import java.util.regex.Pattern;
22-
2322
import org.assertj.core.error.BasicErrorMessageFactory;
2423
import org.assertj.core.internal.Failures;
2524
import org.assertj.core.internal.Throwables;
@@ -125,7 +124,7 @@ public SELF hasCause(Throwable cause) {
125124
}
126125

127126
/**
128-
* Verifies that the actual {@code Throwable} has a cause that refers to the given one, i.e. using == comparison
127+
* Verifies that the actual {@code Throwable} has a cause that refers to the given one, i.e., using == comparison
129128
* <p>
130129
* Example:
131130
* <pre><code class='java'> Throwable invalidArgException = new IllegalArgumentException("invalid arg");

assertj-core/src/main/java/org/assertj/core/error/BasicErrorMessageFactory.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323

2424
import java.util.Arrays;
2525
import java.util.Objects;
26-
2726
import org.assertj.core.description.Description;
2827
import org.assertj.core.presentation.Representation;
2928
import org.assertj.core.util.VisibleForTesting;
@@ -110,13 +109,13 @@ public String create(Description d, Representation representation) {
110109
/** {@inheritDoc} */
111110
@Override
112111
public String create(Description d) {
113-
return formatter.format(d, CONFIGURATION_PROVIDER.representation(), format, arguments);
112+
return create(d, CONFIGURATION_PROVIDER.representation());
114113
}
115114

116115
/** {@inheritDoc} */
117116
@Override
118117
public String create() {
119-
return formatter.format(emptyDescription(), CONFIGURATION_PROVIDER.representation(), format, arguments);
118+
return create(emptyDescription());
120119
}
121120

122121
/**

assertj-core/src/main/java/org/assertj/core/internal/BinaryDiff.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,7 @@ public BinaryDiffResult diff(Path actual, byte[] expected) throws IOException {
4444

4545
@VisibleForTesting
4646
public BinaryDiffResult diff(InputStream actualStream, byte[] expected) throws IOException {
47-
try (InputStream expectedStream = new ByteArrayInputStream(expected)) {
48-
return diff(actualStream, expectedStream);
49-
}
47+
return diff(actualStream, new ByteArrayInputStream(expected));
5048
}
5149

5250
@VisibleForTesting

assertj-core/src/main/java/org/assertj/core/internal/Digests.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
package org.assertj.core.internal;
1414

1515
import static java.util.Objects.requireNonNull;
16+
import static org.assertj.core.error.ShouldNotBeNull.shouldNotBeNull;
1617
import static org.assertj.core.util.Hexadecimals.byteToHexString;
1718

1819
import java.io.IOException;
@@ -31,7 +32,7 @@ public final class Digests {
3132
private Digests() {}
3233

3334
public static String toHex(byte[] digest) {
34-
requireNonNull(digest, "The digest should not be null");
35+
requireNonNull(digest, shouldNotBeNull("digest")::create);
3536
StringBuilder hex = new StringBuilder(digest.length * 2);
3637
for (byte b : digest) {
3738
hex.append(byteToHexString(b));
@@ -40,7 +41,7 @@ public static String toHex(byte[] digest) {
4041
}
4142

4243
public static byte[] fromHex(String digest) {
43-
requireNonNull(digest, "The digest should not be null");
44+
requireNonNull(digest, shouldNotBeNull("digest")::create);
4445
byte[] bytes = new byte[digest.length() / 2];
4546
for (int i = 0; i < bytes.length; i++) {
4647
bytes[i] = Integer.valueOf(digest.substring(i * 2, (i + 1) * 2), 16).byteValue();

assertj-core/src/main/java/org/assertj/core/internal/InputStreams.java

Lines changed: 0 additions & 164 deletions
This file was deleted.

assertj-core/src/main/java/org/assertj/core/internal/InputStreamsException.java

Lines changed: 0 additions & 40 deletions
This file was deleted.

assertj-core/src/main/java/org/assertj/core/internal/Strings.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282
import java.io.IOException;
8383
import java.io.LineNumberReader;
8484
import java.io.StringReader;
85+
import java.io.UncheckedIOException;
8586
import java.text.Normalizer;
8687
import java.util.Base64;
8788
import java.util.Collections;
@@ -212,7 +213,7 @@ public void assertHasLineCount(AssertionInfo info, CharSequence actual, int expe
212213
try {
213214
while (reader.readLine() != null);
214215
} catch (IOException e) {
215-
throw new InputStreamsException(format("Unable to count lines in `%s`", actual), e);
216+
throw new UncheckedIOException(format("Unable to count lines in `%s`", actual), e);
216217
}
217218
checkLineCounts(actual, reader.getLineNumber(), expectedLineCount, info);
218219
}

assertj-core/src/test/java/org/assertj/core/api/InputStreamAssertBaseTest.java

Lines changed: 0 additions & 46 deletions
This file was deleted.

assertj-core/src/test/java/org/assertj/core/api/file/FileAssert_hasSameTextualContentAs_Test.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import static org.mockito.Mockito.verify;
1919

2020
import java.io.File;
21-
2221
import org.assertj.core.api.FileAssert;
2322
import org.assertj.core.api.FileAssertBaseTest;
2423
import org.junit.jupiter.api.BeforeAll;
@@ -66,4 +65,5 @@ void should_allow_charset_to_be_specified_for_reading_expected_file_content() th
6665
// WHEN/THEN
6766
then(actual).hasSameTextualContentAs(expected, TURKISH_CHARSET);
6867
}
68+
6969
}

0 commit comments

Comments
 (0)