You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2022/01/11 14:22:30 UTC
[commons-io] 01/04: Sort members.
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-io.git
commit 240eda8bd8c1165def702bb53f749a3c42158d87
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Tue Jan 11 08:52:16 2022 -0500
Sort members.
---
.../org/apache/commons/io/DeleteDirectoryTest.java | 10 ++---
.../commons/io/FileUtilsCleanDirectoryTest.java | 30 +++++++-------
.../org/apache/commons/io/IOUtilsCopyTest.java | 34 ++++++++--------
.../io/input/CharSequenceInputStreamTest.java | 32 +++++++--------
.../commons/io/input/ReaderInputStreamTest.java | 46 +++++++++++-----------
.../commons/io/output/BrokenOutputStreamTest.java | 30 +++++++-------
.../apache/commons/io/output/BrokenWriterTest.java | 30 +++++++-------
7 files changed, 106 insertions(+), 106 deletions(-)
diff --git a/src/test/java/org/apache/commons/io/DeleteDirectoryTest.java b/src/test/java/org/apache/commons/io/DeleteDirectoryTest.java
index 2442f2d..871bb75 100644
--- a/src/test/java/org/apache/commons/io/DeleteDirectoryTest.java
+++ b/src/test/java/org/apache/commons/io/DeleteDirectoryTest.java
@@ -87,6 +87,11 @@ public class DeleteDirectoryTest extends AbstractTempDirTest {
}
@Test
+ public void testDeleteDirectoryWithPathUtilsOverrideReadOnly() throws IOException {
+ testDeleteDirectory(dir -> PathUtils.deleteDirectory(dir, StandardDeleteOption.OVERRIDE_READ_ONLY));
+ }
+
+ @Test
@DisabledOnOs(OS.LINUX) // TODO
public void testDeleteFileCheckParentAccess() throws IOException {
// Create a test directory
@@ -117,9 +122,4 @@ public class DeleteDirectoryTest extends AbstractTempDirTest {
assertFalse(Files.isWritable(testDir));
assertFalse(Files.isExecutable(testDir));
}
-
- @Test
- public void testDeleteDirectoryWithPathUtilsOverrideReadOnly() throws IOException {
- testDeleteDirectory(dir -> PathUtils.deleteDirectory(dir, StandardDeleteOption.OVERRIDE_READ_ONLY));
- }
}
diff --git a/src/test/java/org/apache/commons/io/FileUtilsCleanDirectoryTest.java b/src/test/java/org/apache/commons/io/FileUtilsCleanDirectoryTest.java
index 8d20782..04ea31f 100644
--- a/src/test/java/org/apache/commons/io/FileUtilsCleanDirectoryTest.java
+++ b/src/test/java/org/apache/commons/io/FileUtilsCleanDirectoryTest.java
@@ -62,6 +62,21 @@ public class FileUtilsCleanDirectoryTest extends AbstractTempDirTest {
return proc.waitFor() == 0;
}
+ @DisabledOnOs(OS.WINDOWS)
+ @Test
+ public void testCleanDirectoryToForceDelete() throws Exception {
+ final File file = new File(tempDirFile, "restricted");
+ FileUtils.touch(file);
+
+ // 300 = owner: WE.
+ // 500 = owner: RE.
+ // 700 = owner: RWE.
+ assumeTrue(chmod(tempDirFile, 700, false));
+
+ // cleanDirectory calls forceDelete
+ FileUtils.cleanDirectory(tempDirFile);
+ }
+
@Test
public void testCleanEmpty() throws Exception {
assertEquals(0, tempDirFile.list().length);
@@ -100,21 +115,6 @@ public class FileUtilsCleanDirectoryTest extends AbstractTempDirTest {
@DisabledOnOs(OS.WINDOWS)
@Test
- public void testCleanDirectoryToForceDelete() throws Exception {
- final File file = new File(tempDirFile, "restricted");
- FileUtils.touch(file);
-
- // 300 = owner: WE.
- // 500 = owner: RE.
- // 700 = owner: RWE.
- assumeTrue(chmod(tempDirFile, 700, false));
-
- // cleanDirectory calls forceDelete
- FileUtils.cleanDirectory(tempDirFile);
- }
-
- @DisabledOnOs(OS.WINDOWS)
- @Test
public void testThrowsOnNullList() throws Exception {
// test wont work if we can't restrict permissions on the
// directory, so skip it.
diff --git a/src/test/java/org/apache/commons/io/IOUtilsCopyTest.java b/src/test/java/org/apache/commons/io/IOUtilsCopyTest.java
index 3da83d0..e8ac84d 100644
--- a/src/test/java/org/apache/commons/io/IOUtilsCopyTest.java
+++ b/src/test/java/org/apache/commons/io/IOUtilsCopyTest.java
@@ -65,23 +65,6 @@ public class IOUtilsCopyTest {
@SuppressWarnings("resource") // 'in' is deliberately not closed
@Test
- public void testCopy_inputStreamToOutputStream() throws Exception {
- InputStream in = new ByteArrayInputStream(inData);
- in = new ThrowOnCloseInputStream(in);
-
- final ByteArrayOutputStream baout = new ByteArrayOutputStream();
- final OutputStream out = new ThrowOnFlushAndCloseOutputStream(baout, false, true);
-
- final int count = IOUtils.copy(in, out);
-
- assertEquals(0, in.available(), "Not all bytes were read");
- assertEquals(inData.length, baout.size(), "Sizes differ");
- assertArrayEquals(inData, baout.toByteArray(), "Content differs");
- assertEquals(inData.length,count);
- }
-
- @SuppressWarnings("resource") // 'in' is deliberately not closed
- @Test
public void testCopy_byteArrayOutputStreamToInputStream() throws Exception {
final java.io.ByteArrayOutputStream out = new java.io.ByteArrayOutputStream();
out.write(inData);
@@ -101,6 +84,23 @@ public class IOUtilsCopyTest {
assertThrows(NullPointerException.class, () -> IOUtils.copy(null));
}
+ @SuppressWarnings("resource") // 'in' is deliberately not closed
+ @Test
+ public void testCopy_inputStreamToOutputStream() throws Exception {
+ InputStream in = new ByteArrayInputStream(inData);
+ in = new ThrowOnCloseInputStream(in);
+
+ final ByteArrayOutputStream baout = new ByteArrayOutputStream();
+ final OutputStream out = new ThrowOnFlushAndCloseOutputStream(baout, false, true);
+
+ final int count = IOUtils.copy(in, out);
+
+ assertEquals(0, in.available(), "Not all bytes were read");
+ assertEquals(inData.length, baout.size(), "Sizes differ");
+ assertArrayEquals(inData, baout.toByteArray(), "Content differs");
+ assertEquals(inData.length,count);
+ }
+
/**
* Test Copying file > 2GB - see issue# IO-84
*/
diff --git a/src/test/java/org/apache/commons/io/input/CharSequenceInputStreamTest.java b/src/test/java/org/apache/commons/io/input/CharSequenceInputStreamTest.java
index 2d04daa..0f34c07 100644
--- a/src/test/java/org/apache/commons/io/input/CharSequenceInputStreamTest.java
+++ b/src/test/java/org/apache/commons/io/input/CharSequenceInputStreamTest.java
@@ -75,22 +75,6 @@ public class CharSequenceInputStreamTest {
}
@Test
- public void testNullCharset() throws IOException {
- try (CharSequenceInputStream in = new CharSequenceInputStream("A", (Charset) null)) {
- IOUtils.toByteArray(in);
- assertEquals(Charset.defaultCharset(), in.getCharsetEncoder().charset());
- }
- }
-
- @Test
- public void testNullCharsetName() throws IOException {
- try (CharSequenceInputStream in = new CharSequenceInputStream("A", (String) null)) {
- IOUtils.toByteArray(in);
- assertEquals(Charset.defaultCharset(), in.getCharsetEncoder().charset());
- }
- }
-
- @Test
public void testAvailable() throws Exception {
for (final String csName : Charset.availableCharsets().keySet()) {
// prevent java.lang.UnsupportedOperationException at sun.nio.cs.ext.ISO2022_CN.newEncoder.
@@ -357,6 +341,22 @@ public class CharSequenceInputStreamTest {
}
}
+ @Test
+ public void testNullCharset() throws IOException {
+ try (CharSequenceInputStream in = new CharSequenceInputStream("A", (Charset) null)) {
+ IOUtils.toByteArray(in);
+ assertEquals(Charset.defaultCharset(), in.getCharsetEncoder().charset());
+ }
+ }
+
+ @Test
+ public void testNullCharsetName() throws IOException {
+ try (CharSequenceInputStream in = new CharSequenceInputStream("A", (String) null)) {
+ IOUtils.toByteArray(in);
+ assertEquals(Charset.defaultCharset(), in.getCharsetEncoder().charset());
+ }
+ }
+
private void testReadZero(final String csName) throws Exception {
try (InputStream r = new CharSequenceInputStream("test", csName)) {
final byte[] bytes = new byte[30];
diff --git a/src/test/java/org/apache/commons/io/input/ReaderInputStreamTest.java b/src/test/java/org/apache/commons/io/input/ReaderInputStreamTest.java
index f6750ff..ccff6de 100644
--- a/src/test/java/org/apache/commons/io/input/ReaderInputStreamTest.java
+++ b/src/test/java/org/apache/commons/io/input/ReaderInputStreamTest.java
@@ -53,19 +53,6 @@ public class ReaderInputStreamTest {
LARGE_TEST_STRING = buffer.toString();
}
- private final Random random = new Random();
-
- @ParameterizedTest
- @MethodSource("charsetData")
- public void testCharsetEncoderFlush(final String charsetName, final String data) throws IOException {
- final Charset charset = Charset.forName(charsetName);
- final byte[] expected = data.getBytes(charset);
- try (InputStream in = new ReaderInputStream(new StringReader(data), charset)) {
- final byte[] actual = IOUtils.toByteArray(in);
- assertEquals(Arrays.toString(expected), Arrays.toString(actual));
- }
- }
-
static Stream<Arguments> charsetData() {
// @formatter:off
return Stream.of(
@@ -75,12 +62,7 @@ public class ReaderInputStreamTest {
// @formatter:on
}
- @Test
- public void testBufferTooSmall() throws IOException {
- assertThrows(IllegalArgumentException.class, () -> new ReaderInputStream(new StringReader("\uD800"), StandardCharsets.UTF_8, -1));
- assertThrows(IllegalArgumentException.class, () -> new ReaderInputStream(new StringReader("\uD800"), StandardCharsets.UTF_8, 0));
- assertThrows(IllegalArgumentException.class, () -> new ReaderInputStream(new StringReader("\uD800"), StandardCharsets.UTF_8, 1));
- }
+ private final Random random = new Random();
@Test
@Timeout(value = 500, unit = TimeUnit.MILLISECONDS)
@@ -91,6 +73,24 @@ public class ReaderInputStreamTest {
}
}
+ @Test
+ public void testBufferTooSmall() throws IOException {
+ assertThrows(IllegalArgumentException.class, () -> new ReaderInputStream(new StringReader("\uD800"), StandardCharsets.UTF_8, -1));
+ assertThrows(IllegalArgumentException.class, () -> new ReaderInputStream(new StringReader("\uD800"), StandardCharsets.UTF_8, 0));
+ assertThrows(IllegalArgumentException.class, () -> new ReaderInputStream(new StringReader("\uD800"), StandardCharsets.UTF_8, 1));
+ }
+
+ @ParameterizedTest
+ @MethodSource("charsetData")
+ public void testCharsetEncoderFlush(final String charsetName, final String data) throws IOException {
+ final Charset charset = Charset.forName(charsetName);
+ final byte[] expected = data.getBytes(charset);
+ try (InputStream in = new ReaderInputStream(new StringReader(data), charset)) {
+ final byte[] actual = IOUtils.toByteArray(in);
+ assertEquals(Arrays.toString(expected), Arrays.toString(actual));
+ }
+ }
+
/*
* Tests https://issues.apache.org/jira/browse/IO-277
*/
@@ -122,9 +122,9 @@ public class ReaderInputStreamTest {
@Test
@Timeout(value = 500, unit = TimeUnit.MILLISECONDS)
- public void testConstructNullCharsetEncoder() throws IOException {
+ public void testConstructNullCharset() throws IOException {
final Charset charset = Charset.defaultCharset();
- final CharsetEncoder encoder = null;
+ final Charset encoder = null;
try (ReaderInputStream in = new ReaderInputStream(new StringReader("ABC"), encoder, (int) ReaderInputStream.minBufferSize(charset.newEncoder()))) {
IOUtils.toByteArray(in);
assertEquals(Charset.defaultCharset(), in.getCharsetEncoder().charset());
@@ -133,9 +133,9 @@ public class ReaderInputStreamTest {
@Test
@Timeout(value = 500, unit = TimeUnit.MILLISECONDS)
- public void testConstructNullCharset() throws IOException {
+ public void testConstructNullCharsetEncoder() throws IOException {
final Charset charset = Charset.defaultCharset();
- final Charset encoder = null;
+ final CharsetEncoder encoder = null;
try (ReaderInputStream in = new ReaderInputStream(new StringReader("ABC"), encoder, (int) ReaderInputStream.minBufferSize(charset.newEncoder()))) {
IOUtils.toByteArray(in);
assertEquals(Charset.defaultCharset(), in.getCharsetEncoder().charset());
diff --git a/src/test/java/org/apache/commons/io/output/BrokenOutputStreamTest.java b/src/test/java/org/apache/commons/io/output/BrokenOutputStreamTest.java
index 7750362..1f56c27 100644
--- a/src/test/java/org/apache/commons/io/output/BrokenOutputStreamTest.java
+++ b/src/test/java/org/apache/commons/io/output/BrokenOutputStreamTest.java
@@ -51,21 +51,6 @@ public class BrokenOutputStreamTest {
}
@Test
- public void testWriteByteArray() {
- assertEquals(exception, assertThrows(IOException.class, () -> stream.write(new byte[1])));
- }
-
- @Test
- public void testWriteByteArrayIndexed() {
- assertEquals(exception, assertThrows(IOException.class, () -> stream.write(new byte[1], 0, 1)));
- }
-
- @Test
- public void testWriteInt() {
- assertEquals(exception, assertThrows(IOException.class, () -> stream.write(1)));
- }
-
- @Test
public void testTryWithResources() {
final IOException thrown = assertThrows(IOException.class, () -> {
try (OutputStream newStream = new BrokenOutputStream()) {
@@ -80,4 +65,19 @@ public class BrokenOutputStreamTest {
assertEquals("Broken output stream", suppressed[0].getMessage());
}
+ @Test
+ public void testWriteByteArray() {
+ assertEquals(exception, assertThrows(IOException.class, () -> stream.write(new byte[1])));
+ }
+
+ @Test
+ public void testWriteByteArrayIndexed() {
+ assertEquals(exception, assertThrows(IOException.class, () -> stream.write(new byte[1], 0, 1)));
+ }
+
+ @Test
+ public void testWriteInt() {
+ assertEquals(exception, assertThrows(IOException.class, () -> stream.write(1)));
+ }
+
}
diff --git a/src/test/java/org/apache/commons/io/output/BrokenWriterTest.java b/src/test/java/org/apache/commons/io/output/BrokenWriterTest.java
index e6f2d62..f508b24 100644
--- a/src/test/java/org/apache/commons/io/output/BrokenWriterTest.java
+++ b/src/test/java/org/apache/commons/io/output/BrokenWriterTest.java
@@ -85,6 +85,21 @@ public class BrokenWriterTest {
}
@Test
+ public void testTryWithResources() {
+ final IOException thrown = assertThrows(IOException.class, () -> {
+ try (Writer newWriter = new BrokenWriter()) {
+ newWriter.write(1);
+ }
+ });
+ assertEquals("Broken writer", thrown.getMessage());
+
+ final Throwable[] suppressed = thrown.getSuppressed();
+ assertEquals(1, suppressed.length);
+ assertEquals(IOException.class, suppressed[0].getClass());
+ assertEquals("Broken writer", suppressed[0].getMessage());
+ }
+
+ @Test
public void testWriteCharArray() {
assertEquals(exception, assertThrows(IOException.class, () -> brokenWriter.write(new char[1])));
}
@@ -109,19 +124,4 @@ public class BrokenWriterTest {
assertEquals(exception, assertThrows(IOException.class, () -> brokenWriter.write("01", 0, 1)));
}
- @Test
- public void testTryWithResources() {
- final IOException thrown = assertThrows(IOException.class, () -> {
- try (Writer newWriter = new BrokenWriter()) {
- newWriter.write(1);
- }
- });
- assertEquals("Broken writer", thrown.getMessage());
-
- final Throwable[] suppressed = thrown.getSuppressed();
- assertEquals(1, suppressed.length);
- assertEquals(IOException.class, suppressed[0].getClass());
- assertEquals("Broken writer", suppressed[0].getMessage());
- }
-
}