Skip to content

Commit 240eda8

Browse files
committed
Sort members.
1 parent 932ca4b commit 240eda8

7 files changed

Lines changed: 106 additions & 106 deletions

File tree

src/test/java/org/apache/commons/io/DeleteDirectoryTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,11 @@ public void testDeleteDirectoryWithPathUtils() throws IOException {
8686
testDeleteDirectory(PathUtils::deleteDirectory);
8787
}
8888

89+
@Test
90+
public void testDeleteDirectoryWithPathUtilsOverrideReadOnly() throws IOException {
91+
testDeleteDirectory(dir -> PathUtils.deleteDirectory(dir, StandardDeleteOption.OVERRIDE_READ_ONLY));
92+
}
93+
8994
@Test
9095
@DisabledOnOs(OS.LINUX) // TODO
9196
public void testDeleteFileCheckParentAccess() throws IOException {
@@ -117,9 +122,4 @@ public void testDeleteFileCheckParentAccess() throws IOException {
117122
assertFalse(Files.isWritable(testDir));
118123
assertFalse(Files.isExecutable(testDir));
119124
}
120-
121-
@Test
122-
public void testDeleteDirectoryWithPathUtilsOverrideReadOnly() throws IOException {
123-
testDeleteDirectory(dir -> PathUtils.deleteDirectory(dir, StandardDeleteOption.OVERRIDE_READ_ONLY));
124-
}
125125
}

src/test/java/org/apache/commons/io/FileUtilsCleanDirectoryTest.java

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,21 @@ private boolean chmod(final File file, final int mode, final boolean recurse) th
6262
return proc.waitFor() == 0;
6363
}
6464

65+
@DisabledOnOs(OS.WINDOWS)
66+
@Test
67+
public void testCleanDirectoryToForceDelete() throws Exception {
68+
final File file = new File(tempDirFile, "restricted");
69+
FileUtils.touch(file);
70+
71+
// 300 = owner: WE.
72+
// 500 = owner: RE.
73+
// 700 = owner: RWE.
74+
assumeTrue(chmod(tempDirFile, 700, false));
75+
76+
// cleanDirectory calls forceDelete
77+
FileUtils.cleanDirectory(tempDirFile);
78+
}
79+
6580
@Test
6681
public void testCleanEmpty() throws Exception {
6782
assertEquals(0, tempDirFile.list().length);
@@ -98,21 +113,6 @@ public void testDeletesRegular() throws Exception {
98113
assertEquals(0, tempDirFile.list().length);
99114
}
100115

101-
@DisabledOnOs(OS.WINDOWS)
102-
@Test
103-
public void testCleanDirectoryToForceDelete() throws Exception {
104-
final File file = new File(tempDirFile, "restricted");
105-
FileUtils.touch(file);
106-
107-
// 300 = owner: WE.
108-
// 500 = owner: RE.
109-
// 700 = owner: RWE.
110-
assumeTrue(chmod(tempDirFile, 700, false));
111-
112-
// cleanDirectory calls forceDelete
113-
FileUtils.cleanDirectory(tempDirFile);
114-
}
115-
116116
@DisabledOnOs(OS.WINDOWS)
117117
@Test
118118
public void testThrowsOnNullList() throws Exception {

src/test/java/org/apache/commons/io/IOUtilsCopyTest.java

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -63,23 +63,6 @@ public class IOUtilsCopyTest {
6363

6464
private final byte[] inData = TestUtils.generateTestData(FILE_SIZE);
6565

66-
@SuppressWarnings("resource") // 'in' is deliberately not closed
67-
@Test
68-
public void testCopy_inputStreamToOutputStream() throws Exception {
69-
InputStream in = new ByteArrayInputStream(inData);
70-
in = new ThrowOnCloseInputStream(in);
71-
72-
final ByteArrayOutputStream baout = new ByteArrayOutputStream();
73-
final OutputStream out = new ThrowOnFlushAndCloseOutputStream(baout, false, true);
74-
75-
final int count = IOUtils.copy(in, out);
76-
77-
assertEquals(0, in.available(), "Not all bytes were read");
78-
assertEquals(inData.length, baout.size(), "Sizes differ");
79-
assertArrayEquals(inData, baout.toByteArray(), "Content differs");
80-
assertEquals(inData.length,count);
81-
}
82-
8366
@SuppressWarnings("resource") // 'in' is deliberately not closed
8467
@Test
8568
public void testCopy_byteArrayOutputStreamToInputStream() throws Exception {
@@ -101,6 +84,23 @@ public void testCopy_byteArrayOutputStreamToInputStream_nullOutputStream() {
10184
assertThrows(NullPointerException.class, () -> IOUtils.copy(null));
10285
}
10386

87+
@SuppressWarnings("resource") // 'in' is deliberately not closed
88+
@Test
89+
public void testCopy_inputStreamToOutputStream() throws Exception {
90+
InputStream in = new ByteArrayInputStream(inData);
91+
in = new ThrowOnCloseInputStream(in);
92+
93+
final ByteArrayOutputStream baout = new ByteArrayOutputStream();
94+
final OutputStream out = new ThrowOnFlushAndCloseOutputStream(baout, false, true);
95+
96+
final int count = IOUtils.copy(in, out);
97+
98+
assertEquals(0, in.available(), "Not all bytes were read");
99+
assertEquals(inData.length, baout.size(), "Sizes differ");
100+
assertArrayEquals(inData, baout.toByteArray(), "Content differs");
101+
assertEquals(inData.length,count);
102+
}
103+
104104
/**
105105
* Test Copying file > 2GB - see issue# IO-84
106106
*/

src/test/java/org/apache/commons/io/input/CharSequenceInputStreamTest.java

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -74,22 +74,6 @@ private boolean isOddBallLegacyCharsetThatDoesNotSupportFrenchCharacters(final S
7474
"Shift_JIS".equalsIgnoreCase(csName);
7575
}
7676

77-
@Test
78-
public void testNullCharset() throws IOException {
79-
try (CharSequenceInputStream in = new CharSequenceInputStream("A", (Charset) null)) {
80-
IOUtils.toByteArray(in);
81-
assertEquals(Charset.defaultCharset(), in.getCharsetEncoder().charset());
82-
}
83-
}
84-
85-
@Test
86-
public void testNullCharsetName() throws IOException {
87-
try (CharSequenceInputStream in = new CharSequenceInputStream("A", (String) null)) {
88-
IOUtils.toByteArray(in);
89-
assertEquals(Charset.defaultCharset(), in.getCharsetEncoder().charset());
90-
}
91-
}
92-
9377
@Test
9478
public void testAvailable() throws Exception {
9579
for (final String csName : Charset.availableCharsets().keySet()) {
@@ -357,6 +341,22 @@ public void testMarkSupported() throws Exception {
357341
}
358342
}
359343

344+
@Test
345+
public void testNullCharset() throws IOException {
346+
try (CharSequenceInputStream in = new CharSequenceInputStream("A", (Charset) null)) {
347+
IOUtils.toByteArray(in);
348+
assertEquals(Charset.defaultCharset(), in.getCharsetEncoder().charset());
349+
}
350+
}
351+
352+
@Test
353+
public void testNullCharsetName() throws IOException {
354+
try (CharSequenceInputStream in = new CharSequenceInputStream("A", (String) null)) {
355+
IOUtils.toByteArray(in);
356+
assertEquals(Charset.defaultCharset(), in.getCharsetEncoder().charset());
357+
}
358+
}
359+
360360
private void testReadZero(final String csName) throws Exception {
361361
try (InputStream r = new CharSequenceInputStream("test", csName)) {
362362
final byte[] bytes = new byte[30];

src/test/java/org/apache/commons/io/input/ReaderInputStreamTest.java

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -53,19 +53,6 @@ public class ReaderInputStreamTest {
5353
LARGE_TEST_STRING = buffer.toString();
5454
}
5555

56-
private final Random random = new Random();
57-
58-
@ParameterizedTest
59-
@MethodSource("charsetData")
60-
public void testCharsetEncoderFlush(final String charsetName, final String data) throws IOException {
61-
final Charset charset = Charset.forName(charsetName);
62-
final byte[] expected = data.getBytes(charset);
63-
try (InputStream in = new ReaderInputStream(new StringReader(data), charset)) {
64-
final byte[] actual = IOUtils.toByteArray(in);
65-
assertEquals(Arrays.toString(expected), Arrays.toString(actual));
66-
}
67-
}
68-
6956
static Stream<Arguments> charsetData() {
7057
// @formatter:off
7158
return Stream.of(
@@ -75,12 +62,7 @@ static Stream<Arguments> charsetData() {
7562
// @formatter:on
7663
}
7764

78-
@Test
79-
public void testBufferTooSmall() throws IOException {
80-
assertThrows(IllegalArgumentException.class, () -> new ReaderInputStream(new StringReader("\uD800"), StandardCharsets.UTF_8, -1));
81-
assertThrows(IllegalArgumentException.class, () -> new ReaderInputStream(new StringReader("\uD800"), StandardCharsets.UTF_8, 0));
82-
assertThrows(IllegalArgumentException.class, () -> new ReaderInputStream(new StringReader("\uD800"), StandardCharsets.UTF_8, 1));
83-
}
65+
private final Random random = new Random();
8466

8567
@Test
8668
@Timeout(value = 500, unit = TimeUnit.MILLISECONDS)
@@ -91,6 +73,24 @@ public void testBufferSmallest() throws IOException {
9173
}
9274
}
9375

76+
@Test
77+
public void testBufferTooSmall() throws IOException {
78+
assertThrows(IllegalArgumentException.class, () -> new ReaderInputStream(new StringReader("\uD800"), StandardCharsets.UTF_8, -1));
79+
assertThrows(IllegalArgumentException.class, () -> new ReaderInputStream(new StringReader("\uD800"), StandardCharsets.UTF_8, 0));
80+
assertThrows(IllegalArgumentException.class, () -> new ReaderInputStream(new StringReader("\uD800"), StandardCharsets.UTF_8, 1));
81+
}
82+
83+
@ParameterizedTest
84+
@MethodSource("charsetData")
85+
public void testCharsetEncoderFlush(final String charsetName, final String data) throws IOException {
86+
final Charset charset = Charset.forName(charsetName);
87+
final byte[] expected = data.getBytes(charset);
88+
try (InputStream in = new ReaderInputStream(new StringReader(data), charset)) {
89+
final byte[] actual = IOUtils.toByteArray(in);
90+
assertEquals(Arrays.toString(expected), Arrays.toString(actual));
91+
}
92+
}
93+
9494
/*
9595
* Tests https://issues.apache.org/jira/browse/IO-277
9696
*/
@@ -122,9 +122,9 @@ public void testCodingErrorAction() throws IOException {
122122

123123
@Test
124124
@Timeout(value = 500, unit = TimeUnit.MILLISECONDS)
125-
public void testConstructNullCharsetEncoder() throws IOException {
125+
public void testConstructNullCharset() throws IOException {
126126
final Charset charset = Charset.defaultCharset();
127-
final CharsetEncoder encoder = null;
127+
final Charset encoder = null;
128128
try (ReaderInputStream in = new ReaderInputStream(new StringReader("ABC"), encoder, (int) ReaderInputStream.minBufferSize(charset.newEncoder()))) {
129129
IOUtils.toByteArray(in);
130130
assertEquals(Charset.defaultCharset(), in.getCharsetEncoder().charset());
@@ -133,9 +133,9 @@ public void testConstructNullCharsetEncoder() throws IOException {
133133

134134
@Test
135135
@Timeout(value = 500, unit = TimeUnit.MILLISECONDS)
136-
public void testConstructNullCharset() throws IOException {
136+
public void testConstructNullCharsetEncoder() throws IOException {
137137
final Charset charset = Charset.defaultCharset();
138-
final Charset encoder = null;
138+
final CharsetEncoder encoder = null;
139139
try (ReaderInputStream in = new ReaderInputStream(new StringReader("ABC"), encoder, (int) ReaderInputStream.minBufferSize(charset.newEncoder()))) {
140140
IOUtils.toByteArray(in);
141141
assertEquals(Charset.defaultCharset(), in.getCharsetEncoder().charset());

src/test/java/org/apache/commons/io/output/BrokenOutputStreamTest.java

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -50,21 +50,6 @@ public void testFlush() {
5050
assertEquals(exception, assertThrows(IOException.class, () -> stream.flush()));
5151
}
5252

53-
@Test
54-
public void testWriteByteArray() {
55-
assertEquals(exception, assertThrows(IOException.class, () -> stream.write(new byte[1])));
56-
}
57-
58-
@Test
59-
public void testWriteByteArrayIndexed() {
60-
assertEquals(exception, assertThrows(IOException.class, () -> stream.write(new byte[1], 0, 1)));
61-
}
62-
63-
@Test
64-
public void testWriteInt() {
65-
assertEquals(exception, assertThrows(IOException.class, () -> stream.write(1)));
66-
}
67-
6853
@Test
6954
public void testTryWithResources() {
7055
final IOException thrown = assertThrows(IOException.class, () -> {
@@ -80,4 +65,19 @@ public void testTryWithResources() {
8065
assertEquals("Broken output stream", suppressed[0].getMessage());
8166
}
8267

68+
@Test
69+
public void testWriteByteArray() {
70+
assertEquals(exception, assertThrows(IOException.class, () -> stream.write(new byte[1])));
71+
}
72+
73+
@Test
74+
public void testWriteByteArrayIndexed() {
75+
assertEquals(exception, assertThrows(IOException.class, () -> stream.write(new byte[1], 0, 1)));
76+
}
77+
78+
@Test
79+
public void testWriteInt() {
80+
assertEquals(exception, assertThrows(IOException.class, () -> stream.write(1)));
81+
}
82+
8383
}

src/test/java/org/apache/commons/io/output/BrokenWriterTest.java

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,21 @@ public void testToString() {
8484
assertEquals(exception, assertThrows(IOException.class, () -> brokenWriter.toString()));
8585
}
8686

87+
@Test
88+
public void testTryWithResources() {
89+
final IOException thrown = assertThrows(IOException.class, () -> {
90+
try (Writer newWriter = new BrokenWriter()) {
91+
newWriter.write(1);
92+
}
93+
});
94+
assertEquals("Broken writer", thrown.getMessage());
95+
96+
final Throwable[] suppressed = thrown.getSuppressed();
97+
assertEquals(1, suppressed.length);
98+
assertEquals(IOException.class, suppressed[0].getClass());
99+
assertEquals("Broken writer", suppressed[0].getMessage());
100+
}
101+
87102
@Test
88103
public void testWriteCharArray() {
89104
assertEquals(exception, assertThrows(IOException.class, () -> brokenWriter.write(new char[1])));
@@ -109,19 +124,4 @@ public void testWriteStringIndexed() {
109124
assertEquals(exception, assertThrows(IOException.class, () -> brokenWriter.write("01", 0, 1)));
110125
}
111126

112-
@Test
113-
public void testTryWithResources() {
114-
final IOException thrown = assertThrows(IOException.class, () -> {
115-
try (Writer newWriter = new BrokenWriter()) {
116-
newWriter.write(1);
117-
}
118-
});
119-
assertEquals("Broken writer", thrown.getMessage());
120-
121-
final Throwable[] suppressed = thrown.getSuppressed();
122-
assertEquals(1, suppressed.length);
123-
assertEquals(IOException.class, suppressed[0].getClass());
124-
assertEquals("Broken writer", suppressed[0].getMessage());
125-
}
126-
127127
}

0 commit comments

Comments
 (0)