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 2021/10/02 15:59:42 UTC
[commons-io] branch master updated: Checkstyle and fix test sources.
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
The following commit(s) were added to refs/heads/master by this push:
new c819ca0 Checkstyle and fix test sources.
c819ca0 is described below
commit c819ca0c3fcdbb6641faca23b7920d1a5bfb917d
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sat Oct 2 11:17:01 2021 -0400
Checkstyle and fix test sources.
- Move Checkstyle configuration from root folder to src/conf.
- Remove unused imports.
- Remove trailing whitespace.
- Adjust line lengths.
- No tabs.
- Use final.
---
pom.xml | 4 +-
src/conf/checkstyle-suppressions.xml | 28 ++++
checkstyle.xml => src/conf/checkstyle.xml | 37 +++--
.../commons/io/input/ReadAheadInputStream.java | 2 +-
.../apache/commons/io/FileCleaningTrackerTest.java | 10 +-
.../apache/commons/io/FileDeleteStrategyTest.java | 1 -
.../org/apache/commons/io/FileSystemUtilsTest.java | 1 -
.../io/FileUtilsDeleteDirectoryLinuxTest.java | 167 ++++++++++-----------
.../org/apache/commons/io/FilenameUtilsTest.java | 44 +++---
.../java/org/apache/commons/io/IOCaseTest.java | 2 -
.../java/org/apache/commons/io/IOUtilsTest.java | 10 +-
.../org/apache/commons/io/ThreadMonitorTest.java | 2 +-
.../commons/io/file/PathUtilsDeleteFileTest.java | 7 -
.../org/apache/commons/io/file/PathUtilsTest.java | 1 -
.../commons/io/filefilter/RegexFileFilterTest.java | 3 +-
.../io/filefilter/WildcardFileFilterTest.java | 2 -
.../commons/io/input/BrokenInputStreamTest.java | 2 +
.../apache/commons/io/input/BrokenReaderTest.java | 2 +
.../commons/io/input/ByteBufferCleanerTest.java | 22 +--
.../commons/io/input/ReaderInputStreamTest.java | 6 +-
.../ReversedLinesFileReaderTestParamBlockSize.java | 3 +-
.../org/apache/commons/io/input/TailerTest.java | 1 -
.../io/input/UnixLineEndingInputStreamTest.java | 46 +++---
.../buffer/CircularBufferInputStreamTest.java | 133 ++++++++--------
.../commons/io/output/BrokenOutputStreamTest.java | 2 +
.../apache/commons/io/output/BrokenWriterTest.java | 2 +
.../io/output/ByteArrayOutputStreamTest.java | 40 ++---
.../commons/io/output/LockableFileWriterTest.java | 3 -
28 files changed, 290 insertions(+), 293 deletions(-)
diff --git a/pom.xml b/pom.xml
index 9f3975b..75684ff 100644
--- a/pom.xml
+++ b/pom.xml
@@ -372,8 +372,10 @@ file comparators, endian transformation classes, and much more.
<artifactId>maven-checkstyle-plugin</artifactId>
<version>${checkstyle.plugin.version}</version>
<configuration>
- <configLocation>${basedir}/checkstyle.xml</configLocation>
+ <configLocation>${basedir}/src/conf/checkstyle.xml</configLocation>
+ <suppressionsLocation>${basedir}/src/conf/checkstyle-suppressions.xml</suppressionsLocation>
<enableRulesSummary>false</enableRulesSummary>
+ <includeTestSourceDirectory>true</includeTestSourceDirectory>
</configuration>
<dependencies>
<dependency>
diff --git a/src/conf/checkstyle-suppressions.xml b/src/conf/checkstyle-suppressions.xml
new file mode 100644
index 0000000..14a483b
--- /dev/null
+++ b/src/conf/checkstyle-suppressions.xml
@@ -0,0 +1,28 @@
+<?xml version="1.0"?>
+<!DOCTYPE suppressions PUBLIC
+ "-//Checkstyle//DTD SuppressionFilter Configuration 1.2//EN"
+ "https://checkstyle.org/dtds/suppressions_1_2.dtd">
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<suppressions>
+ <!-- Suppress test Javadoc checks-->
+ <suppress checks="JavadocMethod" files="src[/\\]test[/\\]java[/\\]" />
+ <suppress checks="JavadocPackage" files="src[/\\]test[/\\]java[/\\]" />
+ <!-- Suppress generated-test-sources checks-->
+ <suppress checks=".*" files="target[/\\]generated-test-sources[/\\]" />
+</suppressions>
diff --git a/checkstyle.xml b/src/conf/checkstyle.xml
similarity index 63%
rename from checkstyle.xml
rename to src/conf/checkstyle.xml
index 55c7fa1..bbc848f 100644
--- a/checkstyle.xml
+++ b/src/conf/checkstyle.xml
@@ -18,32 +18,31 @@ limitations under the License.
<!DOCTYPE module PUBLIC
"-//Checkstyle//DTD Checkstyle Configuration 1.2//EN"
"https://checkstyle.org/dtds/configuration_1_2.dtd">
-<!-- commons lang customization of default Checkstyle behavior -->
<module name="Checker">
- <property name="localeLanguage" value="en"/>
+ <property name="localeLanguage" value="en" />
<module name="JavadocPackage">
<!-- setting allowLegacy means it will check for package.html instead of just package-info.java -->
- <property name="allowLegacy" value="true"/>
+ <property name="allowLegacy" value="true" />
</module>
<module name="FileTabCharacter">
- <property name="fileExtensions" value="java,xml"/>
+ <property name="fileExtensions" value="java,xml" />
</module>
<module name="LineLength">
- <property name="max" value="160"/>
+ <property name="max" value="160" />
</module>
<module name="TreeWalker">
- <module name="AvoidStarImport"/>
- <module name="RedundantImport"/>
- <module name="UnusedImports"/>
- <module name="NeedBraces"/>
- <module name="LeftCurly"/>
- <module name="JavadocMethod">
- </module>
- <!-- No Trailing whitespace -->
- <module name="Regexp">
- <property name="format" value="[ \t]+$"/>
- <property name="illegalPattern" value="true"/>
- <property name="message" value="Trailing whitespace"/>
- </module>
- </module>
+ <module name="AvoidStarImport" />
+ <module name="RedundantImport" />
+ <module name="UnusedImports" />
+ <module name="NeedBraces" />
+ <module name="LeftCurly" />
+ <module name="JavadocMethod" />
+ <module name="FinalLocalVariable" />
+ <!-- No Trailing whitespace -->
+ <module name="Regexp">
+ <property name="format" value="[ \t]+$" />
+ <property name="illegalPattern" value="true" />
+ <property name="message" value="Trailing whitespace" />
+ </module>
+ </module>
</module>
diff --git a/src/main/java/org/apache/commons/io/input/ReadAheadInputStream.java b/src/main/java/org/apache/commons/io/input/ReadAheadInputStream.java
index 415902c..d1cddd8 100644
--- a/src/main/java/org/apache/commons/io/input/ReadAheadInputStream.java
+++ b/src/main/java/org/apache/commons/io/input/ReadAheadInputStream.java
@@ -383,7 +383,7 @@ public class ReadAheadInputStream extends InputStream {
return n;
}
stateChangeLock.lock();
- long skipped;
+ final long skipped;
try {
skipped = skipInternal(n);
} finally {
diff --git a/src/test/java/org/apache/commons/io/FileCleaningTrackerTest.java b/src/test/java/org/apache/commons/io/FileCleaningTrackerTest.java
index 1e46d64..30d3757 100644
--- a/src/test/java/org/apache/commons/io/FileCleaningTrackerTest.java
+++ b/src/test/java/org/apache/commons/io/FileCleaningTrackerTest.java
@@ -21,7 +21,6 @@ import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
-import static org.junit.jupiter.api.Assertions.fail;
import java.io.BufferedOutputStream;
import java.io.File;
@@ -33,7 +32,6 @@ import java.nio.file.Files;
import java.util.ArrayList;
import java.util.List;
-import org.apache.commons.io.filefilter.PrefixFileFilter;
import org.apache.commons.io.test.TestUtils;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
@@ -185,7 +183,7 @@ public class FileCleaningTrackerTest {
final String path = testFile.getPath();
final Object marker = new Object();
-
+
assertThrows(IllegalStateException.class, () -> theInstance.track(path, marker));
assertTrue(theInstance.exitWhenFinished);
assertNull(theInstance.reaper);
@@ -306,12 +304,14 @@ public class FileCleaningTrackerTest {
System.gc();
TestUtils.sleep(500);
int count = 0;
- while(theInstance.getTrackCount() != 0 && count++ < 5) {
+ while (theInstance.getTrackCount() != 0 && count++ < 5) {
List<String> list = new ArrayList<>();
try {
long i = 0;
while (theInstance.getTrackCount() != 0) {
- list.add("A Big String A Big String A Big String A Big String A Big String A Big String A Big String A Big String A Big String A Big String " + (i++));
+ list.add(
+ "A Big String A Big String A Big String A Big String A Big String A Big String A Big String A Big String A Big String A Big String "
+ + (i++));
}
} catch (final Throwable ignored) {
}
diff --git a/src/test/java/org/apache/commons/io/FileDeleteStrategyTest.java b/src/test/java/org/apache/commons/io/FileDeleteStrategyTest.java
index ecaf323..db4dd9c 100644
--- a/src/test/java/org/apache/commons/io/FileDeleteStrategyTest.java
+++ b/src/test/java/org/apache/commons/io/FileDeleteStrategyTest.java
@@ -20,7 +20,6 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
-import static org.junit.jupiter.api.Assertions.fail;
import java.io.BufferedOutputStream;
import java.io.File;
diff --git a/src/test/java/org/apache/commons/io/FileSystemUtilsTest.java b/src/test/java/org/apache/commons/io/FileSystemUtilsTest.java
index 0aa0374..8a9d620 100644
--- a/src/test/java/org/apache/commons/io/FileSystemUtilsTest.java
+++ b/src/test/java/org/apache/commons/io/FileSystemUtilsTest.java
@@ -19,7 +19,6 @@ package org.apache.commons.io;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
-import static org.junit.jupiter.api.Assertions.fail;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
diff --git a/src/test/java/org/apache/commons/io/FileUtilsDeleteDirectoryLinuxTest.java b/src/test/java/org/apache/commons/io/FileUtilsDeleteDirectoryLinuxTest.java
index 0736fdc..26fb270 100644
--- a/src/test/java/org/apache/commons/io/FileUtilsDeleteDirectoryLinuxTest.java
+++ b/src/test/java/org/apache/commons/io/FileUtilsDeleteDirectoryLinuxTest.java
@@ -33,88 +33,87 @@ import org.junit.jupiter.api.condition.OS;
@DisabledOnOs({OS.WINDOWS, OS.MAC})
public class FileUtilsDeleteDirectoryLinuxTest extends FileUtilsDeleteDirectoryBaseTest {
- /** Only runs on Linux. */
- private boolean chmod(final File file, final int mode, final boolean recurse) throws InterruptedException {
- final List<String> args = new ArrayList<>();
- args.add("chmod");
-
- if (recurse) {
- args.add("-R");
- }
-
- args.add(Integer.toString(mode));
- args.add(file.getAbsolutePath());
-
- final Process proc;
-
- try {
- proc = Runtime.getRuntime().exec(args.toArray(new String[args.size()]));
- } catch (final IOException e) {
- return false;
- }
- return proc.waitFor() == 0;
- }
-
- @Override
- protected boolean setupSymlink(final File res, final File link) throws Exception {
- // create symlink
- final List<String> args = new ArrayList<>();
- args.add("ln");
- args.add("-s");
-
- args.add(res.getAbsolutePath());
- args.add(link.getAbsolutePath());
-
- final Process proc;
-
- proc = Runtime.getRuntime().exec(args.toArray(new String[args.size()]));
- return proc.waitFor() == 0;
- }
-
- @Test
- public void testThrowsOnCannotDeleteFile() throws Exception {
- final File nested = new File(top, "nested");
- assertTrue(nested.mkdirs());
-
- final File file = new File(nested, "restricted");
- FileUtils.touch(file);
-
- assumeTrue(chmod(nested, 500, false));
-
- try {
- // deleteDirectory calls forceDelete
- FileUtils.deleteDirectory(nested);
- fail("expected IOException");
- } catch (final IOException e) {
- final IOExceptionList list = (IOExceptionList) e;
- assertEquals("Cannot delete file: " + file.getAbsolutePath(), list.getCause(0).getMessage());
- } finally {
- chmod(nested, 755, false);
- FileUtils.deleteDirectory(nested);
- }
- assertEquals(0, top.list().length);
- }
-
- @Test
- public void testThrowsOnNullList() throws Exception {
- final File nested = new File(top, "nested");
- assertTrue(nested.mkdirs());
-
- // test wont work if we can't restrict permissions on the
- // directory, so skip it.
- assumeTrue(chmod(nested, 0, false));
-
- try {
- // cleanDirectory calls forceDelete
- FileUtils.deleteDirectory(nested);
- fail("expected IOException");
- } catch (final IOException e) {
- assertEquals("Unknown I/O error listing contents of directory: " + nested.getAbsolutePath(),
- e.getMessage());
- } finally {
- chmod(nested, 755, false);
- FileUtils.deleteDirectory(nested);
- }
- assertEquals(0, top.list().length);
- }
+ /** Only runs on Linux. */
+ private boolean chmod(final File file, final int mode, final boolean recurse) throws InterruptedException {
+ final List<String> args = new ArrayList<>();
+ args.add("chmod");
+
+ if (recurse) {
+ args.add("-R");
+ }
+
+ args.add(Integer.toString(mode));
+ args.add(file.getAbsolutePath());
+
+ final Process proc;
+
+ try {
+ proc = Runtime.getRuntime().exec(args.toArray(new String[args.size()]));
+ } catch (final IOException e) {
+ return false;
+ }
+ return proc.waitFor() == 0;
+ }
+
+ @Override
+ protected boolean setupSymlink(final File res, final File link) throws Exception {
+ // create symlink
+ final List<String> args = new ArrayList<>();
+ args.add("ln");
+ args.add("-s");
+
+ args.add(res.getAbsolutePath());
+ args.add(link.getAbsolutePath());
+
+ final Process proc;
+
+ proc = Runtime.getRuntime().exec(args.toArray(new String[args.size()]));
+ return proc.waitFor() == 0;
+ }
+
+ @Test
+ public void testThrowsOnCannotDeleteFile() throws Exception {
+ final File nested = new File(top, "nested");
+ assertTrue(nested.mkdirs());
+
+ final File file = new File(nested, "restricted");
+ FileUtils.touch(file);
+
+ assumeTrue(chmod(nested, 500, false));
+
+ try {
+ // deleteDirectory calls forceDelete
+ FileUtils.deleteDirectory(nested);
+ fail("expected IOException");
+ } catch (final IOException e) {
+ final IOExceptionList list = (IOExceptionList) e;
+ assertEquals("Cannot delete file: " + file.getAbsolutePath(), list.getCause(0).getMessage());
+ } finally {
+ chmod(nested, 755, false);
+ FileUtils.deleteDirectory(nested);
+ }
+ assertEquals(0, top.list().length);
+ }
+
+ @Test
+ public void testThrowsOnNullList() throws Exception {
+ final File nested = new File(top, "nested");
+ assertTrue(nested.mkdirs());
+
+ // test wont work if we can't restrict permissions on the
+ // directory, so skip it.
+ assumeTrue(chmod(nested, 0, false));
+
+ try {
+ // cleanDirectory calls forceDelete
+ FileUtils.deleteDirectory(nested);
+ fail("expected IOException");
+ } catch (final IOException e) {
+ assertEquals("Unknown I/O error listing contents of directory: " + nested.getAbsolutePath(), e.getMessage());
+ } finally {
+ chmod(nested, 755, false);
+ FileUtils.deleteDirectory(nested);
+ }
+ assertEquals(0, top.list().length);
+ }
}
diff --git a/src/test/java/org/apache/commons/io/FilenameUtilsTest.java b/src/test/java/org/apache/commons/io/FilenameUtilsTest.java
index 670cc77..ef16996 100644
--- a/src/test/java/org/apache/commons/io/FilenameUtilsTest.java
+++ b/src/test/java/org/apache/commons/io/FilenameUtilsTest.java
@@ -255,15 +255,15 @@ public class FilenameUtilsTest {
if (FilenameUtils.isSystemWindows()) {
// Special case handling for NTFS ADS names
- try {
- FilenameUtils.getExtension("foo.exe:bar.txt");
- throw new AssertionError("Expected Exception");
- } catch (final IllegalArgumentException e) {
- assertEquals("NTFS ADS separator (':') in file name is forbidden.", e.getMessage());
- }
+ try {
+ FilenameUtils.getExtension("foo.exe:bar.txt");
+ throw new AssertionError("Expected Exception");
+ } catch (final IllegalArgumentException e) {
+ assertEquals("NTFS ADS separator (':') in file name is forbidden.", e.getMessage());
+ }
} else {
- // Upwards compatibility:
- assertEquals("txt", FilenameUtils.getExtension("foo.exe:bar.txt"));
+ // Upwards compatibility:
+ assertEquals("txt", FilenameUtils.getExtension("foo.exe:bar.txt"));
}
}
@@ -599,15 +599,15 @@ public class FilenameUtilsTest {
if (FilenameUtils.isSystemWindows()) {
// Special case handling for NTFS ADS names
- try {
- FilenameUtils.indexOfExtension("foo.exe:bar.txt");
- throw new AssertionError("Expected Exception");
- } catch (final IllegalArgumentException e) {
- assertEquals("NTFS ADS separator (':') in file name is forbidden.", e.getMessage());
- }
+ try {
+ FilenameUtils.indexOfExtension("foo.exe:bar.txt");
+ throw new AssertionError("Expected Exception");
+ } catch (final IllegalArgumentException e) {
+ assertEquals("NTFS ADS separator (':') in file name is forbidden.", e.getMessage());
+ }
} else {
- // Upwards compatibility on other systems
- assertEquals(11, FilenameUtils.indexOfExtension("foo.exe:bar.txt"));
+ // Upwards compatibility on other systems
+ assertEquals(11, FilenameUtils.indexOfExtension("foo.exe:bar.txt"));
}
}
@@ -929,16 +929,14 @@ public class FilenameUtilsTest {
assertEquals(SEP + SEP + "::1" + SEP + "a" + SEP + "b" + SEP + "c.txt", FilenameUtils.normalize("\\\\::1\\a\\b\\c.txt"));
assertEquals(SEP + SEP + "1::" + SEP + "a" + SEP + "b" + SEP + "c.txt", FilenameUtils.normalize("\\\\1::\\a\\b\\c.txt"));
assertEquals(SEP + SEP + "server.example.org" + SEP + "a" + SEP + "b" + SEP + "c.txt", FilenameUtils.normalize("\\\\server.example.org\\a\\b\\c.txt"));
- assertEquals(SEP + SEP + "server.sub.example.org" + SEP + "a" + SEP + "b" + SEP + "c.txt", FilenameUtils.normalize("\\\\server.sub.example.org\\a\\b\\c.txt"));
+ assertEquals(SEP + SEP + "server.sub.example.org" + SEP + "a" + SEP + "b" + SEP + "c.txt",
+ FilenameUtils.normalize("\\\\server.sub.example.org\\a\\b\\c.txt"));
assertEquals(SEP + SEP + "server." + SEP + "a" + SEP + "b" + SEP + "c.txt", FilenameUtils.normalize("\\\\server.\\a\\b\\c.txt"));
- assertEquals(SEP + SEP + "1::127.0.0.1" + SEP + "a" + SEP + "b" + SEP + "c.txt",
- FilenameUtils.normalize("\\\\1::127.0.0.1\\a\\b\\c.txt"));
+ assertEquals(SEP + SEP + "1::127.0.0.1" + SEP + "a" + SEP + "b" + SEP + "c.txt", FilenameUtils.normalize("\\\\1::127.0.0.1\\a\\b\\c.txt"));
// not valid IPv4 addresses but technically a valid "reg-name"s according to RFC1034
- assertEquals(SEP + SEP + "127.0.0.256" + SEP + "a" + SEP + "b" + SEP + "c.txt",
- FilenameUtils.normalize("\\\\127.0.0.256\\a\\b\\c.txt"));
- assertEquals(SEP + SEP + "127.0.0.01" + SEP + "a" + SEP + "b" + SEP + "c.txt",
- FilenameUtils.normalize("\\\\127.0.0.01\\a\\b\\c.txt"));
+ assertEquals(SEP + SEP + "127.0.0.256" + SEP + "a" + SEP + "b" + SEP + "c.txt", FilenameUtils.normalize("\\\\127.0.0.256\\a\\b\\c.txt"));
+ assertEquals(SEP + SEP + "127.0.0.01" + SEP + "a" + SEP + "b" + SEP + "c.txt", FilenameUtils.normalize("\\\\127.0.0.01\\a\\b\\c.txt"));
assertNull(FilenameUtils.normalize("\\\\-server\\a\\b\\c.txt"));
assertNull(FilenameUtils.normalize("\\\\.\\a\\b\\c.txt"));
diff --git a/src/test/java/org/apache/commons/io/IOCaseTest.java b/src/test/java/org/apache/commons/io/IOCaseTest.java
index 0193eca..ebf9b60 100644
--- a/src/test/java/org/apache/commons/io/IOCaseTest.java
+++ b/src/test/java/org/apache/commons/io/IOCaseTest.java
@@ -21,12 +21,10 @@ import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
-import static org.junit.jupiter.api.Assertions.fail;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
-import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
diff --git a/src/test/java/org/apache/commons/io/IOUtilsTest.java b/src/test/java/org/apache/commons/io/IOUtilsTest.java
index ed08f27..838d17d 100644
--- a/src/test/java/org/apache/commons/io/IOUtilsTest.java
+++ b/src/test/java/org/apache/commons/io/IOUtilsTest.java
@@ -644,7 +644,7 @@ public class IOUtilsTest {
@Test
public void testCopy_ByteArray_OutputStream() throws Exception {
final File destination = TestUtils.newFile(temporaryFolder, "copy8.txt");
- byte[] in;
+ final byte[] in;
try (InputStream fin = Files.newInputStream(testFilePath)) {
// Create our byte[]. Rely on testInputStreamToByteArray() to make sure this is valid.
in = IOUtils.toByteArray(fin);
@@ -664,7 +664,7 @@ public class IOUtilsTest {
@Test
public void testCopy_ByteArray_Writer() throws Exception {
final File destination = TestUtils.newFile(temporaryFolder, "copy7.txt");
- byte[] in;
+ final byte[] in;
try (InputStream fin = Files.newInputStream(testFilePath)) {
// Create our byte[]. Rely on testInputStreamToByteArray() to make sure this is valid.
in = IOUtils.toByteArray(fin);
@@ -682,7 +682,7 @@ public class IOUtilsTest {
@Test
public void testCopy_String_Writer() throws Exception {
final File destination = TestUtils.newFile(temporaryFolder, "copy6.txt");
- String str;
+ final String str;
try (Reader fin = Files.newBufferedReader(testFilePath)) {
// Create our String. Rely on testReaderToString() to make sure this is valid.
str = IOUtils.toString(fin);
@@ -1386,7 +1386,7 @@ public class IOUtilsTest {
@Test
public void testStringToOutputStream() throws Exception {
final File destination = TestUtils.newFile(temporaryFolder, "copy5.txt");
- String str;
+ final String str;
try (Reader fin = Files.newBufferedReader(testFilePath)) {
// Create our String. Rely on testReaderToString() to make sure this is valid.
str = IOUtils.toString(fin);
@@ -1557,7 +1557,7 @@ public class IOUtilsTest {
@Test
public void testToByteArray_URLConnection() throws Exception {
final URLConnection urlConn = testFile.toURI().toURL().openConnection();
- byte[] actual;
+ final byte[] actual;
try {
actual = IOUtils.toByteArray(urlConn);
} finally {
diff --git a/src/test/java/org/apache/commons/io/ThreadMonitorTest.java b/src/test/java/org/apache/commons/io/ThreadMonitorTest.java
index 997d8d9..064a43f 100644
--- a/src/test/java/org/apache/commons/io/ThreadMonitorTest.java
+++ b/src/test/java/org/apache/commons/io/ThreadMonitorTest.java
@@ -17,8 +17,8 @@
package org.apache.commons.io;
import static org.junit.jupiter.api.Assertions.assertNull;
-import static org.junit.jupiter.api.Assertions.fail;
import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.fail;
import java.time.Duration;
diff --git a/src/test/java/org/apache/commons/io/file/PathUtilsDeleteFileTest.java b/src/test/java/org/apache/commons/io/file/PathUtilsDeleteFileTest.java
index 0101291..6383f64 100644
--- a/src/test/java/org/apache/commons/io/file/PathUtilsDeleteFileTest.java
+++ b/src/test/java/org/apache/commons/io/file/PathUtilsDeleteFileTest.java
@@ -18,24 +18,17 @@
package org.apache.commons.io.file;
import static org.apache.commons.io.file.CounterAssertions.assertCounts;
-import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assumptions.assumeFalse;
-import static org.junit.jupiter.api.Assumptions.assumeTrue;
import java.io.IOException;
-import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.LinkOption;
import java.nio.file.NoSuchFileException;
import java.nio.file.Path;
import java.nio.file.Paths;
-import java.nio.file.attribute.DosFileAttributeView;
-import java.nio.file.attribute.PosixFileAttributeView;
-import java.nio.file.attribute.PosixFilePermission;
-import java.util.Set;
import org.apache.commons.io.file.Counters.PathCounters;
import org.apache.commons.lang3.SystemUtils;
diff --git a/src/test/java/org/apache/commons/io/file/PathUtilsTest.java b/src/test/java/org/apache/commons/io/file/PathUtilsTest.java
index 6e9f3dc..9103273 100644
--- a/src/test/java/org/apache/commons/io/file/PathUtilsTest.java
+++ b/src/test/java/org/apache/commons/io/file/PathUtilsTest.java
@@ -324,5 +324,4 @@ public class PathUtilsTest extends TestArguments {
return file;
}
-
}
diff --git a/src/test/java/org/apache/commons/io/filefilter/RegexFileFilterTest.java b/src/test/java/org/apache/commons/io/filefilter/RegexFileFilterTest.java
index 95883a4..17d0870 100644
--- a/src/test/java/org/apache/commons/io/filefilter/RegexFileFilterTest.java
+++ b/src/test/java/org/apache/commons/io/filefilter/RegexFileFilterTest.java
@@ -16,9 +16,8 @@
*/
package org.apache.commons.io.filefilter;
-import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.fail;
+import static org.junit.jupiter.api.Assertions.assertThrows;
import java.io.File;
import java.nio.file.FileVisitResult;
diff --git a/src/test/java/org/apache/commons/io/filefilter/WildcardFileFilterTest.java b/src/test/java/org/apache/commons/io/filefilter/WildcardFileFilterTest.java
index 74efea0..3d855ae 100644
--- a/src/test/java/org/apache/commons/io/filefilter/WildcardFileFilterTest.java
+++ b/src/test/java/org/apache/commons/io/filefilter/WildcardFileFilterTest.java
@@ -21,13 +21,11 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
-import static org.junit.jupiter.api.Assertions.fail;
import java.io.File;
import java.nio.file.FileVisitResult;
import java.nio.file.Path;
import java.util.Arrays;
-import java.util.Collections;
import java.util.List;
import org.apache.commons.io.IOCase;
diff --git a/src/test/java/org/apache/commons/io/input/BrokenInputStreamTest.java b/src/test/java/org/apache/commons/io/input/BrokenInputStreamTest.java
index 9fe8658..82ad3f5 100644
--- a/src/test/java/org/apache/commons/io/input/BrokenInputStreamTest.java
+++ b/src/test/java/org/apache/commons/io/input/BrokenInputStreamTest.java
@@ -18,8 +18,10 @@ package org.apache.commons.io.input;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
+
import java.io.IOException;
import java.io.InputStream;
+
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
diff --git a/src/test/java/org/apache/commons/io/input/BrokenReaderTest.java b/src/test/java/org/apache/commons/io/input/BrokenReaderTest.java
index 10f078b..0bd9751 100644
--- a/src/test/java/org/apache/commons/io/input/BrokenReaderTest.java
+++ b/src/test/java/org/apache/commons/io/input/BrokenReaderTest.java
@@ -19,8 +19,10 @@ package org.apache.commons.io.input;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
+
import java.io.IOException;
import java.io.Reader;
+
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
diff --git a/src/test/java/org/apache/commons/io/input/ByteBufferCleanerTest.java b/src/test/java/org/apache/commons/io/input/ByteBufferCleanerTest.java
index be639a5..c09d155 100644
--- a/src/test/java/org/apache/commons/io/input/ByteBufferCleanerTest.java
+++ b/src/test/java/org/apache/commons/io/input/ByteBufferCleanerTest.java
@@ -16,7 +16,7 @@
*/
package org.apache.commons.io.input;
-import static org.junit.jupiter.api.Assertions.*;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.nio.ByteBuffer;
@@ -30,19 +30,19 @@ public class ByteBufferCleanerTest {
@Test
void testCleanEmpty() {
- ByteBuffer buffer = ByteBuffer.allocateDirect(10);
- // There is no way verify that the buffer has been cleaned up, we are just verifying that
- // clean() doesn't blow up
- ByteBufferCleaner.clean(buffer);
+ final ByteBuffer buffer = ByteBuffer.allocateDirect(10);
+ // There is no way verify that the buffer has been cleaned up, we are just verifying that
+ // clean() doesn't blow up
+ ByteBufferCleaner.clean(buffer);
}
-
+
@Test
void testCleanFull() {
- ByteBuffer buffer = ByteBuffer.allocateDirect(10);
- buffer.put(RandomUtils.nextBytes(10), 0, 10);
- // There is no way verify that the buffer has been cleaned up, we are just verifying that
- // clean() doesn't blow up
- ByteBufferCleaner.clean(buffer);
+ final ByteBuffer buffer = ByteBuffer.allocateDirect(10);
+ buffer.put(RandomUtils.nextBytes(10), 0, 10);
+ // There is no way verify that the buffer has been cleaned up, we are just verifying that
+ // clean() doesn't blow up
+ ByteBufferCleaner.clean(buffer);
}
@Test
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 adabf8b..b5bf245 100644
--- a/src/test/java/org/apache/commons/io/input/ReaderInputStreamTest.java
+++ b/src/test/java/org/apache/commons/io/input/ReaderInputStreamTest.java
@@ -56,7 +56,7 @@ public class ReaderInputStreamTest {
assertThrows(IllegalArgumentException.class, () -> new ReaderInputStream(new StringReader("\uD800"), StandardCharsets.UTF_8, 0));
assertThrows(IllegalArgumentException.class, () -> new ReaderInputStream(new StringReader("\uD800"), StandardCharsets.UTF_8, 1));
}
-
+
@Test
@Timeout(value = 500, unit = TimeUnit.MILLISECONDS)
public void testBufferSmallest() throws IOException {
@@ -65,7 +65,7 @@ public class ReaderInputStreamTest {
in.read();
}
}
-
+
/*
* Tests https://issues.apache.org/jira/browse/IO-277
*/
@@ -89,7 +89,7 @@ public class ReaderInputStreamTest {
@Timeout(value = 500, unit = TimeUnit.MILLISECONDS)
public void testCodingErrorAction() throws IOException {
final Charset charset = StandardCharsets.UTF_8;
- CharsetEncoder encoder = charset.newEncoder().onMalformedInput(CodingErrorAction.REPORT);
+ final CharsetEncoder encoder = charset.newEncoder().onMalformedInput(CodingErrorAction.REPORT);
try (InputStream in = new ReaderInputStream(new StringReader("\uD800aa"), encoder, (int) ReaderInputStream.minBufferSize(charset.newEncoder()))) {
assertThrows(CharacterCodingException.class, in::read);
}
diff --git a/src/test/java/org/apache/commons/io/input/ReversedLinesFileReaderTestParamBlockSize.java b/src/test/java/org/apache/commons/io/input/ReversedLinesFileReaderTestParamBlockSize.java
index 6d5e212..fd302fc 100644
--- a/src/test/java/org/apache/commons/io/input/ReversedLinesFileReaderTestParamBlockSize.java
+++ b/src/test/java/org/apache/commons/io/input/ReversedLinesFileReaderTestParamBlockSize.java
@@ -41,7 +41,8 @@ public class ReversedLinesFileReaderTestParamBlockSize {
private static final String ISO_8859_1 = "ISO-8859-1";
// "A Test Line. Special chars: ÄäÜüÖöß ÃáéÃïçñ ©µ¥£±²®"
- private static final String TEST_LINE = "A Test Line. Special chars: \u00C4\u00E4\u00DC\u00FC\u00D6\u00F6\u00DF \u00C3\u00E1\u00E9\u00ED\u00EF\u00E7\u00F1\u00C2 \u00A9\u00B5\u00A5\u00A3\u00B1\u00B2\u00AE";
+ private static final String TEST_LINE = "A Test Line. Special chars: "
+ + "\u00C4\u00E4\u00DC\u00FC\u00D6\u00F6\u00DF \u00C3\u00E1\u00E9\u00ED\u00EF\u00E7\u00F1\u00C2 \u00A9\u00B5\u00A5\u00A3\u00B1\u00B2\u00AE";
// Hiragana letters: �����
private static final String TEST_LINE_SHIFT_JIS1 = "Hiragana letters: \u3041\u3042\u3043\u3044\u3045";
diff --git a/src/test/java/org/apache/commons/io/input/TailerTest.java b/src/test/java/org/apache/commons/io/input/TailerTest.java
index c4b662f..6c2f825 100644
--- a/src/test/java/org/apache/commons/io/input/TailerTest.java
+++ b/src/test/java/org/apache/commons/io/input/TailerTest.java
@@ -50,7 +50,6 @@ import org.apache.commons.io.IOUtils;
import org.apache.commons.io.RandomAccessFileMode;
import org.apache.commons.io.TestResources;
import org.apache.commons.io.test.TestUtils;
-import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
diff --git a/src/test/java/org/apache/commons/io/input/UnixLineEndingInputStreamTest.java b/src/test/java/org/apache/commons/io/input/UnixLineEndingInputStreamTest.java
index adfecf1..32a1aa4 100644
--- a/src/test/java/org/apache/commons/io/input/UnixLineEndingInputStreamTest.java
+++ b/src/test/java/org/apache/commons/io/input/UnixLineEndingInputStreamTest.java
@@ -24,66 +24,60 @@ import java.nio.charset.StandardCharsets;
import org.junit.jupiter.api.Test;
-public class UnixLineEndingInputStreamTest
-{
+public class UnixLineEndingInputStreamTest {
@Test
public void crAtEnd() throws Exception {
- assertEquals( "a\n", roundtrip( "a\r" ) );
+ assertEquals("a\n", roundtrip("a\r"));
}
@Test
- public void crOnlyEnsureAtEof()
- throws Exception
- {
- assertEquals( "a\nb\n", roundtrip( "a\rb" ) );
+ public void crOnlyEnsureAtEof() throws Exception {
+ assertEquals("a\nb\n", roundtrip("a\rb"));
}
@Test
- public void crOnlyNotAtEof()
- throws Exception
- {
- assertEquals( "a\nb", roundtrip( "a\rb", false ) );
+ public void crOnlyNotAtEof() throws Exception {
+ assertEquals("a\nb", roundtrip("a\rb", false));
}
@Test
public void inTheMiddleOfTheLine() throws Exception {
- assertEquals( "a\nbc\n", roundtrip( "a\r\nbc" ) );
+ assertEquals("a\nbc\n", roundtrip("a\r\nbc"));
}
@Test
public void multipleBlankLines() throws Exception {
- assertEquals( "a\n\nbc\n", roundtrip( "a\r\n\r\nbc" ) );
+ assertEquals("a\n\nbc\n", roundtrip("a\r\n\r\nbc"));
}
@Test
public void retainLineFeed() throws Exception {
- assertEquals( "a\n\n", roundtrip( "a\r\n\r\n", false ) );
- assertEquals( "a", roundtrip( "a", false ) );
+ assertEquals("a\n\n", roundtrip("a\r\n\r\n", false));
+ assertEquals("a", roundtrip("a", false));
}
- private String roundtrip( final String msg ) throws IOException {
- return roundtrip( msg, true );
+ private String roundtrip(final String msg) throws IOException {
+ return roundtrip(msg, true);
}
-
- private String roundtrip( final String msg, final boolean ensure ) throws IOException {
- final ByteArrayInputStream baos = new ByteArrayInputStream( msg.getBytes(StandardCharsets.UTF_8) );
- final UnixLineEndingInputStream lf = new UnixLineEndingInputStream( baos, ensure );
+ private String roundtrip(final String msg, final boolean ensure) throws IOException {
+ final ByteArrayInputStream baos = new ByteArrayInputStream(msg.getBytes(StandardCharsets.UTF_8));
+ final UnixLineEndingInputStream lf = new UnixLineEndingInputStream(baos, ensure);
final byte[] buf = new byte[100];
- final int read = lf.read( buf );
+ final int read = lf.read(buf);
lf.close();
- return new String( buf, 0, read, StandardCharsets.UTF_8);
+ return new String(buf, 0, read, StandardCharsets.UTF_8);
}
@Test
public void simpleString() throws Exception {
- assertEquals( "abc\n", roundtrip( "abc" ) );
+ assertEquals("abc\n", roundtrip("abc"));
}
@Test
public void twoLinesAtEnd() throws Exception {
- assertEquals( "a\n\n", roundtrip( "a\r\n\r\n" ) );
+ assertEquals("a\n\n", roundtrip("a\r\n\r\n"));
}
-}
\ No newline at end of file
+}
diff --git a/src/test/java/org/apache/commons/io/input/buffer/CircularBufferInputStreamTest.java b/src/test/java/org/apache/commons/io/input/buffer/CircularBufferInputStreamTest.java
index 3cf6dad..8b12299 100644
--- a/src/test/java/org/apache/commons/io/input/buffer/CircularBufferInputStreamTest.java
+++ b/src/test/java/org/apache/commons/io/input/buffer/CircularBufferInputStreamTest.java
@@ -25,78 +25,75 @@ import java.util.Random;
import org.junit.jupiter.api.Test;
-
public class CircularBufferInputStreamTest {
- private final Random rnd = new Random(1530960934483L); // System.currentTimeMillis(), when this test was written.
- // Always using the same seed should ensure a reproducible test.
+ private final Random rnd = new Random(1530960934483L); // System.currentTimeMillis(), when this test was written.
+ // Always using the same seed should ensure a reproducible test.
- /**
- * Create a large, but random input buffer.
- */
- private byte[] newInputBuffer() {
- final byte[] buffer = new byte[16*512+rnd.nextInt(512)];
- rnd.nextBytes(buffer);
- return buffer;
- }
+ /**
+ * Create a large, but random input buffer.
+ */
+ private byte[] newInputBuffer() {
+ final byte[] buffer = new byte[16 * 512 + rnd.nextInt(512)];
+ rnd.nextBytes(buffer);
+ return buffer;
+ }
- @Test
- public void testIO683() throws IOException {
- final byte[] buffer = {0, 1, -2, -2, -1, 4};
- try (final ByteArrayInputStream bais = new ByteArrayInputStream(buffer); final CircularBufferInputStream cbis = new CircularBufferInputStream(bais)) {
- int b;
- int i = 0;
- while ((b = cbis.read()) != -1) {
- assertEquals(buffer[i] & 0xFF, b, "byte at index " + i + " should be equal");
- i++;
- }
- assertEquals(buffer.length, i, "Should have read all the bytes");
- }
- }
+ @Test
+ public void testIO683() throws IOException {
+ final byte[] buffer = {0, 1, -2, -2, -1, 4};
+ try (final ByteArrayInputStream bais = new ByteArrayInputStream(buffer); final CircularBufferInputStream cbis = new CircularBufferInputStream(bais)) {
+ int b;
+ int i = 0;
+ while ((b = cbis.read()) != -1) {
+ assertEquals(buffer[i] & 0xFF, b, "byte at index " + i + " should be equal");
+ i++;
+ }
+ assertEquals(buffer.length, i, "Should have read all the bytes");
+ }
+ }
- @Test
- public void testRandomRead() throws Exception {
- final byte[] inputBuffer = newInputBuffer();
- final byte[] bufferCopy = new byte[inputBuffer.length];
- final ByteArrayInputStream bais = new ByteArrayInputStream(inputBuffer);
- @SuppressWarnings("resource")
- final CircularBufferInputStream cbis = new CircularBufferInputStream(bais, 253);
- int offset = 0;
- final byte[] readBuffer = new byte[256];
- while (offset < bufferCopy.length) {
- switch (rnd.nextInt(2)) {
- case 0:
- {
- final int res = cbis.read();
- if (res == -1) {
- throw new IllegalStateException("Unexpected EOF at offset " + offset);
- }
- if (inputBuffer[offset] != (byte) res) { // compare as bytes
- throw new IllegalStateException("Expected " + inputBuffer[offset] + " at offset " + offset + ", got " + res);
- }
- ++offset;
- break;
- }
- case 1:
- {
- final int res = cbis.read(readBuffer, 0, rnd.nextInt(readBuffer.length+1));
- if (res == -1) {
- throw new IllegalStateException("Unexpected EOF at offset " + offset);
- }
- if (res == 0) {
- throw new IllegalStateException("Unexpected zero-byte-result at offset " + offset);
- }
- for (int i = 0; i < res; i++) {
- if (inputBuffer[offset] != readBuffer[i]) {
- throw new IllegalStateException("Expected " + inputBuffer[offset] + " at offset " + offset + ", got " + readBuffer[i]);
+ @Test
+ public void testRandomRead() throws Exception {
+ final byte[] inputBuffer = newInputBuffer();
+ final byte[] bufferCopy = new byte[inputBuffer.length];
+ final ByteArrayInputStream bais = new ByteArrayInputStream(inputBuffer);
+ @SuppressWarnings("resource")
+ final CircularBufferInputStream cbis = new CircularBufferInputStream(bais, 253);
+ int offset = 0;
+ final byte[] readBuffer = new byte[256];
+ while (offset < bufferCopy.length) {
+ switch (rnd.nextInt(2)) {
+ case 0: {
+ final int res = cbis.read();
+ if (res == -1) {
+ throw new IllegalStateException("Unexpected EOF at offset " + offset);
+ }
+ if (inputBuffer[offset] != (byte) res) { // compare as bytes
+ throw new IllegalStateException("Expected " + inputBuffer[offset] + " at offset " + offset + ", got " + res);
+ }
+ ++offset;
+ break;
+ }
+ case 1: {
+ final int res = cbis.read(readBuffer, 0, rnd.nextInt(readBuffer.length + 1));
+ if (res == -1) {
+ throw new IllegalStateException("Unexpected EOF at offset " + offset);
+ }
+ if (res == 0) {
+ throw new IllegalStateException("Unexpected zero-byte-result at offset " + offset);
+ }
+ for (int i = 0; i < res; i++) {
+ if (inputBuffer[offset] != readBuffer[i]) {
+ throw new IllegalStateException("Expected " + inputBuffer[offset] + " at offset " + offset + ", got " + readBuffer[i]);
+ }
+ ++offset;
+ }
+ break;
+ }
+ default:
+ throw new IllegalStateException("Unexpected random choice value");
}
- ++offset;
}
- break;
- }
- default:
- throw new IllegalStateException("Unexpected random choice value");
- }
- }
- assertTrue(true, "Test finished OK");
- }
+ assertTrue(true, "Test finished OK");
+ }
}
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 dcb331c..7750362 100644
--- a/src/test/java/org/apache/commons/io/output/BrokenOutputStreamTest.java
+++ b/src/test/java/org/apache/commons/io/output/BrokenOutputStreamTest.java
@@ -18,8 +18,10 @@ package org.apache.commons.io.output;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
+
import java.io.IOException;
import java.io.OutputStream;
+
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
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 57d606c..e6f2d62 100644
--- a/src/test/java/org/apache/commons/io/output/BrokenWriterTest.java
+++ b/src/test/java/org/apache/commons/io/output/BrokenWriterTest.java
@@ -18,8 +18,10 @@ package org.apache.commons.io.output;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
+
import java.io.IOException;
import java.io.Writer;
+
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
diff --git a/src/test/java/org/apache/commons/io/output/ByteArrayOutputStreamTest.java b/src/test/java/org/apache/commons/io/output/ByteArrayOutputStreamTest.java
index a47049f..51d2077 100644
--- a/src/test/java/org/apache/commons/io/output/ByteArrayOutputStreamTest.java
+++ b/src/test/java/org/apache/commons/io/output/ByteArrayOutputStreamTest.java
@@ -42,6 +42,7 @@ public class ByteArrayOutputStreamTest {
private interface BAOSFactory<T extends AbstractByteArrayOutputStream> {
T newInstance();
+
T newInstance(final int size);
}
@@ -79,10 +80,8 @@ public class ByteArrayOutputStreamTest {
}
private static Stream<Arguments> baosFactories() {
- return Stream.of(
- Arguments.of(ByteArrayOutputStream.class.getSimpleName(), new ByteArrayOutputStreamFactory()),
- Arguments.of(UnsynchronizedByteArrayOutputStream.class.getSimpleName(), new UnsynchronizedByteArrayOutputStreamFactory())
- );
+ return Stream.of(Arguments.of(ByteArrayOutputStream.class.getSimpleName(), new ByteArrayOutputStreamFactory()),
+ Arguments.of(UnsynchronizedByteArrayOutputStream.class.getSimpleName(), new UnsynchronizedByteArrayOutputStreamFactory()));
}
private static boolean byteCmp(final byte[] src, final byte[] cmp) {
@@ -98,14 +97,13 @@ public class ByteArrayOutputStreamTest {
final IOFunction<InputStream, InputStream> syncBaosToBufferedInputStream = ByteArrayOutputStream::toBufferedInputStream;
final IOFunction<InputStream, InputStream> syncBaosToBufferedInputStreamWithSize = is -> ByteArrayOutputStream.toBufferedInputStream(is, 1024);
final IOFunction<InputStream, InputStream> unSyncBaosToBufferedInputStream = UnsynchronizedByteArrayOutputStream::toBufferedInputStream;
- final IOFunction<InputStream, InputStream> unSyncBaosToBufferedInputStreamWithSize = is -> UnsynchronizedByteArrayOutputStream.toBufferedInputStream(is, 1024);
+ final IOFunction<InputStream, InputStream> unSyncBaosToBufferedInputStreamWithSize = is -> UnsynchronizedByteArrayOutputStream.toBufferedInputStream(is,
+ 1024);
- return Stream.of(
- Arguments.of("ByteArrayOutputStream.toBufferedInputStream(InputStream)", syncBaosToBufferedInputStream),
+ return Stream.of(Arguments.of("ByteArrayOutputStream.toBufferedInputStream(InputStream)", syncBaosToBufferedInputStream),
Arguments.of("ByteArrayOutputStream.toBufferedInputStream(InputStream, int)", syncBaosToBufferedInputStreamWithSize),
Arguments.of("UnsynchronizedByteArrayOutputStream.toBufferedInputStream(InputStream)", unSyncBaosToBufferedInputStream),
- Arguments.of("UnsynchronizedByteArrayOutputStream.toBufferedInputStream(InputStream, int)", unSyncBaosToBufferedInputStreamWithSize)
- );
+ Arguments.of("UnsynchronizedByteArrayOutputStream.toBufferedInputStream(InputStream, int)", unSyncBaosToBufferedInputStreamWithSize));
}
private void checkByteArrays(final byte[] expected, final byte[] actual) {
@@ -117,9 +115,7 @@ public class ByteArrayOutputStreamTest {
}
}
- private void checkStreams(
- final AbstractByteArrayOutputStream actual,
- final java.io.ByteArrayOutputStream expected) {
+ private void checkStreams(final AbstractByteArrayOutputStream actual, final java.io.ByteArrayOutputStream expected) {
assertEquals(expected.size(), actual.size(), "Sizes are not equal");
final byte[] buf = actual.toByteArray();
final byte[] refbuf = expected.toByteArray();
@@ -129,9 +125,7 @@ public class ByteArrayOutputStreamTest {
@ParameterizedTest(name = "[{index}] {0}")
@MethodSource("baosFactories")
public void testInvalidParameterizedConstruction(final String baosName, final BAOSFactory<?> baosFactory) {
- assertThrows(IllegalArgumentException.class, () ->
- baosFactory.newInstance(-1)
- );
+ assertThrows(IllegalArgumentException.class, () -> baosFactory.newInstance(-1));
}
@ParameterizedTest(name = "[{index}] {0}")
@@ -152,8 +146,7 @@ public class ByteArrayOutputStreamTest {
@ParameterizedTest(name = "[{index}] {0}")
@MethodSource("baosFactories")
- public void testInvalidWriteOffsetAndLenUnder(final String baosName, final BAOSFactory<?> baosFactory)
- throws IOException {
+ public void testInvalidWriteOffsetAndLenUnder(final String baosName, final BAOSFactory<?> baosFactory) throws IOException {
try (final AbstractByteArrayOutputStream baout = baosFactory.newInstance()) {
assertThrows(IndexOutOfBoundsException.class, () -> baout.write(new byte[1], 1, -2));
}
@@ -236,7 +229,7 @@ public class ByteArrayOutputStreamTest {
@ParameterizedTest(name = "[{index}] {0}")
@MethodSource("toBufferedInputStreamFunctionFactories")
public void testToBufferedInputStream(final String baosName, final IOFunction<InputStream, InputStream> toBufferedInputStreamFunction) throws IOException {
- final byte data[] = {(byte)0xCA, (byte)0xFE, (byte)0xBA, (byte)0xBE};
+ final byte data[] = {(byte) 0xCA, (byte) 0xFE, (byte) 0xBA, (byte) 0xBE};
try (final ByteArrayInputStream bain = new ByteArrayInputStream(data)) {
assertEquals(data.length, bain.available());
@@ -252,7 +245,8 @@ public class ByteArrayOutputStreamTest {
@ParameterizedTest(name = "[{index}] {0}")
@MethodSource("toBufferedInputStreamFunctionFactories")
- public void testToBufferedInputStreamEmpty(final String baosName, final IOFunction<InputStream, InputStream> toBufferedInputStreamFunction) throws IOException {
+ public void testToBufferedInputStreamEmpty(final String baosName, final IOFunction<InputStream, InputStream> toBufferedInputStreamFunction)
+ throws IOException {
try (final ByteArrayInputStream bain = new ByteArrayInputStream(IOUtils.EMPTY_BYTE_ARRAY)) {
assertEquals(0, bain.available());
@@ -356,9 +350,7 @@ public class ByteArrayOutputStreamTest {
}
}
- private int writeData(final AbstractByteArrayOutputStream baout,
- final java.io.ByteArrayOutputStream ref,
- final int count) {
+ private int writeData(final AbstractByteArrayOutputStream baout, final java.io.ByteArrayOutputStream ref, final int count) {
if (count > DATA.length) {
throw new IllegalArgumentException("Requesting too many bytes");
}
@@ -372,9 +364,7 @@ public class ByteArrayOutputStreamTest {
return count;
}
- private int writeData(final AbstractByteArrayOutputStream baout,
- final java.io.ByteArrayOutputStream ref,
- final int[] instructions) {
+ private int writeData(final AbstractByteArrayOutputStream baout, final java.io.ByteArrayOutputStream ref, final int[] instructions) {
int written = 0;
for (final int instruction : instructions) {
written += writeData(baout, ref, instruction);
diff --git a/src/test/java/org/apache/commons/io/output/LockableFileWriterTest.java b/src/test/java/org/apache/commons/io/output/LockableFileWriterTest.java
index cf3bdda..d664b2b 100644
--- a/src/test/java/org/apache/commons/io/output/LockableFileWriterTest.java
+++ b/src/test/java/org/apache/commons/io/output/LockableFileWriterTest.java
@@ -23,12 +23,9 @@ import static org.junit.jupiter.api.Assertions.fail;
import java.io.File;
import java.io.IOException;
-import java.io.Writer;
import java.nio.charset.StandardCharsets;
import java.nio.charset.UnsupportedCharsetException;
-import java.util.List;
-import org.apache.commons.io.filefilter.WildcardFileFilter;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;