|
96 | 96 | import org.junit.jupiter.params.ParameterizedTest; |
97 | 97 | import org.junit.jupiter.params.provider.Arguments; |
98 | 98 | import org.junit.jupiter.params.provider.MethodSource; |
| 99 | +import org.mockito.ArgumentMatchers; |
99 | 100 | import org.mockito.MockedStatic; |
100 | 101 | import org.mockito.Mockito; |
101 | 102 |
|
@@ -1731,17 +1732,19 @@ void testToByteArray_String() throws Exception { |
1731 | 1732 | } |
1732 | 1733 |
|
1733 | 1734 | @Test |
1734 | | - void testToByteArray_ThrowsIOExceptionOnHugeStream() { |
1735 | | - try (MockedStatic<IOUtils> utils = Mockito.mockStatic(IOUtils.class, Mockito.CALLS_REAL_METHODS)) { |
| 1735 | + void testToByteArray_ThrowsIOExceptionOnHugeStream() throws IOException { |
| 1736 | + try (MockedStatic<IOUtils> utils = Mockito.mockStatic(IOUtils.class, Mockito.CALLS_REAL_METHODS); |
| 1737 | + UnsynchronizedByteArrayOutputStream mockOutputStream = mock(UnsynchronizedByteArrayOutputStream.class)) { |
1736 | 1738 | // Prepare the mocks |
1737 | | - final UnsynchronizedByteArrayOutputStream mockOutputStream = mock(UnsynchronizedByteArrayOutputStream.class); |
1738 | | - utils.when(() -> IOUtils.copyToOutputStream(Mockito.any(InputStream.class), Mockito.anyLong(), Mockito.anyInt())).thenReturn(mockOutputStream); |
| 1739 | + utils.when(() -> IOUtils.copyToOutputStream(ArgumentMatchers.any(InputStream.class), ArgumentMatchers.anyLong(), ArgumentMatchers.anyInt())) |
| 1740 | + .thenReturn(mockOutputStream); |
1739 | 1741 | when(mockOutputStream.size()).thenReturn(IOUtils.SOFT_MAX_ARRAY_LENGTH + 1); |
1740 | 1742 | // Test and check |
1741 | | - final InputStream mockInputStream = mock(InputStream.class); |
1742 | | - final IOException exception = assertThrows(IOException.class, () -> IOUtils.toByteArray(mockInputStream)); |
1743 | | - assertTrue(exception.getMessage().contains(String.format("%,d", IOUtils.SOFT_MAX_ARRAY_LENGTH)), |
1744 | | - "Exception message does not contain the maximum length"); |
| 1743 | + try (InputStream mockInputStream = mock(InputStream.class)) { |
| 1744 | + final IOException exception = assertThrows(IOException.class, () -> IOUtils.toByteArray(mockInputStream)); |
| 1745 | + assertTrue(exception.getMessage().contains(String.format("%,d", IOUtils.SOFT_MAX_ARRAY_LENGTH)), |
| 1746 | + "Exception message does not contain the maximum length"); |
| 1747 | + } |
1745 | 1748 | } |
1746 | 1749 | } |
1747 | 1750 |
|
|
0 commit comments