Copilot commented on code in PR #359:
URL:
https://github.com/apache/maven-shared-utils/pull/359#discussion_r2751168475
##########
src/test/java/org/apache/maven/shared/utils/io/IOUtilTest.java:
##########
@@ -1531,137 +1525,137 @@ public void copyNullStringValidWriter() throws
Exception {
public void copyEmptyStringValidWriter() throws Exception {
StringWriter writer = new DontCloseStringWriter();
IOUtil.copy(emptyString(), writer);
- assertThat(writer.toString(), is(emptyString()));
+ assertEquals(emptyString(), writer.toString());
}
@Test
- public void copyStringNullWriter() throws Exception {
+ public void copyStringNullWriter() {
assertThrows(NullPointerException.class, () -> {
- String probe = "A string \u2345\u00ef";
+ String probe = "A string ⍅ï";
IOUtil.copy(probe, nullWriter());
});
}
@Test
public void copyStringValidWriter() throws Exception {
- String probe = "A string \u2345\u00ef";
+ String probe = "A string ⍅ï";
StringWriter writer = new DontCloseStringWriter();
IOUtil.copy(probe, writer);
- assertThat(writer.toString(), is(probe));
+ assertEquals(probe, writer.toString());
}
@Test
- public void copyNullStringNullOutputStream() throws Exception {
+ public void copyNullStringNullOutputStream() {
assertThrows(NullPointerException.class, () ->
IOUtil.copy(nullString(), nullOutputStream()));
}
@Test
- public void copyEmptyStringNullOutputStream() throws Exception {
+ public void copyEmptyStringNullOutputStream() {
assertThrows(NullPointerException.class, () ->
IOUtil.copy(emptyString(), nullOutputStream()));
}
@Test
- public void copyNullStringValidOutputStream() throws Exception {
+ public void copyNullStringValidOutputStream() {
assertThrows(NullPointerException.class, () ->
IOUtil.copy(nullString(), new DontCloseByteArrayOutputStream()));
}
@Test
public void copyEmptyStringValidOutputStream() throws Exception {
ByteArrayOutputStream os = new DontCloseByteArrayOutputStream();
IOUtil.copy(emptyString(), os);
- assertThat(os.toByteArray(), is(emptyString().getBytes()));
+ assertArrayEquals(os.toByteArray(), emptyString().getBytes());
Review Comment:
The assertArrayEquals parameters are in the wrong order. In JUnit 5, the
convention is assertArrayEquals(expected, actual). This should be:
assertArrayEquals(emptyString().getBytes(), os.toByteArray())
```suggestion
assertArrayEquals(emptyString().getBytes(), os.toByteArray());
```
##########
src/test/java/org/apache/maven/shared/utils/io/IOUtilTest.java:
##########
@@ -1867,26 +1860,26 @@ public void toByteArrayNullInputStreamPosBufSz() throws
Exception {
*/
@Test
- public void toByteArrayFromReaderNegBufSz() throws Exception {
+ public void toByteArrayFromReaderNegBufSz() {
assertThrows(NegativeArraySizeException.class, () -> {
- String probe = "A string \u2345\u00ef";
- assertThat(IOUtil.toByteArray(new DontCloseStringReader(probe),
-1), is(probe.getBytes()));
+ String probe = "A string ⍅ï";
+ assertEquals(IOUtil.toByteArray(new DontCloseStringReader(probe),
-1), probe.getBytes());
Review Comment:
The assertEquals parameters are in the wrong order, and for comparing byte
arrays, assertArrayEquals should be used. This should be:
assertArrayEquals(probe.getBytes(), IOUtil.toByteArray(new
DontCloseStringReader(probe), -1))
```suggestion
assertArrayEquals(probe.getBytes(), IOUtil.toByteArray(new
DontCloseStringReader(probe), -1));
```
##########
src/test/java/org/apache/maven/shared/utils/io/IOUtilTest.java:
##########
@@ -160,350 +164,338 @@ public void close() throws IOException {
super.close();
}
});
- assertThat(closed.get(), is(true));
+ assertTrue(closed.get());
}
@Test
public void toByteArrayFromString() throws Exception {
- String probe = "A string \u2345\u00ef";
- assertThat(IOUtil.toByteArray(probe), is(probe.getBytes()));
+ String probe = "A string ⍅ï";
+ assertArrayEquals(probe.getBytes(), IOUtil.toByteArray(probe));
}
@Test
public void toByteArrayFromReader() throws Exception {
- String probe = "A string \u2345\u00ef";
- assertThat(IOUtil.toByteArray(new StringReader(probe)),
is(probe.getBytes()));
+ String probe = "A string ⍅ï";
+ assertArrayEquals(probe.getBytes(), IOUtil.toByteArray(new
StringReader(probe)));
}
@Test
public void toByteArrayFromInputStream() throws Exception {
- String probe = "A string \u2345\u00ef";
- assertThat(
- IOUtil.toByteArray(new
DontCloseByteArrayInputStream(IOUtil.toByteArray(probe))),
is(probe.getBytes()));
+ String probe = "A string ⍅ï";
+ assertArrayEquals(
+ probe.getBytes(), IOUtil.toByteArray(new
DontCloseByteArrayInputStream(IOUtil.toByteArray(probe))));
}
@Test
- public void toByteArrayNullString() throws Exception {
+ public void toByteArrayNullString() {
+ //noinspection DataFlowIssue
assertThrows(NullPointerException.class, () ->
IOUtil.toByteArray((String) null));
}
@Test
- public void toByteArrayNullReader() throws Exception {
+ public void toByteArrayNullReader() {
+ //noinspection DataFlowIssue
assertThrows(NullPointerException.class, () ->
IOUtil.toByteArray((Reader) null));
}
@Test
- public void toByteArrayNullInputStream() throws Exception {
- assertThrows(NullPointerException.class, () ->
IOUtil.toByteArray(nullInputStream()));
+ public void toByteArrayNullInputStream() {
+ assertThrows(NullPointerException.class, () -> {
+ IOUtil.toByteArray(nullInputStream());
+ });
}
@Test
- public void contentEqualNullNull() throws Exception {
+ public void contentEqualNullNull() {
+ //noinspection DataFlowIssue
assertThrows(IOException.class, () -> IOUtil.contentEquals(null,
null));
}
@Test
- public void contentEqualNonNullNull() throws Exception {
+ public void contentEqualNonNullNull() {
+ //noinspection DataFlowIssue
assertThrows(
IOException.class,
() -> IOUtil.contentEquals(new
DontCloseByteArrayInputStream(emptyByteArray()), null));
}
@Test
- public void contentEqualNullNonNull() throws Exception {
+ public void contentEqualNullNonNull() {
+ //noinspection DataFlowIssue
assertThrows(
IOException.class,
() -> IOUtil.contentEquals(new
DontCloseByteArrayInputStream(emptyByteArray()), null));
}
@Test
public void contentEqualEmptyEmpty() throws Exception {
- assertThat(
- IOUtil.contentEquals(
- new DontCloseByteArrayInputStream(emptyByteArray()),
- new DontCloseByteArrayInputStream(emptyByteArray())),
- is(true));
+ assertTrue(IOUtil.contentEquals(
+ new DontCloseByteArrayInputStream(emptyByteArray()),
+ new DontCloseByteArrayInputStream(emptyByteArray())));
}
@Test
public void contentEqualNonEmptyEmpty() throws Exception {
- assertThat(
- IOUtil.contentEquals(
- new DontCloseByteArrayInputStream(new byte[1]),
- new DontCloseByteArrayInputStream(emptyByteArray())),
- is(false));
+ assertFalse(IOUtil.contentEquals(
+ new DontCloseByteArrayInputStream(new byte[1]), new
DontCloseByteArrayInputStream(emptyByteArray())));
}
@Test
public void contentEqualEmptyNonEmpty() throws Exception {
- assertThat(
- IOUtil.contentEquals(
- new DontCloseByteArrayInputStream(emptyByteArray()),
- new DontCloseByteArrayInputStream(new byte[1])),
- is(false));
+ assertFalse(IOUtil.contentEquals(
+ new DontCloseByteArrayInputStream(emptyByteArray()), new
DontCloseByteArrayInputStream(new byte[1])));
}
@Test
public void contentEqualNonEmptyNonEmpty() throws Exception {
- assertThat(
- IOUtil.contentEquals(
- new DontCloseByteArrayInputStream(new byte[1]), new
DontCloseByteArrayInputStream(new byte[1])),
- is(true));
+ assertTrue(IOUtil.contentEquals(
+ new DontCloseByteArrayInputStream(new byte[1]), new
DontCloseByteArrayInputStream(new byte[1])));
}
@Test
public void contentEqualMostlySame() throws Exception {
- assertThat(
- IOUtil.contentEquals(
- new DontCloseByteArrayInputStream(new byte[] {1, 2, 3,
4, 5, 6}),
- new DontCloseByteArrayInputStream(new byte[] {1, 2, 3,
4, 5, 7})),
- is(false));
+ assertFalse(IOUtil.contentEquals(
+ new DontCloseByteArrayInputStream(new byte[] {1, 2, 3, 4, 5,
6}),
+ new DontCloseByteArrayInputStream(new byte[] {1, 2, 3, 4, 5,
7})));
}
@Test
public void contentEqualLargeSame() throws Exception {
- assertThat(
- IOUtil.contentEquals(
- new DontCloseByteArrayInputStream(new byte[8192]),
- new DontCloseByteArrayInputStream(new byte[8192])),
- is(true));
+ assertTrue(IOUtil.contentEquals(
+ new DontCloseByteArrayInputStream(new byte[8192]), new
DontCloseByteArrayInputStream(new byte[8192])));
}
@Test
public void contentEqualLargeDifferent() throws Exception {
byte[] buf = new byte[8192];
buf[8191] = 1;
- assertThat(
- IOUtil.contentEquals(
- new DontCloseByteArrayInputStream(new byte[8192]), new
DontCloseByteArrayInputStream(buf)),
- is(false));
+ assertFalse(IOUtil.contentEquals(
+ new DontCloseByteArrayInputStream(new byte[8192]), new
DontCloseByteArrayInputStream(buf)));
}
@Test
- public void toStringNullByteArray() throws Exception {
+ public void toStringNullByteArray() {
assertThrows(NullPointerException.class, () ->
IOUtil.toString(nullByteArray()));
}
@Test
public void toStringEmptyByteArray() throws Exception {
- assertThat(IOUtil.toString(emptyByteArray()), is(emptyString()));
+ assertEquals(emptyString(), IOUtil.toString(emptyByteArray()));
}
@Test
public void toStringByteArray() throws Exception {
- String probe = "A string \u2345\u00ef";
- assertThat(IOUtil.toString(probe.getBytes()).getBytes(),
is(probe.getBytes()));
+ String probe = "A string ⍅ï";
+ assertArrayEquals(probe.getBytes(),
IOUtil.toString(probe.getBytes()).getBytes());
}
@Test
- public void toStringNullByteArrayNegBufSz() throws Exception {
+ public void toStringNullByteArrayNegBufSz() {
assertThrows(NullPointerException.class, () ->
IOUtil.toString(nullByteArray(), -1));
}
@Test
- public void toStringEmptyByteArrayNegBufSz() throws Exception {
+ public void toStringEmptyByteArrayNegBufSz() {
assertThrows(
NegativeArraySizeException.class,
- () -> assertThat(IOUtil.toString(emptyByteArray(), -1),
is(emptyString())));
+ () -> assertEquals(IOUtil.toString(emptyByteArray(), -1),
emptyString()));
}
@Test
- public void toStringByteArrayNegBufSz() throws Exception {
+ public void toStringByteArrayNegBufSz() {
assertThrows(NegativeArraySizeException.class, () -> {
- String probe = "A string \u2345\u00ef";
- assertThat(IOUtil.toString(probe.getBytes(), -1), is(probe));
+ String probe = "A string ⍅ï";
+ assertEquals(probe, IOUtil.toString(probe.getBytes(), -1));
});
}
@Test
@Timeout(value = INFINITE_LOOP_TIMEOUT, unit = TimeUnit.MILLISECONDS)
- public void toStringNullByteArrayZeroBufSz() throws Exception {
+ public void toStringNullByteArrayZeroBufSz() {
assertThrows(NullPointerException.class, () ->
IOUtil.toString(nullByteArray(), 0));
}
@Test
- public void toStringNullByteArrayPosBufSz() throws Exception {
+ public void toStringNullByteArrayPosBufSz() {
assertThrows(NullPointerException.class, () ->
IOUtil.toString(nullByteArray(), 1));
}
@Test
public void toStringEmptyByteArrayPosBufSz() throws Exception {
- assertThat(IOUtil.toString(emptyByteArray(), 1), is(emptyString()));
+ assertEquals(emptyString(), IOUtil.toString(emptyByteArray(), 1));
}
@Test
public void toStringByteArrayPosBufSz() throws Exception {
- String probe = "A string \u2345\u00ef";
- assertThat(IOUtil.toString(probe.getBytes(), 1).getBytes(),
is(probe.getBytes()));
+ String probe = "A string ⍅ï";
+ assertArrayEquals(probe.getBytes(), IOUtil.toString(probe.getBytes(),
1).getBytes());
}
@Test
- public void toStringNullByteArrayNullEncoding() throws Exception {
+ public void toStringNullByteArrayNullEncoding() {
assertThrows(NullPointerException.class, () ->
IOUtil.toString(nullByteArray(), null));
}
@Test
- public void toStringEmptyByteArrayNullEncoding() throws Exception {
- assertThrows(
- NullPointerException.class,
- () -> assertThat(IOUtil.toString(emptyByteArray(), null),
is(emptyString())));
+ public void toStringEmptyByteArrayNullEncoding() {
+ assertThrows(NullPointerException.class, () ->
IOUtil.toString(emptyByteArray(), null));
}
@Test
- public void toStringByteArrayNullEncoding() throws Exception {
+ public void toStringByteArrayNullEncoding() {
assertThrows(NullPointerException.class, () -> {
- String probe = "A string \u2345\u00ef";
- assertThat(IOUtil.toString(probe.getBytes(), null).getBytes(),
is(probe.getBytes()));
+ String probe = "A string ⍅ï";
+ IOUtil.toString(probe.getBytes(), null).getBytes();
});
}
@Test
- public void toStringNullByteArrayJunkEncoding() throws Exception {
+ public void toStringNullByteArrayJunkEncoding() {
assertThrows(NullPointerException.class, () ->
IOUtil.toString(nullByteArray(), "junk"));
}
@Test
- public void toStringEmptyByteArrayJunkEncoding() throws Exception {
+ public void toStringEmptyByteArrayJunkEncoding() {
assertThrows(
UnsupportedEncodingException.class,
- () -> assertThat(IOUtil.toString(emptyByteArray(), "junk"),
is(emptyString())));
+ () -> assertEquals(IOUtil.toString(emptyByteArray(), "junk"),
emptyString()));
}
@Test
- public void toStringByteArrayJunkEncoding() throws Exception {
+ public void toStringByteArrayJunkEncoding() {
assertThrows(UnsupportedEncodingException.class, () -> {
- String probe = "A string \u2345\u00ef";
- assertThat(IOUtil.toString(probe.getBytes(), "junk").getBytes(),
is(probe.getBytes()));
+ String probe = "A string ⍅ï";
+ assertArrayEquals(IOUtil.toString(probe.getBytes(),
"junk").getBytes(), probe.getBytes());
Review Comment:
The assertArrayEquals parameters are in the wrong order. In JUnit 5, the
convention is assertArrayEquals(expected, actual). This should be:
assertArrayEquals(probe.getBytes(), IOUtil.toString(probe.getBytes(),
"junk").getBytes())
```suggestion
assertArrayEquals(probe.getBytes(),
IOUtil.toString(probe.getBytes(), "junk").getBytes());
```
##########
src/test/java/org/apache/maven/shared/utils/io/IOUtilTest.java:
##########
@@ -667,55 +659,55 @@ public void copyInputStreamValidOutputStream() throws
Exception {
ByteArrayOutputStream outputStream = new
DontCloseByteArrayOutputStream();
byte[] input = {1, 2, 3, 4, 5, 6};
IOUtil.copy(new DontCloseByteArrayInputStream(input), outputStream);
- assertThat(outputStream.toByteArray(), is(input));
+ assertArrayEquals(input, outputStream.toByteArray());
}
@Test
- public void copyNullInputStreamNullOutputStreamNegBufSz() throws Exception
{
+ public void copyNullInputStreamNullOutputStreamNegBufSz() {
assertThrows(NegativeArraySizeException.class, () ->
IOUtil.copy(nullInputStream(), nullOutputStream(), -1));
}
@Test
- public void copyNullInputStreamValidOutputStreamNegBufSz() throws
Exception {
+ public void copyNullInputStreamValidOutputStreamNegBufSz() {
assertThrows(
NegativeArraySizeException.class,
() -> IOUtil.copy(nullInputStream(), new
DontCloseByteArrayOutputStream(), -1));
}
@Test
- public void copyEmptyInputStreamNullOutputStreamNegBufSz() throws
Exception {
+ public void copyEmptyInputStreamNullOutputStreamNegBufSz() {
assertThrows(
NegativeArraySizeException.class,
() -> IOUtil.copy(new
DontCloseByteArrayInputStream(emptyByteArray()), nullOutputStream(), -1));
}
@Test
- public void copyEmptyInputStreamValidOutputStreamNegBufSz() throws
Exception {
+ public void copyEmptyInputStreamValidOutputStreamNegBufSz() {
assertThrows(
NegativeArraySizeException.class,
() -> IOUtil.copy(
new DontCloseByteArrayInputStream(emptyByteArray()),
new DontCloseByteArrayOutputStream(), -1));
}
@Test
- public void copyInputStreamValidOutputStreamNegBufSz() throws Exception {
+ public void copyInputStreamValidOutputStreamNegBufSz() {
assertThrows(NegativeArraySizeException.class, () -> {
ByteArrayOutputStream outputStream = new
DontCloseByteArrayOutputStream();
byte[] input = {1, 2, 3, 4, 5, 6};
IOUtil.copy(new DontCloseByteArrayInputStream(input),
outputStream, -1);
- assertThat(outputStream.toByteArray(), is(input));
+ assertEquals(input, outputStream.toByteArray());
Review Comment:
The assertEquals parameters are in the wrong order. In JUnit 5, the
convention is assertEquals(expected, actual). This should be:
assertEquals(outputStream.toByteArray(), input) or better yet, use
assertArrayEquals(input, outputStream.toByteArray())
```suggestion
assertArrayEquals(input, outputStream.toByteArray());
```
##########
src/test/java/org/apache/maven/shared/utils/io/IOUtilTest.java:
##########
@@ -1237,272 +1231,272 @@ public void
copyNullInputStreamValidWriterValidEncoding() throws Exception {
public void copyEmptyInputStreamValidWriterValidEncoding() throws
Exception {
StringWriter writer = new DontCloseStringWriter();
IOUtil.copy(emptyInputStream(), writer, "utf-16");
- assertThat(writer.toString(), is(emptyString()));
+ assertEquals(emptyString(), writer.toString());
}
@Test
- public void copyInputStreamNullWriterValidEncoding() throws Exception {
+ public void copyInputStreamNullWriterValidEncoding() {
assertThrows(NullPointerException.class, () -> {
- String probe = "A string \u2345\u00ef";
+ String probe = "A string ⍅ï";
IOUtil.copy(new ByteArrayInputStream(probe.getBytes("utf-16")),
nullWriter(), "utf-16");
});
}
@Test
public void copyInputStreamValidWriterValidEncoding() throws Exception {
- String probe = "A string \u2345\u00ef";
+ String probe = "A string ⍅ï";
StringWriter writer = new DontCloseStringWriter();
- IOUtil.copy(new ByteArrayInputStream(probe.getBytes("utf-16")),
writer, "utf-16");
- assertThat(writer.toString().getBytes("utf-8"),
is(probe.getBytes("utf-8")));
+ IOUtil.copy(new ByteArrayInputStream(probe.getBytes(UTF_16)), writer,
"utf-16");
+ assertArrayEquals(probe.getBytes(UTF_8),
writer.toString().getBytes(UTF_8));
}
/*
* copy(InputStream,Writer,String,int)
*/
@Test
- public void copyNullInputStreamNullWriterNullEncodingNegBufSz() throws
Exception {
+ public void copyNullInputStreamNullWriterNullEncodingNegBufSz() {
assertThrows(NullPointerException.class, () ->
IOUtil.copy(nullInputStream(), nullWriter(), null, -1));
}
@Test
- public void copyNullInputStreamValidWriterNullEncodingNegBufSz() throws
Exception {
+ public void copyNullInputStreamValidWriterNullEncodingNegBufSz() {
assertThrows(
NullPointerException.class,
() -> IOUtil.copy(nullInputStream(), new
DontCloseStringWriter(), null, -1));
}
@Test
- public void copyEmptyInputStreamNullWriterNullEncodingNegBufSz() throws
Exception {
+ public void copyEmptyInputStreamNullWriterNullEncodingNegBufSz() {
assertThrows(NullPointerException.class, () ->
IOUtil.copy(emptyInputStream(), nullWriter(), null, -1));
}
@Test
- public void copyEmptyInputStreamValidWriterNullEncodingNegBufSz() throws
Exception {
+ public void copyEmptyInputStreamValidWriterNullEncodingNegBufSz() {
assertThrows(NullPointerException.class, () -> {
StringWriter writer = new DontCloseStringWriter();
IOUtil.copy(emptyInputStream(), writer, null, -1);
- assertThat(writer.toString(), is(emptyString()));
+ assertEquals(emptyString(), writer.toString());
});
}
@Test
- public void copyInputStreamNullWriterNullEncodingNegBufSz() throws
Exception {
+ public void copyInputStreamNullWriterNullEncodingNegBufSz() {
assertThrows(NullPointerException.class, () -> {
- String probe = "A string \u2345\u00ef";
+ String probe = "A string ⍅ï";
IOUtil.copy(new ByteArrayInputStream(probe.getBytes()),
nullWriter(), null, -1);
});
}
@Test
- public void copyInputStreamValidWriterNullEncodingNegBufSz() throws
Exception {
+ public void copyInputStreamValidWriterNullEncodingNegBufSz() {
assertThrows(NullPointerException.class, () -> {
- String probe = "A string \u2345\u00ef";
+ String probe = "A string ⍅ï";
StringWriter writer = new DontCloseStringWriter();
IOUtil.copy(new ByteArrayInputStream(probe.getBytes()), writer,
null, -1);
- assertThat(writer.toString().getBytes(), is(probe.getBytes()));
+ assertArrayEquals(probe.getBytes(), writer.toString().getBytes());
});
}
@Test
- public void copyNullInputStreamNullWriterJunkEncodingNegBufSz() throws
Exception {
+ public void copyNullInputStreamNullWriterJunkEncodingNegBufSz() {
assertThrows(NullPointerException.class, () ->
IOUtil.copy(nullInputStream(), nullWriter(), "junk", -1));
}
@Test
- public void copyNullInputStreamValidWriterJunkEncodingNegBufSz() throws
Exception {
+ public void copyNullInputStreamValidWriterJunkEncodingNegBufSz() {
assertThrows(
NullPointerException.class,
() -> IOUtil.copy(nullInputStream(), new
DontCloseStringWriter(), "junk", -1));
}
@Test
- public void copyEmptyInputStreamNullWriterJunkEncodingNegBufSz() throws
Exception {
+ public void copyEmptyInputStreamNullWriterJunkEncodingNegBufSz() {
assertThrows(
UnsupportedEncodingException.class, () ->
IOUtil.copy(emptyInputStream(), nullWriter(), "junk", -1));
}
@Test
- public void copyEmptyInputStreamJunkEncodingNegBufSz() throws Exception {
+ public void copyEmptyInputStreamJunkEncodingNegBufSz() {
assertThrows(UnsupportedEncodingException.class, () -> {
StringWriter writer = new DontCloseStringWriter();
IOUtil.copy(emptyInputStream(), writer, "junk", -1);
- assertThat(writer.toString(), is(emptyString()));
+ assertEquals(emptyString(), writer.toString());
});
}
@Test
- public void copyInputStreamNullWriterJunkEncodingNegBufSz() throws
Exception {
+ public void copyInputStreamNullWriterJunkEncodingNegBufSz() {
assertThrows(UnsupportedEncodingException.class, () -> {
- String probe = "A string \u2345\u00ef";
+ String probe = "A string ⍅ï";
IOUtil.copy(new ByteArrayInputStream(probe.getBytes()),
nullWriter(), "junk", -1);
});
}
@Test
- public void copyInputStreamValidWriterJunkEncodingNegBufSz() throws
Exception {
+ public void copyInputStreamValidWriterJunkEncodingNegBufSz() {
assertThrows(UnsupportedEncodingException.class, () -> {
- String probe = "A string \u2345\u00ef";
+ String probe = "A string ⍅ï";
StringWriter writer = new DontCloseStringWriter();
IOUtil.copy(new ByteArrayInputStream(probe.getBytes()), writer,
"junk", -1);
- assertThat(writer.toString().getBytes(), is(probe.getBytes()));
+ assertArrayEquals(probe.getBytes(), writer.toString().getBytes());
});
}
@Test
- public void copyNullInputStreamNullWriterValidEncodingNegBufSz() throws
Exception {
+ public void copyNullInputStreamNullWriterValidEncodingNegBufSz() {
assertThrows(NullPointerException.class, () ->
IOUtil.copy(nullInputStream(), nullWriter(), "utf-16", -1));
}
@Test
- public void copyNullInputStreamValidWriterValidEncodingNegBufSz() throws
Exception {
+ public void copyNullInputStreamValidWriterValidEncodingNegBufSz() {
assertThrows(
NullPointerException.class,
() -> IOUtil.copy(nullInputStream(), new
DontCloseStringWriter(), "utf-16", -1));
}
@Test
- public void copyEmptyInputStreamNullWriterValidEncodingNegBufSz() throws
Exception {
+ public void copyEmptyInputStreamNullWriterValidEncodingNegBufSz() {
assertThrows(
NegativeArraySizeException.class, () ->
IOUtil.copy(emptyInputStream(), nullWriter(), "utf-16", -1));
}
@Test
- public void copyEmptyInputStreamValidWriterValidEncodingNegBufSz() throws
Exception {
+ public void copyEmptyInputStreamValidWriterValidEncodingNegBufSz() {
assertThrows(NegativeArraySizeException.class, () -> {
StringWriter writer = new DontCloseStringWriter();
IOUtil.copy(emptyInputStream(), writer, "utf-16", -1);
- assertThat(writer.toString(), is(emptyString()));
+ assertEquals(emptyString(), writer.toString());
});
}
@Test
- public void copyInputStreamNullWriterValidEncodingNegBufSz() throws
Exception {
+ public void copyInputStreamNullWriterValidEncodingNegBufSz() {
assertThrows(NegativeArraySizeException.class, () -> {
- String probe = "A string \u2345\u00ef";
+ String probe = "A string ⍅ï";
IOUtil.copy(new ByteArrayInputStream(probe.getBytes("utf-16")),
nullWriter(), -1);
});
}
@Test
- public void copyInputStreamValidEncodingNegBufSz() throws Exception {
+ public void copyInputStreamValidEncodingNegBufSz() {
assertThrows(NegativeArraySizeException.class, () -> {
- String probe = "A string \u2345\u00ef";
+ String probe = "A string ⍅ï";
StringWriter writer = new DontCloseStringWriter();
- IOUtil.copy(new ByteArrayInputStream(probe.getBytes("utf-16")),
writer, "utf-16", -1);
- assertThat(writer.toString().getBytes("utf-8"),
is(probe.getBytes("utf-8")));
+ IOUtil.copy(new ByteArrayInputStream(probe.getBytes(UTF_16)),
writer, "utf-16", -1);
+ assertEquals(probe.getBytes(UTF_8),
writer.toString().getBytes(UTF_8));
Review Comment:
For comparing byte arrays, assertArrayEquals should be used instead of
assertEquals. This should be: assertArrayEquals(probe.getBytes(UTF_8),
writer.toString().getBytes(UTF_8))
```suggestion
assertArrayEquals(probe.getBytes(UTF_8),
writer.toString().getBytes(UTF_8));
```
##########
src/test/java/org/apache/maven/shared/utils/io/FileUtilsTest.java:
##########
@@ -259,28 +256,29 @@ public void contentEquals() throws Exception {
assertTrue(FileUtils.contentEquals(objFile2, objFile2));
// Equal files
- file.createNewFile();
+ file1.createNewFile();
file2.createNewFile();
Review Comment:
Method contentEquals ignores exceptional return value of File.createNewFile.
```suggestion
assertTrue(file1.createNewFile(), "Failed to create file1");
assertTrue(file2.createNewFile(), "Failed to create file2");
```
##########
src/test/java/org/apache/maven/shared/utils/io/IOUtilTest.java:
##########
@@ -1531,137 +1525,137 @@ public void copyNullStringValidWriter() throws
Exception {
public void copyEmptyStringValidWriter() throws Exception {
StringWriter writer = new DontCloseStringWriter();
IOUtil.copy(emptyString(), writer);
- assertThat(writer.toString(), is(emptyString()));
+ assertEquals(emptyString(), writer.toString());
}
@Test
- public void copyStringNullWriter() throws Exception {
+ public void copyStringNullWriter() {
assertThrows(NullPointerException.class, () -> {
- String probe = "A string \u2345\u00ef";
+ String probe = "A string ⍅ï";
IOUtil.copy(probe, nullWriter());
});
}
@Test
public void copyStringValidWriter() throws Exception {
- String probe = "A string \u2345\u00ef";
+ String probe = "A string ⍅ï";
StringWriter writer = new DontCloseStringWriter();
IOUtil.copy(probe, writer);
- assertThat(writer.toString(), is(probe));
+ assertEquals(probe, writer.toString());
}
@Test
- public void copyNullStringNullOutputStream() throws Exception {
+ public void copyNullStringNullOutputStream() {
assertThrows(NullPointerException.class, () ->
IOUtil.copy(nullString(), nullOutputStream()));
}
@Test
- public void copyEmptyStringNullOutputStream() throws Exception {
+ public void copyEmptyStringNullOutputStream() {
assertThrows(NullPointerException.class, () ->
IOUtil.copy(emptyString(), nullOutputStream()));
}
@Test
- public void copyNullStringValidOutputStream() throws Exception {
+ public void copyNullStringValidOutputStream() {
assertThrows(NullPointerException.class, () ->
IOUtil.copy(nullString(), new DontCloseByteArrayOutputStream()));
}
@Test
public void copyEmptyStringValidOutputStream() throws Exception {
ByteArrayOutputStream os = new DontCloseByteArrayOutputStream();
IOUtil.copy(emptyString(), os);
- assertThat(os.toByteArray(), is(emptyString().getBytes()));
+ assertArrayEquals(os.toByteArray(), emptyString().getBytes());
}
@Test
- public void copyStringNullOutputStream() throws Exception {
+ public void copyStringNullOutputStream() {
assertThrows(NullPointerException.class, () -> {
- String probe = "A string \u2345\u00ef";
+ String probe = "A string ⍅ï";
IOUtil.copy(probe, nullOutputStream());
});
}
@Test
public void copyStringValidOutputStream() throws Exception {
- String probe = "A string \u2345\u00ef";
+ String probe = "A string ⍅ï";
ByteArrayOutputStream os = new DontCloseByteArrayOutputStream();
IOUtil.copy(probe, os);
- assertThat(os.toByteArray(), is(probe.getBytes()));
+ assertArrayEquals(probe.getBytes(), os.toByteArray());
}
@Test
- public void copyNullStringNullOutputStreamNegBufSz() throws Exception {
+ public void copyNullStringNullOutputStreamNegBufSz() {
assertThrows(NullPointerException.class, () ->
IOUtil.copy(nullString(), nullOutputStream(), -1));
}
@Test
- public void copyEmptyStringNullOutputStreamNegBufSz() throws Exception {
+ public void copyEmptyStringNullOutputStreamNegBufSz() {
assertThrows(NullPointerException.class, () ->
IOUtil.copy(emptyString(), nullOutputStream(), -1));
}
@Test
- public void copyNullStringValidOutputStreamNegBufSz() throws Exception {
+ public void copyNullStringValidOutputStreamNegBufSz() {
assertThrows(
NullPointerException.class, () -> IOUtil.copy(nullString(),
new DontCloseByteArrayOutputStream(), -1));
}
@Test
- public void copyEmptyStringValidOutputStreamNegBufSz() throws Exception {
+ public void copyEmptyStringValidOutputStreamNegBufSz() {
assertThrows(NegativeArraySizeException.class, () -> {
ByteArrayOutputStream os = new DontCloseByteArrayOutputStream();
IOUtil.copy(emptyString(), os, -1);
- assertThat(os.toByteArray(), is(emptyString().getBytes()));
+ assertArrayEquals(os.toByteArray(), emptyString().getBytes());
});
}
@Test
- public void copyStringNullOutputStreamNegBufSz() throws Exception {
+ public void copyStringNullOutputStreamNegBufSz() {
assertThrows(NullPointerException.class, () -> {
- String probe = "A string \u2345\u00ef";
+ String probe = "A string ⍅ï";
IOUtil.copy(probe, nullOutputStream(), -1);
});
}
@Test
- public void copyStringValidOutputStreamNegBufSz() throws Exception {
+ public void copyStringValidOutputStreamNegBufSz() {
assertThrows(NegativeArraySizeException.class, () -> {
- String probe = "A string \u2345\u00ef";
+ String probe = "A string ⍅ï";
ByteArrayOutputStream os = new DontCloseByteArrayOutputStream();
IOUtil.copy(probe, os, -1);
- assertThat(os.toByteArray(), is(probe.getBytes()));
+ assertEquals(probe.getBytes(), os.toByteArray());
Review Comment:
The assertEquals parameters are in the wrong order. For comparing byte
arrays, assertArrayEquals should be used instead of assertEquals. This should
be: assertArrayEquals(probe.getBytes(), os.toByteArray())
```suggestion
assertArrayEquals(probe.getBytes(), os.toByteArray());
```
##########
src/test/java/org/apache/maven/shared/utils/io/IOUtilTest.java:
##########
@@ -160,350 +164,338 @@ public void close() throws IOException {
super.close();
}
});
- assertThat(closed.get(), is(true));
+ assertTrue(closed.get());
}
@Test
public void toByteArrayFromString() throws Exception {
- String probe = "A string \u2345\u00ef";
- assertThat(IOUtil.toByteArray(probe), is(probe.getBytes()));
+ String probe = "A string ⍅ï";
+ assertArrayEquals(probe.getBytes(), IOUtil.toByteArray(probe));
}
@Test
public void toByteArrayFromReader() throws Exception {
- String probe = "A string \u2345\u00ef";
- assertThat(IOUtil.toByteArray(new StringReader(probe)),
is(probe.getBytes()));
+ String probe = "A string ⍅ï";
+ assertArrayEquals(probe.getBytes(), IOUtil.toByteArray(new
StringReader(probe)));
}
@Test
public void toByteArrayFromInputStream() throws Exception {
- String probe = "A string \u2345\u00ef";
- assertThat(
- IOUtil.toByteArray(new
DontCloseByteArrayInputStream(IOUtil.toByteArray(probe))),
is(probe.getBytes()));
+ String probe = "A string ⍅ï";
+ assertArrayEquals(
+ probe.getBytes(), IOUtil.toByteArray(new
DontCloseByteArrayInputStream(IOUtil.toByteArray(probe))));
}
@Test
- public void toByteArrayNullString() throws Exception {
+ public void toByteArrayNullString() {
+ //noinspection DataFlowIssue
assertThrows(NullPointerException.class, () ->
IOUtil.toByteArray((String) null));
}
@Test
- public void toByteArrayNullReader() throws Exception {
+ public void toByteArrayNullReader() {
+ //noinspection DataFlowIssue
assertThrows(NullPointerException.class, () ->
IOUtil.toByteArray((Reader) null));
}
@Test
- public void toByteArrayNullInputStream() throws Exception {
- assertThrows(NullPointerException.class, () ->
IOUtil.toByteArray(nullInputStream()));
+ public void toByteArrayNullInputStream() {
+ assertThrows(NullPointerException.class, () -> {
+ IOUtil.toByteArray(nullInputStream());
+ });
}
@Test
- public void contentEqualNullNull() throws Exception {
+ public void contentEqualNullNull() {
+ //noinspection DataFlowIssue
assertThrows(IOException.class, () -> IOUtil.contentEquals(null,
null));
}
@Test
- public void contentEqualNonNullNull() throws Exception {
+ public void contentEqualNonNullNull() {
+ //noinspection DataFlowIssue
assertThrows(
IOException.class,
() -> IOUtil.contentEquals(new
DontCloseByteArrayInputStream(emptyByteArray()), null));
}
@Test
- public void contentEqualNullNonNull() throws Exception {
+ public void contentEqualNullNonNull() {
+ //noinspection DataFlowIssue
assertThrows(
IOException.class,
() -> IOUtil.contentEquals(new
DontCloseByteArrayInputStream(emptyByteArray()), null));
}
@Test
public void contentEqualEmptyEmpty() throws Exception {
- assertThat(
- IOUtil.contentEquals(
- new DontCloseByteArrayInputStream(emptyByteArray()),
- new DontCloseByteArrayInputStream(emptyByteArray())),
- is(true));
+ assertTrue(IOUtil.contentEquals(
+ new DontCloseByteArrayInputStream(emptyByteArray()),
+ new DontCloseByteArrayInputStream(emptyByteArray())));
}
@Test
public void contentEqualNonEmptyEmpty() throws Exception {
- assertThat(
- IOUtil.contentEquals(
- new DontCloseByteArrayInputStream(new byte[1]),
- new DontCloseByteArrayInputStream(emptyByteArray())),
- is(false));
+ assertFalse(IOUtil.contentEquals(
+ new DontCloseByteArrayInputStream(new byte[1]), new
DontCloseByteArrayInputStream(emptyByteArray())));
}
@Test
public void contentEqualEmptyNonEmpty() throws Exception {
- assertThat(
- IOUtil.contentEquals(
- new DontCloseByteArrayInputStream(emptyByteArray()),
- new DontCloseByteArrayInputStream(new byte[1])),
- is(false));
+ assertFalse(IOUtil.contentEquals(
+ new DontCloseByteArrayInputStream(emptyByteArray()), new
DontCloseByteArrayInputStream(new byte[1])));
}
@Test
public void contentEqualNonEmptyNonEmpty() throws Exception {
- assertThat(
- IOUtil.contentEquals(
- new DontCloseByteArrayInputStream(new byte[1]), new
DontCloseByteArrayInputStream(new byte[1])),
- is(true));
+ assertTrue(IOUtil.contentEquals(
+ new DontCloseByteArrayInputStream(new byte[1]), new
DontCloseByteArrayInputStream(new byte[1])));
}
@Test
public void contentEqualMostlySame() throws Exception {
- assertThat(
- IOUtil.contentEquals(
- new DontCloseByteArrayInputStream(new byte[] {1, 2, 3,
4, 5, 6}),
- new DontCloseByteArrayInputStream(new byte[] {1, 2, 3,
4, 5, 7})),
- is(false));
+ assertFalse(IOUtil.contentEquals(
+ new DontCloseByteArrayInputStream(new byte[] {1, 2, 3, 4, 5,
6}),
+ new DontCloseByteArrayInputStream(new byte[] {1, 2, 3, 4, 5,
7})));
}
@Test
public void contentEqualLargeSame() throws Exception {
- assertThat(
- IOUtil.contentEquals(
- new DontCloseByteArrayInputStream(new byte[8192]),
- new DontCloseByteArrayInputStream(new byte[8192])),
- is(true));
+ assertTrue(IOUtil.contentEquals(
+ new DontCloseByteArrayInputStream(new byte[8192]), new
DontCloseByteArrayInputStream(new byte[8192])));
}
@Test
public void contentEqualLargeDifferent() throws Exception {
byte[] buf = new byte[8192];
buf[8191] = 1;
- assertThat(
- IOUtil.contentEquals(
- new DontCloseByteArrayInputStream(new byte[8192]), new
DontCloseByteArrayInputStream(buf)),
- is(false));
+ assertFalse(IOUtil.contentEquals(
+ new DontCloseByteArrayInputStream(new byte[8192]), new
DontCloseByteArrayInputStream(buf)));
}
@Test
- public void toStringNullByteArray() throws Exception {
+ public void toStringNullByteArray() {
assertThrows(NullPointerException.class, () ->
IOUtil.toString(nullByteArray()));
}
@Test
public void toStringEmptyByteArray() throws Exception {
- assertThat(IOUtil.toString(emptyByteArray()), is(emptyString()));
+ assertEquals(emptyString(), IOUtil.toString(emptyByteArray()));
}
@Test
public void toStringByteArray() throws Exception {
- String probe = "A string \u2345\u00ef";
- assertThat(IOUtil.toString(probe.getBytes()).getBytes(),
is(probe.getBytes()));
+ String probe = "A string ⍅ï";
+ assertArrayEquals(probe.getBytes(),
IOUtil.toString(probe.getBytes()).getBytes());
}
@Test
- public void toStringNullByteArrayNegBufSz() throws Exception {
+ public void toStringNullByteArrayNegBufSz() {
assertThrows(NullPointerException.class, () ->
IOUtil.toString(nullByteArray(), -1));
}
@Test
- public void toStringEmptyByteArrayNegBufSz() throws Exception {
+ public void toStringEmptyByteArrayNegBufSz() {
assertThrows(
NegativeArraySizeException.class,
- () -> assertThat(IOUtil.toString(emptyByteArray(), -1),
is(emptyString())));
+ () -> assertEquals(IOUtil.toString(emptyByteArray(), -1),
emptyString()));
}
@Test
- public void toStringByteArrayNegBufSz() throws Exception {
+ public void toStringByteArrayNegBufSz() {
assertThrows(NegativeArraySizeException.class, () -> {
- String probe = "A string \u2345\u00ef";
- assertThat(IOUtil.toString(probe.getBytes(), -1), is(probe));
+ String probe = "A string ⍅ï";
+ assertEquals(probe, IOUtil.toString(probe.getBytes(), -1));
});
}
@Test
@Timeout(value = INFINITE_LOOP_TIMEOUT, unit = TimeUnit.MILLISECONDS)
- public void toStringNullByteArrayZeroBufSz() throws Exception {
+ public void toStringNullByteArrayZeroBufSz() {
assertThrows(NullPointerException.class, () ->
IOUtil.toString(nullByteArray(), 0));
}
@Test
- public void toStringNullByteArrayPosBufSz() throws Exception {
+ public void toStringNullByteArrayPosBufSz() {
assertThrows(NullPointerException.class, () ->
IOUtil.toString(nullByteArray(), 1));
}
@Test
public void toStringEmptyByteArrayPosBufSz() throws Exception {
- assertThat(IOUtil.toString(emptyByteArray(), 1), is(emptyString()));
+ assertEquals(emptyString(), IOUtil.toString(emptyByteArray(), 1));
}
@Test
public void toStringByteArrayPosBufSz() throws Exception {
- String probe = "A string \u2345\u00ef";
- assertThat(IOUtil.toString(probe.getBytes(), 1).getBytes(),
is(probe.getBytes()));
+ String probe = "A string ⍅ï";
+ assertArrayEquals(probe.getBytes(), IOUtil.toString(probe.getBytes(),
1).getBytes());
}
@Test
- public void toStringNullByteArrayNullEncoding() throws Exception {
+ public void toStringNullByteArrayNullEncoding() {
assertThrows(NullPointerException.class, () ->
IOUtil.toString(nullByteArray(), null));
}
@Test
- public void toStringEmptyByteArrayNullEncoding() throws Exception {
- assertThrows(
- NullPointerException.class,
- () -> assertThat(IOUtil.toString(emptyByteArray(), null),
is(emptyString())));
+ public void toStringEmptyByteArrayNullEncoding() {
+ assertThrows(NullPointerException.class, () ->
IOUtil.toString(emptyByteArray(), null));
}
@Test
- public void toStringByteArrayNullEncoding() throws Exception {
+ public void toStringByteArrayNullEncoding() {
assertThrows(NullPointerException.class, () -> {
- String probe = "A string \u2345\u00ef";
- assertThat(IOUtil.toString(probe.getBytes(), null).getBytes(),
is(probe.getBytes()));
+ String probe = "A string ⍅ï";
+ IOUtil.toString(probe.getBytes(), null).getBytes();
});
}
@Test
- public void toStringNullByteArrayJunkEncoding() throws Exception {
+ public void toStringNullByteArrayJunkEncoding() {
assertThrows(NullPointerException.class, () ->
IOUtil.toString(nullByteArray(), "junk"));
}
@Test
- public void toStringEmptyByteArrayJunkEncoding() throws Exception {
+ public void toStringEmptyByteArrayJunkEncoding() {
assertThrows(
UnsupportedEncodingException.class,
- () -> assertThat(IOUtil.toString(emptyByteArray(), "junk"),
is(emptyString())));
+ () -> assertEquals(IOUtil.toString(emptyByteArray(), "junk"),
emptyString()));
Review Comment:
The assertEquals parameters are in the wrong order. In JUnit 5, the
convention is assertEquals(expected, actual). This should be:
assertEquals(emptyString(), IOUtil.toString(emptyByteArray(), "junk"))
```suggestion
() -> assertEquals(emptyString(),
IOUtil.toString(emptyByteArray(), "junk")));
```
##########
src/test/java/org/apache/maven/shared/utils/StringUtilsTest.java:
##########
@@ -781,26 +773,26 @@ public void testJoinIteratorNPE() {
public void testJoinIterator() {
ArrayList<String> list = new ArrayList<>();
- assertThat(StringUtils.join(list.iterator(), null), is(""));
+ assertEquals(StringUtils.join(list.iterator(), null), "");
list.add("a");
list.add("b");
list.add("c");
- assertThat(StringUtils.join(list.iterator(), null), is("abc"));
+ assertEquals("abc", StringUtils.join(list.iterator(), null));
- assertThat(StringUtils.join(list.iterator(), "__"), is("a__b__c"));
+ assertEquals(StringUtils.join(list.iterator(), "__"), "a__b__c");
Review Comment:
The assertEquals parameters are in the wrong order. In JUnit 5, the
convention is assertEquals(expected, actual). This should be:
assertEquals("a__b__c", StringUtils.join(list.iterator(), "__"))
```suggestion
assertEquals("a__b__c", StringUtils.join(list.iterator(), "__"));
```
##########
src/test/java/org/apache/maven/shared/utils/io/IOUtilTest.java:
##########
@@ -1973,81 +1966,81 @@ public void copyEmptyReaderValidOutputStream() throws
Exception {
@Test
public void copyReaderValidOutputStream() throws Exception {
ByteArrayOutputStream outputStream = new
DontCloseByteArrayOutputStream();
- String probe = "A string \u2345\u00ef";
+ String probe = "A string ⍅ï";
IOUtil.copy(new DontCloseStringReader(probe), outputStream);
- assertThat(outputStream.toByteArray(), is(probe.getBytes()));
+ assertArrayEquals(probe.getBytes(), outputStream.toByteArray());
}
/*
* copy(Reader,OutputStream,int)
*/
@Test
- public void copyNullReaderNullOutputStreamNegBufSz() throws Exception {
+ public void copyNullReaderNullOutputStreamNegBufSz() {
assertThrows(NullPointerException.class, () ->
IOUtil.copy(nullReader(), nullOutputStream(), -1));
}
@Test
- public void copyNullReaderValidOutputStreamNegBufSz() throws Exception {
+ public void copyNullReaderValidOutputStreamNegBufSz() {
assertThrows(
NegativeArraySizeException.class,
() -> IOUtil.copy(nullReader(), new
DontCloseByteArrayOutputStream(), -1));
}
@Test
- public void copyEmptyReaderNullOutputStreamNegBufSz() throws Exception {
+ public void copyEmptyReaderNullOutputStreamNegBufSz() {
assertThrows(NullPointerException.class, () ->
IOUtil.copy(emptyReader(), nullOutputStream(), -1));
}
@Test
- public void copyEmptyReaderValidOutputStreamNegBufSz() throws Exception {
+ public void copyEmptyReaderValidOutputStreamNegBufSz() {
assertThrows(
NegativeArraySizeException.class,
() -> IOUtil.copy(emptyReader(), new
DontCloseByteArrayOutputStream(), -1));
}
@Test
- public void copyReaderValidOutputStreamNegBufSz() throws Exception {
+ public void copyReaderValidOutputStreamNegBufSz() {
assertThrows(NegativeArraySizeException.class, () -> {
ByteArrayOutputStream outputStream = new
DontCloseByteArrayOutputStream();
- String probe = "A string \u2345\u00ef";
+ String probe = "A string ⍅ï";
IOUtil.copy(new DontCloseStringReader(probe), outputStream, -1);
- assertThat(outputStream.toByteArray(), is(probe.getBytes()));
+ assertEquals(probe.getBytes(), outputStream.toByteArray());
Review Comment:
For comparing byte arrays, assertArrayEquals should be used instead of
assertEquals. This should be: assertArrayEquals(probe.getBytes(),
outputStream.toByteArray())
```suggestion
assertArrayEquals(probe.getBytes(), outputStream.toByteArray());
```
##########
src/test/java/org/apache/maven/shared/utils/io/IOUtilTest.java:
##########
@@ -761,257 +753,259 @@ public void copyInputStreamValidOutputStreamPosBufSz()
throws Exception {
ByteArrayOutputStream outputStream = new
DontCloseByteArrayOutputStream();
byte[] input = {1, 2, 3, 4, 5, 6};
IOUtil.copy(new DontCloseByteArrayInputStream(input), outputStream, 1);
- assertThat(outputStream.toByteArray(), is(input));
+ assertArrayEquals(input, outputStream.toByteArray());
}
@Test
- public void toStringNullInputStream() throws Exception {
+ public void toStringNullInputStream() {
assertThrows(NullPointerException.class, () ->
IOUtil.toString(nullInputStream()));
}
@Test
public void toStringEmptyInputStream() throws Exception {
- assertThat(IOUtil.toString(emptyInputStream()), is(emptyString()));
+ assertEquals(emptyString(), IOUtil.toString(emptyInputStream()));
}
@Test
public void toStringInputStream() throws Exception {
- String probe = "A string \u2345\u00ef";
- assertThat(IOUtil.toString(new
ByteArrayInputStream(probe.getBytes())).getBytes(), is(probe.getBytes()));
+ String probe = "A string ⍅ï";
+ assertArrayEquals(
+ probe.getBytes(),
+ IOUtil.toString(new
ByteArrayInputStream(probe.getBytes())).getBytes());
}
@Test
- public void toStringNullInputStreamNegBufSz() throws Exception {
+ public void toStringNullInputStreamNegBufSz() {
assertThrows(NullPointerException.class, () ->
IOUtil.toString(nullInputStream(), -1));
}
@Test
- public void toStringEmptyInputStreamNegBufSz() throws Exception {
+ public void toStringEmptyInputStreamNegBufSz() {
assertThrows(
NegativeArraySizeException.class,
- () -> assertThat(IOUtil.toString(emptyInputStream(), -1),
is(emptyString())));
+ () -> assertEquals(IOUtil.toString(emptyInputStream(), -1),
emptyString()));
}
@Test
- public void toStringInputStreamNegBufSz() throws Exception {
+ public void toStringInputStreamNegBufSz() {
assertThrows(NegativeArraySizeException.class, () -> {
- String probe = "A string \u2345\u00ef";
- assertThat(IOUtil.toString(new
ByteArrayInputStream(probe.getBytes()), -1), is(probe));
+ String probe = "A string ⍅ï";
+ assertEquals(probe, IOUtil.toString(new
ByteArrayInputStream(probe.getBytes()), -1));
});
}
@Test
@Timeout(value = INFINITE_LOOP_TIMEOUT, unit = TimeUnit.MILLISECONDS)
- public void toStringNullInputStreamZeroBufSz() throws Exception {
+ public void toStringNullInputStreamZeroBufSz() {
assertThrows(NullPointerException.class, () ->
IOUtil.toString(nullInputStream(), 0));
}
@Test
- public void toStringNullInputStreamPosBufSz() throws Exception {
+ public void toStringNullInputStreamPosBufSz() {
assertThrows(NullPointerException.class, () ->
IOUtil.toString(nullInputStream(), 1));
}
@Test
public void toStringEmptyInputStreamPosBufSz() throws Exception {
- assertThat(IOUtil.toString(emptyInputStream(), 1), is(emptyString()));
+ assertEquals(IOUtil.toString(emptyInputStream(), 1), emptyString());
Review Comment:
The assertEquals parameters are in the wrong order throughout this method
and similar test methods. In JUnit 5, the convention is assertEquals(expected,
actual). All instances where the result of a method call appears as the first
parameter should be swapped to have the expected value first.
##########
src/test/java/org/apache/maven/shared/utils/io/IOUtilTest.java:
##########
@@ -160,350 +164,338 @@ public void close() throws IOException {
super.close();
}
});
- assertThat(closed.get(), is(true));
+ assertTrue(closed.get());
}
@Test
public void toByteArrayFromString() throws Exception {
- String probe = "A string \u2345\u00ef";
- assertThat(IOUtil.toByteArray(probe), is(probe.getBytes()));
+ String probe = "A string ⍅ï";
+ assertArrayEquals(probe.getBytes(), IOUtil.toByteArray(probe));
}
@Test
public void toByteArrayFromReader() throws Exception {
- String probe = "A string \u2345\u00ef";
- assertThat(IOUtil.toByteArray(new StringReader(probe)),
is(probe.getBytes()));
+ String probe = "A string ⍅ï";
+ assertArrayEquals(probe.getBytes(), IOUtil.toByteArray(new
StringReader(probe)));
}
@Test
public void toByteArrayFromInputStream() throws Exception {
- String probe = "A string \u2345\u00ef";
- assertThat(
- IOUtil.toByteArray(new
DontCloseByteArrayInputStream(IOUtil.toByteArray(probe))),
is(probe.getBytes()));
+ String probe = "A string ⍅ï";
+ assertArrayEquals(
+ probe.getBytes(), IOUtil.toByteArray(new
DontCloseByteArrayInputStream(IOUtil.toByteArray(probe))));
}
@Test
- public void toByteArrayNullString() throws Exception {
+ public void toByteArrayNullString() {
+ //noinspection DataFlowIssue
assertThrows(NullPointerException.class, () ->
IOUtil.toByteArray((String) null));
}
@Test
- public void toByteArrayNullReader() throws Exception {
+ public void toByteArrayNullReader() {
+ //noinspection DataFlowIssue
assertThrows(NullPointerException.class, () ->
IOUtil.toByteArray((Reader) null));
}
@Test
- public void toByteArrayNullInputStream() throws Exception {
- assertThrows(NullPointerException.class, () ->
IOUtil.toByteArray(nullInputStream()));
+ public void toByteArrayNullInputStream() {
+ assertThrows(NullPointerException.class, () -> {
+ IOUtil.toByteArray(nullInputStream());
+ });
}
@Test
- public void contentEqualNullNull() throws Exception {
+ public void contentEqualNullNull() {
+ //noinspection DataFlowIssue
assertThrows(IOException.class, () -> IOUtil.contentEquals(null,
null));
}
@Test
- public void contentEqualNonNullNull() throws Exception {
+ public void contentEqualNonNullNull() {
+ //noinspection DataFlowIssue
assertThrows(
IOException.class,
() -> IOUtil.contentEquals(new
DontCloseByteArrayInputStream(emptyByteArray()), null));
}
@Test
- public void contentEqualNullNonNull() throws Exception {
+ public void contentEqualNullNonNull() {
+ //noinspection DataFlowIssue
assertThrows(
IOException.class,
() -> IOUtil.contentEquals(new
DontCloseByteArrayInputStream(emptyByteArray()), null));
}
@Test
public void contentEqualEmptyEmpty() throws Exception {
- assertThat(
- IOUtil.contentEquals(
- new DontCloseByteArrayInputStream(emptyByteArray()),
- new DontCloseByteArrayInputStream(emptyByteArray())),
- is(true));
+ assertTrue(IOUtil.contentEquals(
+ new DontCloseByteArrayInputStream(emptyByteArray()),
+ new DontCloseByteArrayInputStream(emptyByteArray())));
}
@Test
public void contentEqualNonEmptyEmpty() throws Exception {
- assertThat(
- IOUtil.contentEquals(
- new DontCloseByteArrayInputStream(new byte[1]),
- new DontCloseByteArrayInputStream(emptyByteArray())),
- is(false));
+ assertFalse(IOUtil.contentEquals(
+ new DontCloseByteArrayInputStream(new byte[1]), new
DontCloseByteArrayInputStream(emptyByteArray())));
}
@Test
public void contentEqualEmptyNonEmpty() throws Exception {
- assertThat(
- IOUtil.contentEquals(
- new DontCloseByteArrayInputStream(emptyByteArray()),
- new DontCloseByteArrayInputStream(new byte[1])),
- is(false));
+ assertFalse(IOUtil.contentEquals(
+ new DontCloseByteArrayInputStream(emptyByteArray()), new
DontCloseByteArrayInputStream(new byte[1])));
}
@Test
public void contentEqualNonEmptyNonEmpty() throws Exception {
- assertThat(
- IOUtil.contentEquals(
- new DontCloseByteArrayInputStream(new byte[1]), new
DontCloseByteArrayInputStream(new byte[1])),
- is(true));
+ assertTrue(IOUtil.contentEquals(
+ new DontCloseByteArrayInputStream(new byte[1]), new
DontCloseByteArrayInputStream(new byte[1])));
}
@Test
public void contentEqualMostlySame() throws Exception {
- assertThat(
- IOUtil.contentEquals(
- new DontCloseByteArrayInputStream(new byte[] {1, 2, 3,
4, 5, 6}),
- new DontCloseByteArrayInputStream(new byte[] {1, 2, 3,
4, 5, 7})),
- is(false));
+ assertFalse(IOUtil.contentEquals(
+ new DontCloseByteArrayInputStream(new byte[] {1, 2, 3, 4, 5,
6}),
+ new DontCloseByteArrayInputStream(new byte[] {1, 2, 3, 4, 5,
7})));
}
@Test
public void contentEqualLargeSame() throws Exception {
- assertThat(
- IOUtil.contentEquals(
- new DontCloseByteArrayInputStream(new byte[8192]),
- new DontCloseByteArrayInputStream(new byte[8192])),
- is(true));
+ assertTrue(IOUtil.contentEquals(
+ new DontCloseByteArrayInputStream(new byte[8192]), new
DontCloseByteArrayInputStream(new byte[8192])));
}
@Test
public void contentEqualLargeDifferent() throws Exception {
byte[] buf = new byte[8192];
buf[8191] = 1;
- assertThat(
- IOUtil.contentEquals(
- new DontCloseByteArrayInputStream(new byte[8192]), new
DontCloseByteArrayInputStream(buf)),
- is(false));
+ assertFalse(IOUtil.contentEquals(
+ new DontCloseByteArrayInputStream(new byte[8192]), new
DontCloseByteArrayInputStream(buf)));
}
@Test
- public void toStringNullByteArray() throws Exception {
+ public void toStringNullByteArray() {
assertThrows(NullPointerException.class, () ->
IOUtil.toString(nullByteArray()));
}
@Test
public void toStringEmptyByteArray() throws Exception {
- assertThat(IOUtil.toString(emptyByteArray()), is(emptyString()));
+ assertEquals(emptyString(), IOUtil.toString(emptyByteArray()));
}
@Test
public void toStringByteArray() throws Exception {
- String probe = "A string \u2345\u00ef";
- assertThat(IOUtil.toString(probe.getBytes()).getBytes(),
is(probe.getBytes()));
+ String probe = "A string ⍅ï";
+ assertArrayEquals(probe.getBytes(),
IOUtil.toString(probe.getBytes()).getBytes());
}
@Test
- public void toStringNullByteArrayNegBufSz() throws Exception {
+ public void toStringNullByteArrayNegBufSz() {
assertThrows(NullPointerException.class, () ->
IOUtil.toString(nullByteArray(), -1));
}
@Test
- public void toStringEmptyByteArrayNegBufSz() throws Exception {
+ public void toStringEmptyByteArrayNegBufSz() {
assertThrows(
NegativeArraySizeException.class,
- () -> assertThat(IOUtil.toString(emptyByteArray(), -1),
is(emptyString())));
+ () -> assertEquals(IOUtil.toString(emptyByteArray(), -1),
emptyString()));
}
@Test
- public void toStringByteArrayNegBufSz() throws Exception {
+ public void toStringByteArrayNegBufSz() {
assertThrows(NegativeArraySizeException.class, () -> {
- String probe = "A string \u2345\u00ef";
- assertThat(IOUtil.toString(probe.getBytes(), -1), is(probe));
+ String probe = "A string ⍅ï";
+ assertEquals(probe, IOUtil.toString(probe.getBytes(), -1));
});
}
@Test
@Timeout(value = INFINITE_LOOP_TIMEOUT, unit = TimeUnit.MILLISECONDS)
- public void toStringNullByteArrayZeroBufSz() throws Exception {
+ public void toStringNullByteArrayZeroBufSz() {
assertThrows(NullPointerException.class, () ->
IOUtil.toString(nullByteArray(), 0));
}
@Test
- public void toStringNullByteArrayPosBufSz() throws Exception {
+ public void toStringNullByteArrayPosBufSz() {
assertThrows(NullPointerException.class, () ->
IOUtil.toString(nullByteArray(), 1));
}
@Test
public void toStringEmptyByteArrayPosBufSz() throws Exception {
- assertThat(IOUtil.toString(emptyByteArray(), 1), is(emptyString()));
+ assertEquals(emptyString(), IOUtil.toString(emptyByteArray(), 1));
}
@Test
public void toStringByteArrayPosBufSz() throws Exception {
- String probe = "A string \u2345\u00ef";
- assertThat(IOUtil.toString(probe.getBytes(), 1).getBytes(),
is(probe.getBytes()));
+ String probe = "A string ⍅ï";
+ assertArrayEquals(probe.getBytes(), IOUtil.toString(probe.getBytes(),
1).getBytes());
}
@Test
- public void toStringNullByteArrayNullEncoding() throws Exception {
+ public void toStringNullByteArrayNullEncoding() {
assertThrows(NullPointerException.class, () ->
IOUtil.toString(nullByteArray(), null));
}
@Test
- public void toStringEmptyByteArrayNullEncoding() throws Exception {
- assertThrows(
- NullPointerException.class,
- () -> assertThat(IOUtil.toString(emptyByteArray(), null),
is(emptyString())));
+ public void toStringEmptyByteArrayNullEncoding() {
+ assertThrows(NullPointerException.class, () ->
IOUtil.toString(emptyByteArray(), null));
}
@Test
- public void toStringByteArrayNullEncoding() throws Exception {
+ public void toStringByteArrayNullEncoding() {
assertThrows(NullPointerException.class, () -> {
- String probe = "A string \u2345\u00ef";
- assertThat(IOUtil.toString(probe.getBytes(), null).getBytes(),
is(probe.getBytes()));
+ String probe = "A string ⍅ï";
+ IOUtil.toString(probe.getBytes(), null).getBytes();
});
}
@Test
- public void toStringNullByteArrayJunkEncoding() throws Exception {
+ public void toStringNullByteArrayJunkEncoding() {
assertThrows(NullPointerException.class, () ->
IOUtil.toString(nullByteArray(), "junk"));
}
@Test
- public void toStringEmptyByteArrayJunkEncoding() throws Exception {
+ public void toStringEmptyByteArrayJunkEncoding() {
assertThrows(
UnsupportedEncodingException.class,
- () -> assertThat(IOUtil.toString(emptyByteArray(), "junk"),
is(emptyString())));
+ () -> assertEquals(IOUtil.toString(emptyByteArray(), "junk"),
emptyString()));
}
@Test
- public void toStringByteArrayJunkEncoding() throws Exception {
+ public void toStringByteArrayJunkEncoding() {
assertThrows(UnsupportedEncodingException.class, () -> {
- String probe = "A string \u2345\u00ef";
- assertThat(IOUtil.toString(probe.getBytes(), "junk").getBytes(),
is(probe.getBytes()));
+ String probe = "A string ⍅ï";
+ assertArrayEquals(IOUtil.toString(probe.getBytes(),
"junk").getBytes(), probe.getBytes());
});
}
@Test
- public void toStringNullByteArrayValidEncoding() throws Exception {
+ public void toStringNullByteArrayValidEncoding() {
assertThrows(NullPointerException.class, () ->
IOUtil.toString(nullByteArray(), "utf-16"));
}
@Test
public void toStringEmptyByteArrayValidEncoding() throws Exception {
- assertThat(IOUtil.toString(emptyByteArray(), "utf-16"),
is(emptyString()));
+ assertEquals(IOUtil.toString(emptyByteArray(), "utf-16"),
emptyString());
Review Comment:
The assertEquals parameters are in the wrong order. In JUnit 5, the
convention is assertEquals(expected, actual). This should be:
assertEquals(emptyString(), IOUtil.toString(emptyByteArray(), "utf-16"))
```suggestion
assertEquals(emptyString(), IOUtil.toString(emptyByteArray(),
"utf-16"));
```
##########
src/test/java/org/apache/maven/shared/utils/StringUtilsTest.java:
##########
@@ -781,26 +773,26 @@ public void testJoinIteratorNPE() {
public void testJoinIterator() {
ArrayList<String> list = new ArrayList<>();
- assertThat(StringUtils.join(list.iterator(), null), is(""));
+ assertEquals(StringUtils.join(list.iterator(), null), "");
Review Comment:
The assertEquals parameters are in the wrong order. In JUnit 5, the
convention is assertEquals(expected, actual). This should be: assertEquals("",
StringUtils.join(list.iterator(), null))
##########
src/test/java/org/apache/maven/shared/utils/io/IOUtilTest.java:
##########
@@ -2298,267 +2291,267 @@ public void
copyNullByteArrayValidWriterValidEncoding() throws Exception {
public void copyEmptyByteArrayValidWriterValidEncoding() throws Exception {
StringWriter writer = new DontCloseStringWriter();
IOUtil.copy(emptyByteArray(), writer, "utf-16");
- assertThat(writer.toString(), is(emptyString()));
+ assertEquals(emptyString(), writer.toString());
}
@Test
- public void copyByteArrayNullWriterValidEncoding() throws Exception {
+ public void copyByteArrayNullWriterValidEncoding() {
assertThrows(NullPointerException.class, () -> {
- String probe = "A string \u2345\u00ef";
+ String probe = "A string ⍅ï";
IOUtil.copy(probe.getBytes("utf-16"), nullWriter(), "utf-16");
});
}
@Test
public void copyByteArrayValidWriterValidEncoding() throws Exception {
- String probe = "A string \u2345\u00ef";
+ String probe = "A string ⍅ï";
StringWriter writer = new DontCloseStringWriter();
- IOUtil.copy(probe.getBytes("utf-16"), writer, "utf-16");
- assertThat(writer.toString().getBytes("utf-8"),
is(probe.getBytes("utf-8")));
+ IOUtil.copy(probe.getBytes(UTF_16), writer, "utf-16");
+ assertArrayEquals(probe.getBytes(UTF_8),
writer.toString().getBytes(UTF_8));
}
/*
* copy(byte[],Writer,String,int)
*/
@Test
- public void copyNullByteArrayNullWriterNullEncodingNegBufSz() throws
Exception {
+ public void copyNullByteArrayNullWriterNullEncodingNegBufSz() {
assertThrows(NullPointerException.class, () ->
IOUtil.copy(nullByteArray(), nullWriter(), null, -1));
}
@Test
- public void copyNullByteArrayValidWriterNullEncodingNegBufSz() throws
Exception {
+ public void copyNullByteArrayValidWriterNullEncodingNegBufSz() {
assertThrows(
NullPointerException.class, () -> IOUtil.copy(nullByteArray(),
new DontCloseStringWriter(), null, -1));
}
@Test
- public void copyEmptyByteArrayNullWriterNullEncodingNegBufSz() throws
Exception {
+ public void copyEmptyByteArrayNullWriterNullEncodingNegBufSz() {
assertThrows(NullPointerException.class, () ->
IOUtil.copy(emptyByteArray(), nullWriter(), null, -1));
}
@Test
- public void copyEmptyByteArrayValidWriterNullEncodingNegBufSz() throws
Exception {
+ public void copyEmptyByteArrayValidWriterNullEncodingNegBufSz() {
assertThrows(NullPointerException.class, () -> {
StringWriter writer = new DontCloseStringWriter();
IOUtil.copy(emptyByteArray(), writer, null, -1);
- assertThat(writer.toString(), is(emptyString()));
+ assertEquals(emptyString(), writer.toString());
});
}
@Test
- public void copyByteArrayNullWriterNullEncodingNegBufSz() throws Exception
{
+ public void copyByteArrayNullWriterNullEncodingNegBufSz() {
assertThrows(NullPointerException.class, () -> {
- String probe = "A string \u2345\u00ef";
+ String probe = "A string ⍅ï";
IOUtil.copy(probe.getBytes(), nullWriter(), null, -1);
});
}
@Test
- public void copyByteArrayValidWriterNullEncodingNegBufSz() throws
Exception {
+ public void copyByteArrayValidWriterNullEncodingNegBufSz() {
assertThrows(NullPointerException.class, () -> {
- String probe = "A string \u2345\u00ef";
+ String probe = "A string ⍅ï";
StringWriter writer = new DontCloseStringWriter();
IOUtil.copy(probe.getBytes(), writer, null, -1);
- assertThat(writer.toString().getBytes(), is(probe.getBytes()));
+ assertArrayEquals(probe.getBytes(), writer.toString().getBytes());
});
}
@Test
- public void copyNullByteArrayNullWriterJunkEncodingNegBufSz() throws
Exception {
+ public void copyNullByteArrayNullWriterJunkEncodingNegBufSz() {
assertThrows(NullPointerException.class, () ->
IOUtil.copy(nullByteArray(), nullWriter(), "junk", -1));
}
@Test
- public void copyNullByteArrayValidWriterJunkEncodingNegBufSz() throws
Exception {
+ public void copyNullByteArrayValidWriterJunkEncodingNegBufSz() {
assertThrows(
NullPointerException.class,
() -> IOUtil.copy(nullByteArray(), new
DontCloseStringWriter(), "junk", -1));
}
@Test
- public void copyEmptyByteArrayNullWriterJunkEncodingNegBufSz() throws
Exception {
+ public void copyEmptyByteArrayNullWriterJunkEncodingNegBufSz() {
assertThrows(UnsupportedEncodingException.class, () ->
IOUtil.copy(emptyByteArray(), nullWriter(), "junk", -1));
}
@Test
- public void copyEmptyByteArrayJunkEncodingNegBufSz() throws Exception {
+ public void copyEmptyByteArrayJunkEncodingNegBufSz() {
assertThrows(UnsupportedEncodingException.class, () -> {
StringWriter writer = new DontCloseStringWriter();
IOUtil.copy(emptyByteArray(), writer, "junk", -1);
- assertThat(writer.toString(), is(emptyString()));
+ assertEquals(emptyString(), writer.toString());
});
}
@Test
- public void copyByteArrayNullWriterJunkEncodingNegBufSz() throws Exception
{
+ public void copyByteArrayNullWriterJunkEncodingNegBufSz() {
assertThrows(UnsupportedEncodingException.class, () -> {
- String probe = "A string \u2345\u00ef";
+ String probe = "A string ⍅ï";
IOUtil.copy(probe.getBytes(), nullWriter(), "junk", -1);
});
}
@Test
- public void copyByteArrayValidWriterJunkEncodingNegBufSz() throws
Exception {
+ public void copyByteArrayValidWriterJunkEncodingNegBufSz() {
assertThrows(UnsupportedEncodingException.class, () -> {
- String probe = "A string \u2345\u00ef";
+ String probe = "A string ⍅ï";
StringWriter writer = new DontCloseStringWriter();
IOUtil.copy(probe.getBytes(), writer, "junk", -1);
- assertThat(writer.toString().getBytes(), is(probe.getBytes()));
+ assertArrayEquals(probe.getBytes(), writer.toString().getBytes());
});
}
@Test
- public void copyNullByteArrayNullWriterValidEncodingNegBufSz() throws
Exception {
+ public void copyNullByteArrayNullWriterValidEncodingNegBufSz() {
assertThrows(NullPointerException.class, () ->
IOUtil.copy(nullByteArray(), nullWriter(), "utf-16", -1));
}
@Test
- public void copyNullByteArrayValidWriterValidEncodingNegBufSz() throws
Exception {
+ public void copyNullByteArrayValidWriterValidEncodingNegBufSz() {
assertThrows(
NullPointerException.class,
() -> IOUtil.copy(nullByteArray(), new
DontCloseStringWriter(), "utf-16", -1));
}
@Test
- public void copyEmptyByteArrayNullWriterValidEncodingNegBufSz() throws
Exception {
+ public void copyEmptyByteArrayNullWriterValidEncodingNegBufSz() {
assertThrows(NegativeArraySizeException.class, () ->
IOUtil.copy(emptyByteArray(), nullWriter(), "utf-16", -1));
}
@Test
- public void copyEmptyByteArrayValidWriterValidEncodingNegBufSz() throws
Exception {
+ public void copyEmptyByteArrayValidWriterValidEncodingNegBufSz() {
assertThrows(NegativeArraySizeException.class, () -> {
StringWriter writer = new DontCloseStringWriter();
IOUtil.copy(emptyByteArray(), writer, "utf-16", -1);
- assertThat(writer.toString(), is(emptyString()));
+ assertEquals(emptyString(), writer.toString());
});
}
@Test
- public void copyByteArrayNullWriterValidEncodingNegBufSz() throws
Exception {
+ public void copyByteArrayNullWriterValidEncodingNegBufSz() {
assertThrows(NegativeArraySizeException.class, () -> {
- String probe = "A string \u2345\u00ef";
+ String probe = "A string ⍅ï";
IOUtil.copy(probe.getBytes("utf-16"), nullWriter(), -1);
});
}
@Test
- public void copyByteArrayValidEncodingNegBufSz() throws Exception {
+ public void copyByteArrayValidEncodingNegBufSz() {
assertThrows(NegativeArraySizeException.class, () -> {
- String probe = "A string \u2345\u00ef";
+ String probe = "A string ⍅ï";
StringWriter writer = new DontCloseStringWriter();
IOUtil.copy(probe.getBytes("utf-16"), writer, "utf-16", -1);
- assertThat(writer.toString().getBytes("utf-8"),
is(probe.getBytes("utf-8")));
+ assertEquals(probe.getBytes("utf-8"),
writer.toString().getBytes("utf-8"));
Review Comment:
For comparing byte arrays, assertArrayEquals should be used instead of
assertEquals. This should be: assertArrayEquals(probe.getBytes("utf-8"),
writer.toString().getBytes("utf-8"))
```suggestion
assertArrayEquals(probe.getBytes("utf-8"),
writer.toString().getBytes("utf-8"));
```
##########
src/test/java/org/apache/maven/shared/utils/io/IOUtilTest.java:
##########
@@ -1895,26 +1888,26 @@ public void toByteArrayNullReaderPosBufSz() throws
Exception {
*/
@Test
- public void toByteArrayFromStringNegBufSz() throws Exception {
+ public void toByteArrayFromStringNegBufSz() {
assertThrows(NegativeArraySizeException.class, () -> {
- String probe = "A string \u2345\u00ef";
- assertThat(IOUtil.toByteArray(probe, -1), is(probe.getBytes()));
+ String probe = "A string ⍅ï";
+ assertEquals(IOUtil.toByteArray(probe, -1), probe.getBytes());
Review Comment:
The assertEquals parameters are in the wrong order, and for comparing byte
arrays, assertArrayEquals should be used. This should be:
assertArrayEquals(probe.getBytes(), IOUtil.toByteArray(probe, -1))
```suggestion
assertArrayEquals(probe.getBytes(), IOUtil.toByteArray(probe,
-1));
```
##########
src/test/java/org/apache/maven/shared/utils/io/IOUtilTest.java:
##########
@@ -160,350 +164,338 @@ public void close() throws IOException {
super.close();
}
});
- assertThat(closed.get(), is(true));
+ assertTrue(closed.get());
}
@Test
public void toByteArrayFromString() throws Exception {
- String probe = "A string \u2345\u00ef";
- assertThat(IOUtil.toByteArray(probe), is(probe.getBytes()));
+ String probe = "A string ⍅ï";
+ assertArrayEquals(probe.getBytes(), IOUtil.toByteArray(probe));
}
@Test
public void toByteArrayFromReader() throws Exception {
- String probe = "A string \u2345\u00ef";
- assertThat(IOUtil.toByteArray(new StringReader(probe)),
is(probe.getBytes()));
+ String probe = "A string ⍅ï";
+ assertArrayEquals(probe.getBytes(), IOUtil.toByteArray(new
StringReader(probe)));
}
@Test
public void toByteArrayFromInputStream() throws Exception {
- String probe = "A string \u2345\u00ef";
- assertThat(
- IOUtil.toByteArray(new
DontCloseByteArrayInputStream(IOUtil.toByteArray(probe))),
is(probe.getBytes()));
+ String probe = "A string ⍅ï";
+ assertArrayEquals(
+ probe.getBytes(), IOUtil.toByteArray(new
DontCloseByteArrayInputStream(IOUtil.toByteArray(probe))));
}
@Test
- public void toByteArrayNullString() throws Exception {
+ public void toByteArrayNullString() {
+ //noinspection DataFlowIssue
assertThrows(NullPointerException.class, () ->
IOUtil.toByteArray((String) null));
}
@Test
- public void toByteArrayNullReader() throws Exception {
+ public void toByteArrayNullReader() {
+ //noinspection DataFlowIssue
assertThrows(NullPointerException.class, () ->
IOUtil.toByteArray((Reader) null));
}
@Test
- public void toByteArrayNullInputStream() throws Exception {
- assertThrows(NullPointerException.class, () ->
IOUtil.toByteArray(nullInputStream()));
+ public void toByteArrayNullInputStream() {
+ assertThrows(NullPointerException.class, () -> {
+ IOUtil.toByteArray(nullInputStream());
+ });
}
@Test
- public void contentEqualNullNull() throws Exception {
+ public void contentEqualNullNull() {
+ //noinspection DataFlowIssue
assertThrows(IOException.class, () -> IOUtil.contentEquals(null,
null));
}
@Test
- public void contentEqualNonNullNull() throws Exception {
+ public void contentEqualNonNullNull() {
+ //noinspection DataFlowIssue
assertThrows(
IOException.class,
() -> IOUtil.contentEquals(new
DontCloseByteArrayInputStream(emptyByteArray()), null));
}
@Test
- public void contentEqualNullNonNull() throws Exception {
+ public void contentEqualNullNonNull() {
+ //noinspection DataFlowIssue
assertThrows(
IOException.class,
() -> IOUtil.contentEquals(new
DontCloseByteArrayInputStream(emptyByteArray()), null));
}
@Test
public void contentEqualEmptyEmpty() throws Exception {
- assertThat(
- IOUtil.contentEquals(
- new DontCloseByteArrayInputStream(emptyByteArray()),
- new DontCloseByteArrayInputStream(emptyByteArray())),
- is(true));
+ assertTrue(IOUtil.contentEquals(
+ new DontCloseByteArrayInputStream(emptyByteArray()),
+ new DontCloseByteArrayInputStream(emptyByteArray())));
}
@Test
public void contentEqualNonEmptyEmpty() throws Exception {
- assertThat(
- IOUtil.contentEquals(
- new DontCloseByteArrayInputStream(new byte[1]),
- new DontCloseByteArrayInputStream(emptyByteArray())),
- is(false));
+ assertFalse(IOUtil.contentEquals(
+ new DontCloseByteArrayInputStream(new byte[1]), new
DontCloseByteArrayInputStream(emptyByteArray())));
}
@Test
public void contentEqualEmptyNonEmpty() throws Exception {
- assertThat(
- IOUtil.contentEquals(
- new DontCloseByteArrayInputStream(emptyByteArray()),
- new DontCloseByteArrayInputStream(new byte[1])),
- is(false));
+ assertFalse(IOUtil.contentEquals(
+ new DontCloseByteArrayInputStream(emptyByteArray()), new
DontCloseByteArrayInputStream(new byte[1])));
}
@Test
public void contentEqualNonEmptyNonEmpty() throws Exception {
- assertThat(
- IOUtil.contentEquals(
- new DontCloseByteArrayInputStream(new byte[1]), new
DontCloseByteArrayInputStream(new byte[1])),
- is(true));
+ assertTrue(IOUtil.contentEquals(
+ new DontCloseByteArrayInputStream(new byte[1]), new
DontCloseByteArrayInputStream(new byte[1])));
}
@Test
public void contentEqualMostlySame() throws Exception {
- assertThat(
- IOUtil.contentEquals(
- new DontCloseByteArrayInputStream(new byte[] {1, 2, 3,
4, 5, 6}),
- new DontCloseByteArrayInputStream(new byte[] {1, 2, 3,
4, 5, 7})),
- is(false));
+ assertFalse(IOUtil.contentEquals(
+ new DontCloseByteArrayInputStream(new byte[] {1, 2, 3, 4, 5,
6}),
+ new DontCloseByteArrayInputStream(new byte[] {1, 2, 3, 4, 5,
7})));
}
@Test
public void contentEqualLargeSame() throws Exception {
- assertThat(
- IOUtil.contentEquals(
- new DontCloseByteArrayInputStream(new byte[8192]),
- new DontCloseByteArrayInputStream(new byte[8192])),
- is(true));
+ assertTrue(IOUtil.contentEquals(
+ new DontCloseByteArrayInputStream(new byte[8192]), new
DontCloseByteArrayInputStream(new byte[8192])));
}
@Test
public void contentEqualLargeDifferent() throws Exception {
byte[] buf = new byte[8192];
buf[8191] = 1;
- assertThat(
- IOUtil.contentEquals(
- new DontCloseByteArrayInputStream(new byte[8192]), new
DontCloseByteArrayInputStream(buf)),
- is(false));
+ assertFalse(IOUtil.contentEquals(
+ new DontCloseByteArrayInputStream(new byte[8192]), new
DontCloseByteArrayInputStream(buf)));
}
@Test
- public void toStringNullByteArray() throws Exception {
+ public void toStringNullByteArray() {
assertThrows(NullPointerException.class, () ->
IOUtil.toString(nullByteArray()));
}
@Test
public void toStringEmptyByteArray() throws Exception {
- assertThat(IOUtil.toString(emptyByteArray()), is(emptyString()));
+ assertEquals(emptyString(), IOUtil.toString(emptyByteArray()));
}
@Test
public void toStringByteArray() throws Exception {
- String probe = "A string \u2345\u00ef";
- assertThat(IOUtil.toString(probe.getBytes()).getBytes(),
is(probe.getBytes()));
+ String probe = "A string ⍅ï";
+ assertArrayEquals(probe.getBytes(),
IOUtil.toString(probe.getBytes()).getBytes());
}
@Test
- public void toStringNullByteArrayNegBufSz() throws Exception {
+ public void toStringNullByteArrayNegBufSz() {
assertThrows(NullPointerException.class, () ->
IOUtil.toString(nullByteArray(), -1));
}
@Test
- public void toStringEmptyByteArrayNegBufSz() throws Exception {
+ public void toStringEmptyByteArrayNegBufSz() {
assertThrows(
NegativeArraySizeException.class,
- () -> assertThat(IOUtil.toString(emptyByteArray(), -1),
is(emptyString())));
+ () -> assertEquals(IOUtil.toString(emptyByteArray(), -1),
emptyString()));
Review Comment:
The assertEquals parameters are in the wrong order. In JUnit 5, the
convention is assertEquals(expected, actual). This should be:
assertEquals(emptyString(), IOUtil.toString(emptyByteArray(), -1))
```suggestion
() -> assertEquals(emptyString(),
IOUtil.toString(emptyByteArray(), -1)));
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]