diff --git a/src/test/java/com/picimako/mockitools/inspection/consecutive/SimplifyConsecutiveReturnCallsInspectionTest.java b/src/test/java/com/picimako/mockitools/inspection/consecutive/SimplifyConsecutiveReturnCallsInspectionTest.java index f547fe2..72c91af 100644 --- a/src/test/java/com/picimako/mockitools/inspection/consecutive/SimplifyConsecutiveReturnCallsInspectionTest.java +++ b/src/test/java/com/picimako/mockitools/inspection/consecutive/SimplifyConsecutiveReturnCallsInspectionTest.java @@ -2,12 +2,17 @@ package com.picimako.mockitools.inspection.consecutive; +import static org.junit.jupiter.params.provider.Arguments.arguments; + import com.intellij.codeInspection.InspectionProfileEntry; import com.picimako.mockitools.inspection.MockitoolsInspectionTestBase; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; +import java.util.stream.Stream; + /** * Functional test for {@link SimplifyConsecutiveReturnCallsInspection}. */ @@ -22,414 +27,408 @@ public int didSomething() { } """; - private static String[][] whenThenReturnCases() { - return new String[][]{ - { + private static Stream whenThenReturnCases() { + return Stream.of( + arguments( " Mockito.when(mockObject.didSomething()).thenReturn(1).thenReturn(2);", - " Mockito.when(mockObject.didSomething()).thenReturn(1, 2);" - }, - { - """ - Mockito.when(mockObject.didSomething()).thenReturn(1) - .thenCallRealMethod() - .thenReturn(2) - .thenReturn(3);\ -""", - """ - Mockito.when(mockObject.didSomething()).thenReturn(1) - .thenCallRealMethod() - .thenReturn(2, 3);\ -""" - }, - { - """ - Mockito.when(mockObject.didSomething()).thenReturn(1) - .thenReturn(2) - .thenCallRealMethod() - .thenReturn(3);\ -""", - """ - Mockito.when(mockObject.didSomething()).thenReturn(1, 2) - .thenCallRealMethod() - .thenReturn(3);\ -""" - }, - { - """ - Mockito.when(mockObject.didSomething()).thenReturn(1) - .thenReturn(2) - .thenCallRealMethod() - .thenReturn(3) - .thenReturn(4);\ -""", - """ - Mockito.when(mockObject.didSomething()).thenReturn(1, 2) - .thenCallRealMethod() - .thenReturn(3) - .thenReturn(4);\ -""" - }, - { - """ - Mockito.when(mockObject.didSomething()).thenReturn(1) - .thenReturn(2) - .thenCallRealMethod() - .thenReturn(3) - .thenReturn(4);\ -""", - """ - Mockito.when(mockObject.didSomething()).thenReturn(1) - .thenReturn(2) - .thenCallRealMethod() - .thenReturn(3, 4);\ -""" - }, - { - """ - Mockito.when(mockObject.didSomething()).thenReturn(1, 2, 3) - .thenReturn(4) - .thenCallRealMethod() - .thenReturn(5) - .thenReturn(6, 7);\ -""", - """ - Mockito.when(mockObject.didSomething()).thenReturn(1, 2, 3) - .thenReturn(4) - .thenCallRealMethod() - .thenReturn(5, 6, 7);\ -""" - }, - }; + " Mockito.when(mockObject.didSomething()).thenReturn(1, 2);"), + arguments( + """ + Mockito.when(mockObject.didSomething()).thenReturn(1) + .thenCallRealMethod() + .thenReturn(2) + .thenReturn(3);\ + """, + """ + Mockito.when(mockObject.didSomething()).thenReturn(1) + .thenCallRealMethod() + .thenReturn(2, 3);\ + """ + ), + arguments( + """ + Mockito.when(mockObject.didSomething()).thenReturn(1) + .thenReturn(2) + .thenCallRealMethod() + .thenReturn(3);\ + """, + """ + Mockito.when(mockObject.didSomething()).thenReturn(1, 2) + .thenCallRealMethod() + .thenReturn(3);\ + """ + ), + arguments( + """ + Mockito.when(mockObject.didSomething()).thenReturn(1) + .thenReturn(2) + .thenCallRealMethod() + .thenReturn(3) + .thenReturn(4);\ + """, + """ + Mockito.when(mockObject.didSomething()).thenReturn(1, 2) + .thenCallRealMethod() + .thenReturn(3) + .thenReturn(4);\ + """ + ), + arguments( + """ + Mockito.when(mockObject.didSomething()).thenReturn(1) + .thenReturn(2) + .thenCallRealMethod() + .thenReturn(3) + .thenReturn(4);\ + """, + """ + Mockito.when(mockObject.didSomething()).thenReturn(1) + .thenReturn(2) + .thenCallRealMethod() + .thenReturn(3, 4);\ + """ + ), + arguments( + """ + Mockito.when(mockObject.didSomething()).thenReturn(1, 2, 3) + .thenReturn(4) + .thenCallRealMethod() + .thenReturn(5) + .thenReturn(6, 7);\ + """, + """ + Mockito.when(mockObject.didSomething()).thenReturn(1, 2, 3) + .thenReturn(4) + .thenCallRealMethod() + .thenReturn(5, 6, 7);\ + """ + )); } - private static String[][] doReturnWhenCases() { - return new String[][]{ - { + private static Stream doReturnWhenCases() { + return Stream.of( + arguments( " Mockito.doReturn(1).doReturn(2).when(mockObject).didSomething();", " Mockito.doReturn(1, 2).when(mockObject).didSomething();" - }, - { - """ - Mockito.doReturn(1) - .doCallRealMethod() - .doReturn(2) - .doReturn(3) - .when(mockObject).didSomething();\ -""", - """ - Mockito.doReturn(1) - .doCallRealMethod() - .doReturn(2, 3) - .when(mockObject).didSomething();\ -""" - }, - { - """ - Mockito.doReturn(1) - .doReturn(2) - .doCallRealMethod() - .doReturn(3) - .when(mockObject).didSomething();\ -""", - """ - Mockito.doReturn(1, 2) - .doCallRealMethod() - .doReturn(3) - .when(mockObject).didSomething();\ -""" - }, - { - """ - Mockito.doReturn(1) - .doReturn(2) - .doCallRealMethod() - .doReturn(3) - .doReturn(4) - .when(mockObject).didSomething();\ -""", - """ - Mockito.doReturn(1, 2) - .doCallRealMethod() - .doReturn(3) - .doReturn(4) - .when(mockObject).didSomething();\ -""" - }, - { - """ - Mockito.doReturn(1) - .doReturn(2) - .doCallRealMethod() - .doReturn(3) - .doReturn(4) - .when(mockObject).didSomething();\ -""", - """ - Mockito.doReturn(1) - .doReturn(2) - .doCallRealMethod() - .doReturn(3, 4) - .when(mockObject).didSomething();\ -""" - }, - { - """ - Mockito.doReturn(1, 2, 3) - .doReturn(4) - .doCallRealMethod() - .doReturn(5) - .doReturn(6, 7) - .when(mockObject).didSomething();\ -""", - """ - Mockito.doReturn(1, 2, 3) - .doReturn(4) - .doCallRealMethod() - .doReturn(5, 6, 7) - .when(mockObject).didSomething();\ -""" - } - }; + ), + arguments( + """ + Mockito.doReturn(1) + .doCallRealMethod() + .doReturn(2) + .doReturn(3) + .when(mockObject).didSomething();\ + """, + """ + Mockito.doReturn(1) + .doCallRealMethod() + .doReturn(2, 3) + .when(mockObject).didSomething();\ + """ + ), + arguments( + """ + Mockito.doReturn(1) + .doReturn(2) + .doCallRealMethod() + .doReturn(3) + .when(mockObject).didSomething();\ + """, + """ + Mockito.doReturn(1, 2) + .doCallRealMethod() + .doReturn(3) + .when(mockObject).didSomething();\ + """ + ), + arguments( + """ + Mockito.doReturn(1) + .doReturn(2) + .doCallRealMethod() + .doReturn(3) + .doReturn(4) + .when(mockObject).didSomething();\ + """, + """ + Mockito.doReturn(1, 2) + .doCallRealMethod() + .doReturn(3) + .doReturn(4) + .when(mockObject).didSomething();\ + """ + ), + arguments( + """ + Mockito.doReturn(1) + .doReturn(2) + .doCallRealMethod() + .doReturn(3) + .doReturn(4) + .when(mockObject).didSomething();\ + """, + """ + Mockito.doReturn(1) + .doReturn(2) + .doCallRealMethod() + .doReturn(3, 4) + .when(mockObject).didSomething();\ + """ + ), + arguments( + """ + Mockito.doReturn(1, 2, 3) + .doReturn(4) + .doCallRealMethod() + .doReturn(5) + .doReturn(6, 7) + .when(mockObject).didSomething();\ + """, + """ + Mockito.doReturn(1, 2, 3) + .doReturn(4) + .doCallRealMethod() + .doReturn(5, 6, 7) + .when(mockObject).didSomething();\ + """ + )); } - private static String[][] givenWillReturnCases() { - return new String[][]{ - { + private static Stream givenWillReturnCases() { + return Stream.of( + arguments( " BDDMockito.given(mockObject.didSomething()).willReturn(1).willReturn(2);", " BDDMockito.given(mockObject.didSomething()).willReturn(1, 2);" - }, - { - """ - BDDMockito.given(mockObject.didSomething()).willReturn(1) - .willCallRealMethod() - .willReturn(2) - .willReturn(3);\ -""", - """ - BDDMockito.given(mockObject.didSomething()).willReturn(1) - .willCallRealMethod() - .willReturn(2, 3);\ -""" - }, - { - """ - BDDMockito.given(mockObject.didSomething()).willReturn(1) - .willReturn(2) - .willCallRealMethod() - .willReturn(3);\ -""", - """ - BDDMockito.given(mockObject.didSomething()).willReturn(1, 2) - .willCallRealMethod() - .willReturn(3);\ -""" - }, - { - """ - BDDMockito.given(mockObject.didSomething()).willReturn(1) - .willReturn(2) - .willCallRealMethod() - .willReturn(3) - .willReturn(4);\ -""", - """ - BDDMockito.given(mockObject.didSomething()).willReturn(1, 2) - .willCallRealMethod() - .willReturn(3) - .willReturn(4);\ -""" - }, - { - """ - BDDMockito.given(mockObject.didSomething()).willReturn(1) - .willReturn(2) - .willCallRealMethod() - .willReturn(3) - .willReturn(4);\ -""", - """ - BDDMockito.given(mockObject.didSomething()).willReturn(1) - .willReturn(2) - .willCallRealMethod() - .willReturn(3, 4);\ -""" - }, - { - """ - BDDMockito.given(mockObject.didSomething()).willReturn(1, 2, 3) - .willReturn(4) - .willCallRealMethod() - .willReturn(5) - .willReturn(6, 7);\ -""", - """ - BDDMockito.given(mockObject.didSomething()).willReturn(1, 2, 3, 4) - .willCallRealMethod() - .willReturn(5) - .willReturn(6, 7);\ -""" - } - }; + ), + arguments( + """ + BDDMockito.given(mockObject.didSomething()).willReturn(1) + .willCallRealMethod() + .willReturn(2) + .willReturn(3);\ + """, + """ + BDDMockito.given(mockObject.didSomething()).willReturn(1) + .willCallRealMethod() + .willReturn(2, 3);\ + """ + ), + arguments( + """ + BDDMockito.given(mockObject.didSomething()).willReturn(1) + .willReturn(2) + .willCallRealMethod() + .willReturn(3);\ + """, + """ + BDDMockito.given(mockObject.didSomething()).willReturn(1, 2) + .willCallRealMethod() + .willReturn(3);\ + """ + ), + arguments( + """ + BDDMockito.given(mockObject.didSomething()).willReturn(1) + .willReturn(2) + .willCallRealMethod() + .willReturn(3) + .willReturn(4);\ + """, + """ + BDDMockito.given(mockObject.didSomething()).willReturn(1, 2) + .willCallRealMethod() + .willReturn(3) + .willReturn(4);\ + """ + ), + arguments( + """ + BDDMockito.given(mockObject.didSomething()).willReturn(1) + .willReturn(2) + .willCallRealMethod() + .willReturn(3) + .willReturn(4);\ + """, + """ + BDDMockito.given(mockObject.didSomething()).willReturn(1) + .willReturn(2) + .willCallRealMethod() + .willReturn(3, 4);\ + """ + ), + arguments( + """ + BDDMockito.given(mockObject.didSomething()).willReturn(1, 2, 3) + .willReturn(4) + .willCallRealMethod() + .willReturn(5) + .willReturn(6, 7);\ + """, + """ + BDDMockito.given(mockObject.didSomething()).willReturn(1, 2, 3, 4) + .willCallRealMethod() + .willReturn(5) + .willReturn(6, 7);\ + """ + )); } - private static String[][] willReturnGivenCases() { - return new String[][]{ - { + private static Stream willReturnGivenCases() { + return Stream.of( + arguments( " BDDMockito.willReturn(1).willReturn(2).given(mockObject).didSomething();", " BDDMockito.willReturn(1, 2).given(mockObject).didSomething();" - }, - { - """ - BDDMockito.willReturn(1) - .willCallRealMethod() - .willReturn(2) - .willReturn(3).given(mockObject).didSomething();\ -""", - """ - BDDMockito.willReturn(1) - .willCallRealMethod() - .willReturn(2, 3).given(mockObject).didSomething();\ -""" - }, - { - """ - BDDMockito.willReturn(1) - .willReturn(2) - .willCallRealMethod() - .willReturn(3).given(mockObject).didSomething();\ -""", - """ - BDDMockito.willReturn(1, 2) - .willCallRealMethod() - .willReturn(3).given(mockObject).didSomething();\ -""" - }, - { - """ - BDDMockito.willReturn(1) - .willReturn(2) - .willCallRealMethod() - .willReturn(3) - .willReturn(4).given(mockObject).didSomething();\ -""", - """ - BDDMockito.willReturn(1, 2) - .willCallRealMethod() - .willReturn(3) - .willReturn(4).given(mockObject).didSomething();\ -""" - }, - { - """ - BDDMockito.willReturn(1) - .willReturn(2) - .willCallRealMethod() - .willReturn(3) - .willReturn(4).given(mockObject).didSomething();\ -""", - """ - BDDMockito.willReturn(1) - .willReturn(2) - .willCallRealMethod() - .willReturn(3, 4).given(mockObject).didSomething();\ -""" - }, - { - """ - BDDMockito.willReturn(1, 2, 3) - .willReturn(4) - .willCallRealMethod() - .willReturn(5) - .willReturn(6, 7).given(mockObject).didSomething();\ -""", - """ - BDDMockito.willReturn(1, 2, 3, 4) - .willCallRealMethod() - .willReturn(5) - .willReturn(6, 7).given(mockObject).didSomething();\ -""" - } - }; + ), + arguments( + """ + BDDMockito.willReturn(1) + .willCallRealMethod() + .willReturn(2) + .willReturn(3).given(mockObject).didSomething();\ + """, + """ + BDDMockito.willReturn(1) + .willCallRealMethod() + .willReturn(2, 3).given(mockObject).didSomething();\ + """ + ), + arguments( + """ + BDDMockito.willReturn(1) + .willReturn(2) + .willCallRealMethod() + .willReturn(3).given(mockObject).didSomething();\ + """, + """ + BDDMockito.willReturn(1, 2) + .willCallRealMethod() + .willReturn(3).given(mockObject).didSomething();\ + """ + ), + arguments( + """ + BDDMockito.willReturn(1) + .willReturn(2) + .willCallRealMethod() + .willReturn(3) + .willReturn(4).given(mockObject).didSomething();\ + """, + """ + BDDMockito.willReturn(1, 2) + .willCallRealMethod() + .willReturn(3) + .willReturn(4).given(mockObject).didSomething();\ + """ + ), + arguments( + """ + BDDMockito.willReturn(1) + .willReturn(2) + .willCallRealMethod() + .willReturn(3) + .willReturn(4).given(mockObject).didSomething();\ + """, + """ + BDDMockito.willReturn(1) + .willReturn(2) + .willCallRealMethod() + .willReturn(3, 4).given(mockObject).didSomething();\ + """ + ), + arguments( + """ + BDDMockito.willReturn(1, 2, 3) + .willReturn(4) + .willCallRealMethod() + .willReturn(5) + .willReturn(6, 7).given(mockObject).didSomething();\ + """, + """ + BDDMockito.willReturn(1, 2, 3, 4) + .willCallRealMethod() + .willReturn(5) + .willReturn(6, 7).given(mockObject).didSomething();\ + """ + )); } - private static String[][] mockedStaticWhenThenReturnCases() { - return new String[][]{ - { + private static Stream mockedStaticWhenThenReturnCases() { + return Stream.of( + arguments( " mock.when(List::of).thenReturn(List.of()).thenReturn(Collections.emptyList());", " mock.when(List::of).thenReturn(List.of(), Collections.emptyList());" - }, - { - """ - mock.when(List::of).thenReturn(List.of()) - .thenCallRealMethod() - .thenReturn(Collections.emptyList()) - .thenReturn(Collections.EMPTY_LIST);\ -""", - """ - mock.when(List::of).thenReturn(List.of()) - .thenCallRealMethod() - .thenReturn(Collections.emptyList(), Collections.EMPTY_LIST);\ -""" - }, - { - """ - mock.when(List::of).thenReturn(List.of()) - .thenReturn(Collections.emptyList()) - .thenCallRealMethod() - .thenReturn(Collections.EMPTY_LIST);\ -""", - """ - mock.when(List::of).thenReturn(List.of(), Collections.emptyList()) - .thenCallRealMethod() - .thenReturn(Collections.EMPTY_LIST);\ -""" - }, - { - """ - mock.when(List::of).thenReturn(List.of()) - .thenReturn(Collections.emptyList()) - .thenCallRealMethod() - .thenReturn(Collections.EMPTY_LIST) - .thenReturn(null);\ -""", - """ - mock.when(List::of).thenReturn(List.of(), Collections.emptyList()) - .thenCallRealMethod() - .thenReturn(Collections.EMPTY_LIST) - .thenReturn(null);\ -""" - }, - { - """ - mock.when(List::of).thenReturn(List.of()) - .thenReturn(Collections.emptyList()) - .thenCallRealMethod() - .thenReturn(Collections.EMPTY_LIST) - .thenReturn(null);\ -""", - """ - mock.when(List::of).thenReturn(List.of()) - .thenReturn(Collections.emptyList()) - .thenCallRealMethod() - .thenReturn(Collections.EMPTY_LIST, null);\ -""" - }, - { - """ - mock.when(List::of).thenReturn(List.of(), Collections.emptyList(), Collections.EMPTY_LIST) - .thenReturn(null) - .thenCallRealMethod() - .thenReturn(List.of()) - .thenReturn(Collections.emptyList(), Collections.EMPTY_LIST);\ -""", - """ - mock.when(List::of).thenReturn(List.of(), Collections.emptyList(), Collections.EMPTY_LIST, null) - .thenCallRealMethod() - .thenReturn(List.of()) - .thenReturn(Collections.emptyList(), Collections.EMPTY_LIST);\ -""" - } - }; + ), + arguments( + """ + mock.when(List::of).thenReturn(List.of()) + .thenCallRealMethod() + .thenReturn(Collections.emptyList()) + .thenReturn(Collections.EMPTY_LIST);\ + """, + """ + mock.when(List::of).thenReturn(List.of()) + .thenCallRealMethod() + .thenReturn(Collections.emptyList(), Collections.EMPTY_LIST);\ + """ + ), + arguments( + """ + mock.when(List::of).thenReturn(List.of()) + .thenReturn(Collections.emptyList()) + .thenCallRealMethod() + .thenReturn(Collections.EMPTY_LIST);\ + """, + """ + mock.when(List::of).thenReturn(List.of(), Collections.emptyList()) + .thenCallRealMethod() + .thenReturn(Collections.EMPTY_LIST);\ + """ + ), + arguments( + """ + mock.when(List::of).thenReturn(List.of()) + .thenReturn(Collections.emptyList()) + .thenCallRealMethod() + .thenReturn(Collections.EMPTY_LIST) + .thenReturn(null);\ + """, + """ + mock.when(List::of).thenReturn(List.of(), Collections.emptyList()) + .thenCallRealMethod() + .thenReturn(Collections.EMPTY_LIST) + .thenReturn(null);\ + """ + ), + arguments( + """ + mock.when(List::of).thenReturn(List.of()) + .thenReturn(Collections.emptyList()) + .thenCallRealMethod() + .thenReturn(Collections.EMPTY_LIST) + .thenReturn(null);\ + """, + """ + mock.when(List::of).thenReturn(List.of()) + .thenReturn(Collections.emptyList()) + .thenCallRealMethod() + .thenReturn(Collections.EMPTY_LIST, null);\ + """ + ), + arguments( + """ + mock.when(List::of).thenReturn(List.of(), Collections.emptyList(), Collections.EMPTY_LIST) + .thenReturn(null) + .thenCallRealMethod() + .thenReturn(List.of()) + .thenReturn(Collections.emptyList(), Collections.EMPTY_LIST);\ + """, + """ + mock.when(List::of).thenReturn(List.of(), Collections.emptyList(), Collections.EMPTY_LIST, null) + .thenCallRealMethod() + .thenReturn(List.of()) + .thenReturn(Collections.emptyList(), Collections.EMPTY_LIST);\ + """ + )); } @Override @@ -437,14 +436,14 @@ protected InspectionProfileEntry getInspection() { return new SimplifyConsecutiveReturnCallsInspection(); } - //Highlighting +//Highlighting @Test void testSimplifyConsecutiveStubbingCalls() { doJavaTest(); } - //Quick fixes +//Quick fixes @ParameterizedTest @MethodSource("whenThenReturnCases") @@ -478,29 +477,29 @@ void testReplacesMockedStaticWhenThenReturns(String before, String after) { private String createClassText(String beforeOrAfter) { return "import org.mockito.Mockito;\n" + - "import org.mockito.BDDMockito;\n" + - "\n" + - "class QuickFix {\n" + - " void testMethod() {\n" + - beforeOrAfter + "\n" + - " }\n" + - "\n" + - MOCK_OBJECT_CLASS + - "}"; + "import org.mockito.BDDMockito;\n" + + "\n" + + "class QuickFix {\n" + + " void testMethod() {\n" + + beforeOrAfter + "\n" + + " }\n" + + "\n" + + MOCK_OBJECT_CLASS + + "}"; } private String createMockedStaticClassText(String beforeOrAfter) { return "import org.mockito.Mockito;\n" + - "import org.mockito.MockedStatic;\n" + - "import java.util.Collections;\n" + - "import java.util.List;\n" + - "\n" + - "class QuickFix {\n" + - " void testMethod() {\n" + - " try (MockedStatic mock = Mockito.mockStatic(List.class)) {\n" + - beforeOrAfter + "\n" + - " }\n" + - " }\n" + - "}"; + "import org.mockito.MockedStatic;\n" + + "import java.util.Collections;\n" + + "import java.util.List;\n" + + "\n" + + "class QuickFix {\n" + + " void testMethod() {\n" + + " try (MockedStatic mock = Mockito.mockStatic(List.class)) {\n" + + beforeOrAfter + "\n" + + " }\n" + + " }\n" + + "}"; } } diff --git a/src/test/java/com/picimako/mockitools/inspection/consecutive/SimplifyConsecutiveThrowCallsInspectionTest.java b/src/test/java/com/picimako/mockitools/inspection/consecutive/SimplifyConsecutiveThrowCallsInspectionTest.java index 31c4a7a..526641a 100644 --- a/src/test/java/com/picimako/mockitools/inspection/consecutive/SimplifyConsecutiveThrowCallsInspectionTest.java +++ b/src/test/java/com/picimako/mockitools/inspection/consecutive/SimplifyConsecutiveThrowCallsInspectionTest.java @@ -2,12 +2,17 @@ package com.picimako.mockitools.inspection.consecutive; +import static org.junit.jupiter.params.provider.Arguments.arguments; + import com.intellij.codeInspection.InspectionProfileEntry; import com.picimako.mockitools.inspection.MockitoolsInspectionTestBase; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; +import java.util.stream.Stream; + /** * Functional test for {@link SimplifyConsecutiveThrowCallsInspection}; */ @@ -22,487 +27,480 @@ public int didSomething() { } """; - private static String[][] whenThenThrowCases() { - return new String[][]{ - { + private static Stream whenThenThrowCases() { + return Stream.of( + arguments( " Mockito.when(mockObject.doSomething()).thenThrow(NoSuchMethodException.class).thenThrow(IOException.class);", " Mockito.when(mockObject.doSomething()).thenThrow(NoSuchMethodException.class, IOException.class);" - }, - { + ), + arguments( " Mockito.when(mockObject.doSomething()).thenThrow(IOException.class, NoSuchMethodException.class).thenThrow(IllegalArgumentException.class);", " Mockito.when(mockObject.doSomething()).thenThrow(IOException.class, NoSuchMethodException.class, IllegalArgumentException.class);" - }, - { + ), + arguments( " Mockito.when(mockObject.doSomething()).thenThrow(IOException.class).thenThrow(IllegalArgumentException.class, NoSuchMethodException.class);", " Mockito.when(mockObject.doSomething()).thenThrow(IOException.class, IllegalArgumentException.class, NoSuchMethodException.class);" - }, - { + ), + arguments( " Mockito.when(mockObject.doSomething()).thenThrow(new IOException()).thenThrow(new IllegalArgumentException());", " Mockito.when(mockObject.doSomething()).thenThrow(new IOException(), new IllegalArgumentException());" - }, - { + ), + arguments( " Mockito.when(mockObject.doSomething()).thenThrow(new IOException(), new NoSuchMethodException()).thenThrow(new IllegalArgumentException());", " Mockito.when(mockObject.doSomething()).thenThrow(new IOException(), new NoSuchMethodException(), new IllegalArgumentException());" - }, - { - """ - Mockito.when(mockObject.doSomething()).thenThrow(new IOException(), new NoSuchMethodException()).thenThrow(new IllegalArgumentException()) - .thenReturn(10) - .thenThrow(new IOException(), new NoSuchMethodException()).thenThrow(new IllegalArgumentException());\ -""", - """ - Mockito.when(mockObject.doSomething()).thenThrow(new IOException(), new NoSuchMethodException()).thenThrow(new IllegalArgumentException()) - .thenReturn(10) - .thenThrow(new IOException(), new NoSuchMethodException(), new IllegalArgumentException());\ -""" - }, - { - """ - Mockito.when(mockObject.doSomething()).thenThrow(new IOException(), new NoSuchMethodException()).thenThrow(new IllegalArgumentException()) - .thenReturn(10) - .thenThrow(new IOException(), new NoSuchMethodException()).thenThrow(new IllegalArgumentException());\ -""", - """ - Mockito.when(mockObject.doSomething()).thenThrow(new IOException(), new NoSuchMethodException(), new IllegalArgumentException()) - .thenReturn(10) - .thenThrow(new IOException(), new NoSuchMethodException()).thenThrow(new IllegalArgumentException());\ -""" - }, - { + ), + arguments( + """ + Mockito.when(mockObject.doSomething()).thenThrow(new IOException(), new NoSuchMethodException()).thenThrow(new IllegalArgumentException()) + .thenReturn(10) + .thenThrow(new IOException(), new NoSuchMethodException()).thenThrow(new IllegalArgumentException());\ + """, + """ + Mockito.when(mockObject.doSomething()).thenThrow(new IOException(), new NoSuchMethodException()).thenThrow(new IllegalArgumentException()) + .thenReturn(10) + .thenThrow(new IOException(), new NoSuchMethodException(), new IllegalArgumentException());\ + """ + ), + arguments( + """ + Mockito.when(mockObject.doSomething()).thenThrow(new IOException(), new NoSuchMethodException()).thenThrow(new IllegalArgumentException()) + .thenReturn(10) + .thenThrow(new IOException(), new NoSuchMethodException()).thenThrow(new IllegalArgumentException());\ + """, + """ + Mockito.when(mockObject.doSomething()).thenThrow(new IOException(), new NoSuchMethodException(), new IllegalArgumentException()) + .thenReturn(10) + .thenThrow(new IOException(), new NoSuchMethodException()).thenThrow(new IllegalArgumentException());\ + """ + ), + arguments( " Mockito.when(mockObject.doSomething()).thenThrow(new IOException()).thenThrow(new IllegalArgumentException(\"message\"));", " Mockito.when(mockObject.doSomething()).thenThrow(new IOException(), new IllegalArgumentException(\"message\"));" - }, - { + ), + arguments( " Mockito.when(mockObject.doSomething()).thenThrow(NoSuchMethodException.class).thenThrow(new IllegalArgumentException(\"message\"));", " Mockito.when(mockObject.doSomething()).thenThrow(new NoSuchMethodException(), new IllegalArgumentException(\"message\"));" - } - }; + )); } - private static String[][] givenWillThrowCases() { - return new String[][]{ - { + private static Stream givenWillThrowCases() { + return Stream.of( + arguments( " BDDMockito.given(mockObject.doSomething()).willThrow(IOException.class).willThrow(NoSuchMethodException.class);", " BDDMockito.given(mockObject.doSomething()).willThrow(IOException.class, NoSuchMethodException.class);" - }, - { + ), + arguments( " BDDMockito.given(mockObject.doSomething()).willThrow(IOException.class, NoSuchMethodException.class).willThrow(IllegalArgumentException.class);", " BDDMockito.given(mockObject.doSomething()).willThrow(IOException.class, NoSuchMethodException.class, IllegalArgumentException.class);" - }, - { + ), + arguments( " BDDMockito.given(mockObject.doSomething()).willThrow(IllegalArgumentException.class).willThrow(IOException.class, NoSuchMethodException.class);", " BDDMockito.given(mockObject.doSomething()).willThrow(IllegalArgumentException.class, IOException.class, NoSuchMethodException.class);" - }, - { + ), + arguments( " BDDMockito.given(mockObject.doSomething()).willThrow(new IOException()).willThrow(new IllegalArgumentException(\"message\"));", " BDDMockito.given(mockObject.doSomething()).willThrow(new IOException(), new IllegalArgumentException(\"message\"));" - }, - { + ), + arguments( " BDDMockito.given(mockObject.doSomething()).willThrow(IOException.class).willThrow(new IllegalArgumentException(\"message\"));", " BDDMockito.given(mockObject.doSomething()).willThrow(new IOException(), new IllegalArgumentException(\"message\"));" - }, - { - """ - BDDMockito.given(mockObject.doSomething()).willThrow(new IOException(), new IllegalArgumentException("message")).willThrow(NoSuchMethodException.class) - .willReturn(10) - .willThrow(new IOException(), new IllegalArgumentException()).willThrow(NoSuchMethodException.class);\ -""", - """ - BDDMockito.given(mockObject.doSomething()).willThrow(new IOException(), new IllegalArgumentException("message"), new NoSuchMethodException()) - .willReturn(10) - .willThrow(new IOException(), new IllegalArgumentException()).willThrow(NoSuchMethodException.class);\ -""" - }, - { - """ - BDDMockito.given(mockObject.doSomething()).willThrow(new IllegalArgumentException("message")).willThrow(NoSuchMethodException.class) - .willReturn(10) - .willThrow(new IOException(), new IllegalArgumentException()).willThrow(NoSuchMethodException.class);\ -""", - """ - BDDMockito.given(mockObject.doSomething()).willThrow(new IllegalArgumentException("message"), new NoSuchMethodException()) - .willReturn(10) - .willThrow(new IOException(), new IllegalArgumentException()).willThrow(NoSuchMethodException.class);\ -""" - } - }; + ), + arguments( + """ + BDDMockito.given(mockObject.doSomething()).willThrow(new IOException(), new IllegalArgumentException("message")).willThrow(NoSuchMethodException.class) + .willReturn(10) + .willThrow(new IOException(), new IllegalArgumentException()).willThrow(NoSuchMethodException.class);\ + """, + """ + BDDMockito.given(mockObject.doSomething()).willThrow(new IOException(), new IllegalArgumentException("message"), new NoSuchMethodException()) + .willReturn(10) + .willThrow(new IOException(), new IllegalArgumentException()).willThrow(NoSuchMethodException.class);\ + """ + ), + arguments( + """ + BDDMockito.given(mockObject.doSomething()).willThrow(new IllegalArgumentException("message")).willThrow(NoSuchMethodException.class) + .willReturn(10) + .willThrow(new IOException(), new IllegalArgumentException()).willThrow(NoSuchMethodException.class);\ + """, + """ + BDDMockito.given(mockObject.doSomething()).willThrow(new IllegalArgumentException("message"), new NoSuchMethodException()) + .willReturn(10) + .willThrow(new IOException(), new IllegalArgumentException()).willThrow(NoSuchMethodException.class);\ + """ + )); } - private static String[][] willThrowGivenCases() { - return new String[][]{ - { + private static Stream willThrowGivenCases() { + return Stream.of( + arguments( " BDDMockito.willThrow(IOException.class).willThrow(NoSuchMethodException.class).given(mockObject).doSomething();", " BDDMockito.willThrow(IOException.class, NoSuchMethodException.class).given(mockObject).doSomething();" - }, - { + ), + arguments( " BDDMockito.willThrow(IOException.class, NoSuchMethodException.class).willThrow(IllegalArgumentException.class).given(mockObject).doSomething();", " BDDMockito.willThrow(IOException.class, NoSuchMethodException.class, IllegalArgumentException.class).given(mockObject).doSomething();" - }, - { + ), + arguments( " BDDMockito.willThrow(IllegalArgumentException.class).willThrow(IOException.class, NoSuchMethodException.class).given(mockObject).doSomething();", " BDDMockito.willThrow(IllegalArgumentException.class, IOException.class, NoSuchMethodException.class).given(mockObject).doSomething();" - }, - { + ), + arguments( " BDDMockito.willThrow(new IOException()).willThrow(new IllegalArgumentException(\"message\")).given(mockObject).doSomething();", " BDDMockito.willThrow(new IOException(), new IllegalArgumentException(\"message\")).given(mockObject).doSomething();" - }, - { + ), + arguments( " BDDMockito.willThrow(IOException.class).willThrow(new IllegalArgumentException(\"message\")).given(mockObject).doSomething();", " BDDMockito.willThrow(new IOException(), new IllegalArgumentException(\"message\")).given(mockObject).doSomething();" - } - }; + )); } - private static String[][] toClassesMixedCases() { - return new String[][]{ - { - """ - BDDMockito.willThrow(new IOException(), new IllegalArgumentException()).willThrow(NoSuchMethodException.class) - .willReturn(10) - .willThrow(new IOException(), new IllegalArgumentException()).willThrow(NoSuchMethodException.class) - .given(mockObject.doSomething());\ -""", - """ - BDDMockito.willThrow(IOException.class, IllegalArgumentException.class, NoSuchMethodException.class) - .willReturn(10) - .willThrow(new IOException(), new IllegalArgumentException()).willThrow(NoSuchMethodException.class) - .given(mockObject.doSomething());\ -""" - }, - { - """ - BDDMockito.willThrow(new IOException(), new IllegalArgumentException()).willThrow(NoSuchMethodException.class) - .willReturn(10) - .willThrow(new IOException(), new IllegalArgumentException()).willThrow(NoSuchMethodException.class) - .given(mockObject.doSomething());\ -""", - """ - BDDMockito.willThrow(new IOException(), new IllegalArgumentException()).willThrow(NoSuchMethodException.class) - .willReturn(10) - .willThrow(IOException.class, IllegalArgumentException.class, NoSuchMethodException.class) - .given(mockObject.doSomething());\ -""" - }, - { - """ - BDDMockito.given(mockObject.doSomething()).willThrow(new IOException(), new IllegalArgumentException()).willThrow(NoSuchMethodException.class) - .willReturn(10) - .willThrow(new IOException(), new IllegalArgumentException()).willThrow(NoSuchMethodException.class);\ -""", - """ - BDDMockito.given(mockObject.doSomething()).willThrow(IOException.class, IllegalArgumentException.class, NoSuchMethodException.class) - .willReturn(10) - .willThrow(new IOException(), new IllegalArgumentException()).willThrow(NoSuchMethodException.class);\ -""" - }, - { - """ - BDDMockito.given(mockObject.doSomething()).willThrow(new IOException(), new IllegalArgumentException()).willThrow(NoSuchMethodException.class) - .willReturn(10) - .willThrow(new IOException(), new IllegalArgumentException()).willThrow(NoSuchMethodException.class);\ -""", - """ - BDDMockito.given(mockObject.doSomething()).willThrow(new IOException(), new IllegalArgumentException()).willThrow(NoSuchMethodException.class) - .willReturn(10) - .willThrow(IOException.class, IllegalArgumentException.class, NoSuchMethodException.class);\ -""" - }, - { - """ - BDDMockito.given(mockObject.doSomething()).willThrow(new IOException(), new IllegalArgumentException("message")).willThrow(NoSuchMethodException.class) - .willReturn(10) - .willThrow(new IOException(), new IllegalArgumentException()).willThrow(NoSuchMethodException.class);\ -""", - """ - BDDMockito.given(mockObject.doSomething()).willThrow(new IOException(), new IllegalArgumentException("message")).willThrow(NoSuchMethodException.class) - .willReturn(10) - .willThrow(IOException.class, IllegalArgumentException.class, NoSuchMethodException.class);\ -""" - }, - { + private static Stream toClassesMixedCases() { + return Stream.of( + arguments( + """ + BDDMockito.willThrow(new IOException(), new IllegalArgumentException()).willThrow(NoSuchMethodException.class) + .willReturn(10) + .willThrow(new IOException(), new IllegalArgumentException()).willThrow(NoSuchMethodException.class) + .given(mockObject.doSomething());\ + """, + """ + BDDMockito.willThrow(IOException.class, IllegalArgumentException.class, NoSuchMethodException.class) + .willReturn(10) + .willThrow(new IOException(), new IllegalArgumentException()).willThrow(NoSuchMethodException.class) + .given(mockObject.doSomething());\ + """ + ), + arguments( + """ + BDDMockito.willThrow(new IOException(), new IllegalArgumentException()).willThrow(NoSuchMethodException.class) + .willReturn(10) + .willThrow(new IOException(), new IllegalArgumentException()).willThrow(NoSuchMethodException.class) + .given(mockObject.doSomething());\ + """, + """ + BDDMockito.willThrow(new IOException(), new IllegalArgumentException()).willThrow(NoSuchMethodException.class) + .willReturn(10) + .willThrow(IOException.class, IllegalArgumentException.class, NoSuchMethodException.class) + .given(mockObject.doSomething());\ + """ + ), + arguments( + """ + BDDMockito.given(mockObject.doSomething()).willThrow(new IOException(), new IllegalArgumentException()).willThrow(NoSuchMethodException.class) + .willReturn(10) + .willThrow(new IOException(), new IllegalArgumentException()).willThrow(NoSuchMethodException.class);\ + """, + """ + BDDMockito.given(mockObject.doSomething()).willThrow(IOException.class, IllegalArgumentException.class, NoSuchMethodException.class) + .willReturn(10) + .willThrow(new IOException(), new IllegalArgumentException()).willThrow(NoSuchMethodException.class);\ + """ + ), + arguments( + """ + BDDMockito.given(mockObject.doSomething()).willThrow(new IOException(), new IllegalArgumentException()).willThrow(NoSuchMethodException.class) + .willReturn(10) + .willThrow(new IOException(), new IllegalArgumentException()).willThrow(NoSuchMethodException.class);\ + """, + """ + BDDMockito.given(mockObject.doSomething()).willThrow(new IOException(), new IllegalArgumentException()).willThrow(NoSuchMethodException.class) + .willReturn(10) + .willThrow(IOException.class, IllegalArgumentException.class, NoSuchMethodException.class);\ + """ + ), + arguments( + """ + BDDMockito.given(mockObject.doSomething()).willThrow(new IOException(), new IllegalArgumentException("message")).willThrow(NoSuchMethodException.class) + .willReturn(10) + .willThrow(new IOException(), new IllegalArgumentException()).willThrow(NoSuchMethodException.class);\ + """, + """ + BDDMockito.given(mockObject.doSomething()).willThrow(new IOException(), new IllegalArgumentException("message")).willThrow(NoSuchMethodException.class) + .willReturn(10) + .willThrow(IOException.class, IllegalArgumentException.class, NoSuchMethodException.class);\ + """ + ), + arguments( " BDDMockito.given(mockObject.doSomething()).willThrow(new IOException()).willThrow(IllegalArgumentException.class);", " BDDMockito.given(mockObject.doSomething()).willThrow(IOException.class, IllegalArgumentException.class);" - }, - { + ), + arguments( " BDDMockito.given(mockObject.doSomething()).willThrow(IOException.class).willThrow(new IllegalArgumentException());", " BDDMockito.given(mockObject.doSomething()).willThrow(IOException.class, IllegalArgumentException.class);" - }, - { + ), + arguments( " BDDMockito.given(mockObject.doSomething()).willThrow(new IOException(), new IllegalArgumentException()).willThrow(NoSuchMethodException.class);", " BDDMockito.given(mockObject.doSomething()).willThrow(IOException.class, IllegalArgumentException.class, NoSuchMethodException.class);" - }, - { + ), + arguments( " Mockito.when(mockObject.doSomething()).thenThrow(IOException.class).thenThrow(new IllegalArgumentException());", " Mockito.when(mockObject.doSomething()).thenThrow(IOException.class, IllegalArgumentException.class);" - }, - { + ), + arguments( " Mockito.doThrow(IOException.class).doThrow(new IllegalArgumentException()).when(mockObject).doSomething();", " Mockito.doThrow(IOException.class, IllegalArgumentException.class).when(mockObject).doSomething();" - } - }; + )); } - private static String[][] toThrowableMixedCases() { - return new String[][]{ - { - """ - BDDMockito.willThrow(new IOException(), new IllegalArgumentException()).willThrow(NoSuchMethodException.class) - .willReturn(10) - .willThrow(new IOException(), new IllegalArgumentException()).willThrow(NoSuchMethodException.class) - .given(mockObject.doSomething());\ -""", - """ - BDDMockito.willThrow(new IOException(), new IllegalArgumentException(), new NoSuchMethodException()) - .willReturn(10) - .willThrow(new IOException(), new IllegalArgumentException()).willThrow(NoSuchMethodException.class) - .given(mockObject.doSomething());\ -""" - }, - { - """ - BDDMockito.willThrow(new IOException(), new IllegalArgumentException()).willThrow(NoSuchMethodException.class) - .willReturn(10) - .willThrow(new IOException(), new IllegalArgumentException()).willThrow(NoSuchMethodException.class) - .given(mockObject.doSomething());\ -""", - """ - BDDMockito.willThrow(new IOException(), new IllegalArgumentException()).willThrow(NoSuchMethodException.class) - .willReturn(10) - .willThrow(new IOException(), new IllegalArgumentException(), new NoSuchMethodException()) - .given(mockObject.doSomething());\ -""" - }, - { - """ - BDDMockito.given(mockObject.doSomething()).willThrow(new IOException(), new IllegalArgumentException()).willThrow(NoSuchMethodException.class) - .willReturn(10) - .willThrow(new IOException(), new IllegalArgumentException()).willThrow(NoSuchMethodException.class);\ -""", - """ - BDDMockito.given(mockObject.doSomething()).willThrow(new IOException(), new IllegalArgumentException(), new NoSuchMethodException()) - .willReturn(10) - .willThrow(new IOException(), new IllegalArgumentException()).willThrow(NoSuchMethodException.class);\ -""" - }, - { - """ - BDDMockito.given(mockObject.doSomething()).willThrow(new IOException(), new IllegalArgumentException()).willThrow(NoSuchMethodException.class) - .willReturn(10) - .willThrow(new IOException(), new IllegalArgumentException()).willThrow(NoSuchMethodException.class);\ -""", - """ - BDDMockito.given(mockObject.doSomething()).willThrow(new IOException(), new IllegalArgumentException()).willThrow(NoSuchMethodException.class) - .willReturn(10) - .willThrow(new IOException(), new IllegalArgumentException(), new NoSuchMethodException());\ -""" - }, - { - """ - BDDMockito.given(mockObject.doSomething()).willThrow(new IOException(), new IllegalArgumentException("message")).willThrow(NoSuchMethodException.class) - .willReturn(10) - .willThrow(new IOException(), new IllegalArgumentException()).willThrow(NoSuchMethodException.class);\ -""", - """ - BDDMockito.given(mockObject.doSomething()).willThrow(new IOException(), new IllegalArgumentException("message")).willThrow(NoSuchMethodException.class) - .willReturn(10) - .willThrow(new IOException(), new IllegalArgumentException(), new NoSuchMethodException());\ -""" - }, - { + private static Stream toThrowableMixedCases() { + return Stream.of( + arguments( + """ + BDDMockito.willThrow(new IOException(), new IllegalArgumentException()).willThrow(NoSuchMethodException.class) + .willReturn(10) + .willThrow(new IOException(), new IllegalArgumentException()).willThrow(NoSuchMethodException.class) + .given(mockObject.doSomething());\ + """, + """ + BDDMockito.willThrow(new IOException(), new IllegalArgumentException(), new NoSuchMethodException()) + .willReturn(10) + .willThrow(new IOException(), new IllegalArgumentException()).willThrow(NoSuchMethodException.class) + .given(mockObject.doSomething());\ + """ + ), + arguments( + """ + BDDMockito.willThrow(new IOException(), new IllegalArgumentException()).willThrow(NoSuchMethodException.class) + .willReturn(10) + .willThrow(new IOException(), new IllegalArgumentException()).willThrow(NoSuchMethodException.class) + .given(mockObject.doSomething());\ + """, + """ + BDDMockito.willThrow(new IOException(), new IllegalArgumentException()).willThrow(NoSuchMethodException.class) + .willReturn(10) + .willThrow(new IOException(), new IllegalArgumentException(), new NoSuchMethodException()) + .given(mockObject.doSomething());\ + """ + ), + arguments( + """ + BDDMockito.given(mockObject.doSomething()).willThrow(new IOException(), new IllegalArgumentException()).willThrow(NoSuchMethodException.class) + .willReturn(10) + .willThrow(new IOException(), new IllegalArgumentException()).willThrow(NoSuchMethodException.class);\ + """, + """ + BDDMockito.given(mockObject.doSomething()).willThrow(new IOException(), new IllegalArgumentException(), new NoSuchMethodException()) + .willReturn(10) + .willThrow(new IOException(), new IllegalArgumentException()).willThrow(NoSuchMethodException.class);\ + """ + ), + arguments( + """ + BDDMockito.given(mockObject.doSomething()).willThrow(new IOException(), new IllegalArgumentException()).willThrow(NoSuchMethodException.class) + .willReturn(10) + .willThrow(new IOException(), new IllegalArgumentException()).willThrow(NoSuchMethodException.class);\ + """, + """ + BDDMockito.given(mockObject.doSomething()).willThrow(new IOException(), new IllegalArgumentException()).willThrow(NoSuchMethodException.class) + .willReturn(10) + .willThrow(new IOException(), new IllegalArgumentException(), new NoSuchMethodException());\ + """ + ), + arguments( + """ + BDDMockito.given(mockObject.doSomething()).willThrow(new IOException(), new IllegalArgumentException("message")).willThrow(NoSuchMethodException.class) + .willReturn(10) + .willThrow(new IOException(), new IllegalArgumentException()).willThrow(NoSuchMethodException.class);\ + """, + """ + BDDMockito.given(mockObject.doSomething()).willThrow(new IOException(), new IllegalArgumentException("message")).willThrow(NoSuchMethodException.class) + .willReturn(10) + .willThrow(new IOException(), new IllegalArgumentException(), new NoSuchMethodException());\ + """ + ), + arguments( " BDDMockito.given(mockObject.doSomething()).willThrow(new IOException()).willThrow(IllegalArgumentException.class);", " BDDMockito.given(mockObject.doSomething()).willThrow(new IOException(), new IllegalArgumentException());" - }, - { + ), + arguments( " BDDMockito.given(mockObject.doSomething()).willThrow(IOException.class).willThrow(new IllegalArgumentException());", " BDDMockito.given(mockObject.doSomething()).willThrow(new IOException(), new IllegalArgumentException());" - }, - { + ), + arguments( " BDDMockito.given(mockObject.doSomething()).willThrow(new IOException(), new IllegalArgumentException()).willThrow(NoSuchMethodException.class);", " BDDMockito.given(mockObject.doSomething()).willThrow(new IOException(), new IllegalArgumentException(), new NoSuchMethodException());" - }, - { + ), + arguments( " Mockito.when(mockObject.doSomething()).thenThrow(IOException.class).thenThrow(new IllegalArgumentException());", " Mockito.when(mockObject.doSomething()).thenThrow(new IOException(), new IllegalArgumentException());" - }, - { + ), + arguments( " Mockito.doThrow(IOException.class).doThrow(new IllegalArgumentException()).when(mockObject).doSomething();", " Mockito.doThrow(new IOException(), new IllegalArgumentException()).when(mockObject).doSomething();" - } - }; + )); } - private static String[][] mockedStaticWhenThenThrowsCases() { - return new String[][]{ - { + private static Stream mockedStaticWhenThenThrowsCases() { + return Stream.of( + arguments( " mock.when(List::of).thenThrow(IOException.class).thenThrow(NoSuchMethodException.class);", " mock.when(List::of).thenThrow(IOException.class, NoSuchMethodException.class);" - }, - { + ), + arguments( " mock.when(List::of).thenThrow(IOException.class, NoSuchMethodException.class).thenThrow(IllegalArgumentException.class);", " mock.when(List::of).thenThrow(IOException.class, NoSuchMethodException.class, IllegalArgumentException.class);" - }, - { + ), + arguments( " mock.when(List::of).thenThrow(IllegalArgumentException.class).thenThrow(IOException.class, NoSuchMethodException.class);", " mock.when(List::of).thenThrow(IllegalArgumentException.class, IOException.class, NoSuchMethodException.class);" - }, - { + ), + arguments( " mock.when(List::of).thenThrow(new IOException()).thenThrow(new IllegalArgumentException(\"message\"));", " mock.when(List::of).thenThrow(new IOException(), new IllegalArgumentException(\"message\"));" - }, - { + ), + arguments( " mock.when(List::of).thenThrow(IOException.class).thenThrow(new IllegalArgumentException(\"message\"));", " mock.when(List::of).thenThrow(new IOException(), new IllegalArgumentException(\"message\"));" - }, - { - """ - mock.when(List::of).thenThrow(new IOException(), new IllegalArgumentException("message")).thenThrow(NoSuchMethodException.class) - .thenReturn(List.of()) - .thenThrow(new IOException(), new IllegalArgumentException()).thenThrow(NoSuchMethodException.class);\ -""", - """ - mock.when(List::of).thenThrow(new IOException(), new IllegalArgumentException("message"), new NoSuchMethodException()) - .thenReturn(List.of()) - .thenThrow(new IOException(), new IllegalArgumentException()).thenThrow(NoSuchMethodException.class);\ -""" - }, - { - """ - mock.when(List::of).thenThrow(new IllegalArgumentException("message")).thenThrow(NoSuchMethodException.class) - .thenReturn(List.of()) - .thenThrow(new IOException(), new IllegalArgumentException()).thenThrow(NoSuchMethodException.class);\ -""", - """ - mock.when(List::of).thenThrow(new IllegalArgumentException("message"), new NoSuchMethodException()) - .thenReturn(List.of()) - .thenThrow(new IOException(), new IllegalArgumentException()).thenThrow(NoSuchMethodException.class);\ -""" - } - }; + ), + arguments( + """ + mock.when(List::of).thenThrow(new IOException(), new IllegalArgumentException("message")).thenThrow(NoSuchMethodException.class) + .thenReturn(List.of()) + .thenThrow(new IOException(), new IllegalArgumentException()).thenThrow(NoSuchMethodException.class);\ + """, + """ + mock.when(List::of).thenThrow(new IOException(), new IllegalArgumentException("message"), new NoSuchMethodException()) + .thenReturn(List.of()) + .thenThrow(new IOException(), new IllegalArgumentException()).thenThrow(NoSuchMethodException.class);\ + """ + ), + arguments( + """ + mock.when(List::of).thenThrow(new IllegalArgumentException("message")).thenThrow(NoSuchMethodException.class) + .thenReturn(List.of()) + .thenThrow(new IOException(), new IllegalArgumentException()).thenThrow(NoSuchMethodException.class);\ + """, + """ + mock.when(List::of).thenThrow(new IllegalArgumentException("message"), new NoSuchMethodException()) + .thenReturn(List.of()) + .thenThrow(new IOException(), new IllegalArgumentException()).thenThrow(NoSuchMethodException.class);\ + """ + )); } - private static String[][] doThrowWhenCases() { - return new String[][]{ - { + private static Stream doThrowWhenCases() { + return Stream.of( + arguments( " Mockito.doThrow(IllegalArgumentException.class).doThrow(NoSuchMethodException.class).when(mockObject).doSomething();", " Mockito.doThrow(IllegalArgumentException.class, NoSuchMethodException.class).when(mockObject).doSomething();" - }, - { + ), + arguments( " Mockito.doThrow(IllegalArgumentException.class, NoSuchMethodException.class).doThrow(IOException.class).when(mockObject).doSomething();", " Mockito.doThrow(IllegalArgumentException.class, NoSuchMethodException.class, IOException.class).when(mockObject).doSomething();" - }, - { + ), + arguments( " Mockito.doThrow(IllegalArgumentException.class).doThrow(IOException.class, NoSuchMethodException.class).when(mockObject).doSomething();", " Mockito.doThrow(IllegalArgumentException.class, IOException.class, NoSuchMethodException.class).when(mockObject).doSomething();" - }, - { + ), + arguments( " Mockito.doThrow(new IllegalArgumentException()).doThrow(new IOException()).when(mockObject).doSomething();", " Mockito.doThrow(new IllegalArgumentException(), new IOException()).when(mockObject).doSomething();" - }, - { + ), + arguments( " Mockito.doThrow(new IllegalArgumentException(), new NoSuchMethodException()).doThrow(new IOException()).when(mockObject).doSomething();", " Mockito.doThrow(new IllegalArgumentException(), new NoSuchMethodException(), new IOException()).when(mockObject).doSomething();" - }, - { - """ - Mockito.doThrow(new IllegalArgumentException(), new NoSuchMethodException()).doThrow(new IOException()) - .doReturn(10) - .doThrow(new IllegalArgumentException(), new NoSuchMethodException()).doThrow(new IOException()) - .when(mockObject).doSomething();\ -""", - """ - Mockito.doThrow(new IllegalArgumentException(), new NoSuchMethodException(), new IOException()) - .doReturn(10) - .doThrow(new IllegalArgumentException(), new NoSuchMethodException()).doThrow(new IOException()) - .when(mockObject).doSomething();\ -""" - }, - { - """ - Mockito.doThrow(new IllegalArgumentException(), new NoSuchMethodException()).doThrow(new IOException()) - .doReturn(10) - .doThrow(new IllegalArgumentException(), new NoSuchMethodException()).doThrow(new IOException()) - .when(mockObject).doSomething();\ -""", - """ - Mockito.doThrow(new IllegalArgumentException(), new NoSuchMethodException()).doThrow(new IOException()) - .doReturn(10) - .doThrow(new IllegalArgumentException(), new NoSuchMethodException(), new IOException()) - .when(mockObject).doSomething();\ -""" - }, - { - """ - Mockito.doThrow(IllegalArgumentException.class, NoSuchMethodException.class).doThrow(IOException.class) - .doReturn(10) - .doThrow(IllegalArgumentException.class, NoSuchMethodException.class).doThrow(IOException.class) - .when(mockObject).doSomething();\ -""", - """ - Mockito.doThrow(IllegalArgumentException.class, NoSuchMethodException.class, IOException.class) - .doReturn(10) - .doThrow(IllegalArgumentException.class, NoSuchMethodException.class).doThrow(IOException.class) - .when(mockObject).doSomething();\ -""" - }, - { - """ - Mockito.doThrow(IllegalArgumentException.class, NoSuchMethodException.class).doThrow(IOException.class) - .doReturn(10) - .doThrow(IllegalArgumentException.class, NoSuchMethodException.class).doThrow(IOException.class) - .when(mockObject).doSomething();\ -""", - """ - Mockito.doThrow(IllegalArgumentException.class, NoSuchMethodException.class).doThrow(IOException.class) - .doReturn(10) - .doThrow(IllegalArgumentException.class, NoSuchMethodException.class, IOException.class) - .when(mockObject).doSomething();\ -""" - }, - { - """ - Mockito.doReturn(5) - .doThrow(new IllegalArgumentException(), new NoSuchMethodException()).doThrow(new IOException()) - .doReturn(10) - .doThrow(new IllegalArgumentException(), new NoSuchMethodException()).doThrow(new IOException()) - .when(mockObject).doSomething();\ -""", - """ - Mockito.doReturn(5) - .doThrow(new IllegalArgumentException(), new NoSuchMethodException(), new IOException()) - .doReturn(10) - .doThrow(new IllegalArgumentException(), new NoSuchMethodException()).doThrow(new IOException()) - .when(mockObject).doSomething();\ -""" - }, - { - """ - Mockito.doReturn(5) - .doThrow(new IllegalArgumentException(), new NoSuchMethodException()).doThrow(new IOException()) - .doReturn(10) - .doThrow(new IllegalArgumentException(), new NoSuchMethodException()).doThrow(new IOException()) - .when(mockObject).doSomething();\ -""", - """ - Mockito.doReturn(5) - .doThrow(new IllegalArgumentException(), new NoSuchMethodException()).doThrow(new IOException()) - .doReturn(10) - .doThrow(new IllegalArgumentException(), new NoSuchMethodException(), new IOException()) - .when(mockObject).doSomething();\ -""" - }, - { + ), + arguments( + """ + Mockito.doThrow(new IllegalArgumentException(), new NoSuchMethodException()).doThrow(new IOException()) + .doReturn(10) + .doThrow(new IllegalArgumentException(), new NoSuchMethodException()).doThrow(new IOException()) + .when(mockObject).doSomething();\ + """, + """ + Mockito.doThrow(new IllegalArgumentException(), new NoSuchMethodException(), new IOException()) + .doReturn(10) + .doThrow(new IllegalArgumentException(), new NoSuchMethodException()).doThrow(new IOException()) + .when(mockObject).doSomething();\ + """ + ), + arguments( + """ + Mockito.doThrow(new IllegalArgumentException(), new NoSuchMethodException()).doThrow(new IOException()) + .doReturn(10) + .doThrow(new IllegalArgumentException(), new NoSuchMethodException()).doThrow(new IOException()) + .when(mockObject).doSomething();\ + """, + """ + Mockito.doThrow(new IllegalArgumentException(), new NoSuchMethodException()).doThrow(new IOException()) + .doReturn(10) + .doThrow(new IllegalArgumentException(), new NoSuchMethodException(), new IOException()) + .when(mockObject).doSomething();\ + """ + ), + arguments( + """ + Mockito.doThrow(IllegalArgumentException.class, NoSuchMethodException.class).doThrow(IOException.class) + .doReturn(10) + .doThrow(IllegalArgumentException.class, NoSuchMethodException.class).doThrow(IOException.class) + .when(mockObject).doSomething();\ + """, + """ + Mockito.doThrow(IllegalArgumentException.class, NoSuchMethodException.class, IOException.class) + .doReturn(10) + .doThrow(IllegalArgumentException.class, NoSuchMethodException.class).doThrow(IOException.class) + .when(mockObject).doSomething();\ + """ + ), + arguments( + """ + Mockito.doThrow(IllegalArgumentException.class, NoSuchMethodException.class).doThrow(IOException.class) + .doReturn(10) + .doThrow(IllegalArgumentException.class, NoSuchMethodException.class).doThrow(IOException.class) + .when(mockObject).doSomething();\ + """, + """ + Mockito.doThrow(IllegalArgumentException.class, NoSuchMethodException.class).doThrow(IOException.class) + .doReturn(10) + .doThrow(IllegalArgumentException.class, NoSuchMethodException.class, IOException.class) + .when(mockObject).doSomething();\ + """ + ), + arguments( + """ + Mockito.doReturn(5) + .doThrow(new IllegalArgumentException(), new NoSuchMethodException()).doThrow(new IOException()) + .doReturn(10) + .doThrow(new IllegalArgumentException(), new NoSuchMethodException()).doThrow(new IOException()) + .when(mockObject).doSomething();\ + """, + """ + Mockito.doReturn(5) + .doThrow(new IllegalArgumentException(), new NoSuchMethodException(), new IOException()) + .doReturn(10) + .doThrow(new IllegalArgumentException(), new NoSuchMethodException()).doThrow(new IOException()) + .when(mockObject).doSomething();\ + """ + ), + arguments( + """ + Mockito.doReturn(5) + .doThrow(new IllegalArgumentException(), new NoSuchMethodException()).doThrow(new IOException()) + .doReturn(10) + .doThrow(new IllegalArgumentException(), new NoSuchMethodException()).doThrow(new IOException()) + .when(mockObject).doSomething();\ + """, + """ + Mockito.doReturn(5) + .doThrow(new IllegalArgumentException(), new NoSuchMethodException()).doThrow(new IOException()) + .doReturn(10) + .doThrow(new IllegalArgumentException(), new NoSuchMethodException(), new IOException()) + .when(mockObject).doSomething();\ + """ + ), + arguments( " Mockito.doThrow(new IllegalArgumentException()).doThrow(new IOException(\"message\")).when(mockObject).doSomething();", " Mockito.doThrow(new IllegalArgumentException(), new IOException(\"message\")).when(mockObject).doSomething();" - }, - { + ), + arguments( " Mockito.doThrow(IllegalArgumentException.class).doThrow(new IOException(\"message\")).when(mockObject).doSomething();", " Mockito.doThrow(new IllegalArgumentException(), new IOException(\"message\")).when(mockObject).doSomething();" - }, - { + ), + arguments( " Mockito.doThrow(IllegalArgumentException.class).doThrow(new IOException()).doThrow(new IOException(\"message\")).when(mockObject).doSomething();", " Mockito.doThrow(new IllegalArgumentException(), new IOException(), new IOException(\"message\")).when(mockObject).doSomething();" - } - }; + )); } @Override @@ -563,32 +561,32 @@ void testReplacesMockedStaticWhenThenThrows(String before, String after) { private String createClassText(String beforeOrAfter) { return "import org.mockito.Mockito;\n" + - "import org.mockito.BDDMockito;\n" + - "import java.io.IOException;\n" + - "\n" + - "class QuickFix {\n" + - " void testMethod() {\n" + - " MockObject mockObject = Mockito.mock(MockObject.class);\n" + - beforeOrAfter + "\n" + - " }\n" + - "\n" + - MOCK_OBJECT_CLASS + - "}"; + "import org.mockito.BDDMockito;\n" + + "import java.io.IOException;\n" + + "\n" + + "class QuickFix {\n" + + " void testMethod() {\n" + + " MockObject mockObject = Mockito.mock(MockObject.class);\n" + + beforeOrAfter + "\n" + + " }\n" + + "\n" + + MOCK_OBJECT_CLASS + + "}"; } private String createMockedStaticClassText(String beforeOrAfter) { return "import org.mockito.Mockito;\n" + - "import org.mockito.MockedStatic;\n" + - "import java.util.Collections;\n" + - "import java.util.List;\n" + - "import java.io.IOException;\n" + - "\n" + - "class QuickFix {\n" + - " void testMethod() {\n" + - " try (MockedStatic mock = Mockito.mockStatic(List.class)) {\n" + - beforeOrAfter + "\n" + - " }\n" + - " }\n" + - "}"; + "import org.mockito.MockedStatic;\n" + + "import java.util.Collections;\n" + + "import java.util.List;\n" + + "import java.io.IOException;\n" + + "\n" + + "class QuickFix {\n" + + " void testMethod() {\n" + + " try (MockedStatic mock = Mockito.mockStatic(List.class)) {\n" + + beforeOrAfter + "\n" + + " }\n" + + " }\n" + + "}"; } }