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 2025/09/22 13:38:28 UTC

(commons-io) 02/02: Fix compiler warnings

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 61caea1f3c9276cd3a0d7418675fe28e941ac752
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Mon Sep 22 09:38:21 2025 -0400

    Fix compiler warnings
    
    Access static methods on the class that define them
---
 src/test/java/org/apache/commons/io/IOUtilsTest.java | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/src/test/java/org/apache/commons/io/IOUtilsTest.java b/src/test/java/org/apache/commons/io/IOUtilsTest.java
index 64de368c9..bae8f59e3 100644
--- a/src/test/java/org/apache/commons/io/IOUtilsTest.java
+++ b/src/test/java/org/apache/commons/io/IOUtilsTest.java
@@ -96,6 +96,7 @@
 import org.junit.jupiter.params.ParameterizedTest;
 import org.junit.jupiter.params.provider.Arguments;
 import org.junit.jupiter.params.provider.MethodSource;
+import org.mockito.ArgumentMatchers;
 import org.mockito.MockedStatic;
 import org.mockito.Mockito;
 
@@ -1731,17 +1732,19 @@ void testToByteArray_String() throws Exception {
     }
 
     @Test
-    void testToByteArray_ThrowsIOExceptionOnHugeStream() {
-        try (MockedStatic<IOUtils> utils = Mockito.mockStatic(IOUtils.class, Mockito.CALLS_REAL_METHODS)) {
+    void testToByteArray_ThrowsIOExceptionOnHugeStream() throws IOException {
+        try (MockedStatic<IOUtils> utils = Mockito.mockStatic(IOUtils.class, Mockito.CALLS_REAL_METHODS);
+                UnsynchronizedByteArrayOutputStream mockOutputStream = mock(UnsynchronizedByteArrayOutputStream.class)) {
             // Prepare the mocks
-            final UnsynchronizedByteArrayOutputStream mockOutputStream = mock(UnsynchronizedByteArrayOutputStream.class);
-            utils.when(() -> IOUtils.copyToOutputStream(Mockito.any(InputStream.class), Mockito.anyLong(), Mockito.anyInt())).thenReturn(mockOutputStream);
+            utils.when(() -> IOUtils.copyToOutputStream(ArgumentMatchers.any(InputStream.class), ArgumentMatchers.anyLong(), ArgumentMatchers.anyInt()))
+                    .thenReturn(mockOutputStream);
             when(mockOutputStream.size()).thenReturn(IOUtils.SOFT_MAX_ARRAY_LENGTH + 1);
             // Test and check
-            final InputStream mockInputStream = mock(InputStream.class);
-            final IOException exception = assertThrows(IOException.class, () -> IOUtils.toByteArray(mockInputStream));
-            assertTrue(exception.getMessage().contains(String.format("%,d", IOUtils.SOFT_MAX_ARRAY_LENGTH)),
-                    "Exception message does not contain the maximum length");
+            try (InputStream mockInputStream = mock(InputStream.class)) {
+                final IOException exception = assertThrows(IOException.class, () -> IOUtils.toByteArray(mockInputStream));
+                assertTrue(exception.getMessage().contains(String.format("%,d", IOUtils.SOFT_MAX_ARRAY_LENGTH)),
+                        "Exception message does not contain the maximum length");
+            }
         }
     }