@@ -5,6 +5,7 @@ import examples.SummaryTestCaseGeneratorTest
55import org.junit.jupiter.api.Test
66import org.junit.jupiter.api.extension.ExtendWith
77import org.utbot.examples.controlflow.Switch
8+ import org.utbot.examples.exceptions.ExceptionExamples
89import org.utbot.framework.plugin.api.MockStrategyApi
910import org.utbot.testing.DoNotCalculate
1011
@@ -16,19 +17,19 @@ class SummarySwitchTest : SummaryTestCaseGeneratorTest(
1617 fun testSimpleSwitch () {
1718 val summary1 = " @utbot.classUnderTest {@link Switch}\n " +
1819 " @utbot.methodUnderTest {@link org.utbot.examples.controlflow.Switch#simpleSwitch(int)}\n " +
19- " @utbot.activatesSwitch {@code case 10}\n " +
20+ " @utbot.activatesSwitch {@code switch(x) case: 10}\n " +
2021 " @utbot.returnsFrom {@code return 10;}"
2122 val summary2 = " @utbot.classUnderTest {@link Switch}\n " +
2223 " @utbot.methodUnderTest {@link org.utbot.examples.controlflow.Switch#simpleSwitch(int)}\n " +
23- " @utbot.activatesSwitch {@code case default}\n " +
24+ " @utbot.activatesSwitch {@code switch(x) case: default}\n " +
2425 " @utbot.returnsFrom {@code return -1;}"
2526 val summary3 = " @utbot.classUnderTest {@link Switch}\n " +
2627 " @utbot.methodUnderTest {@link org.utbot.examples.controlflow.Switch#simpleSwitch(int)}\n " +
27- " @utbot.activatesSwitch {@code case 12}\n " +
28+ " @utbot.activatesSwitch {@code switch(x) case: 12}\n " +
2829 " @utbot.returnsFrom {@code return 12;}"
2930 val summary4 = " @utbot.classUnderTest {@link Switch}\n " +
3031 " @utbot.methodUnderTest {@link org.utbot.examples.controlflow.Switch#simpleSwitch(int)}\n " +
31- " @utbot.activatesSwitch {@code case 13}\n " +
32+ " @utbot.activatesSwitch {@code switch(x) case: 13}\n " +
3233 " @utbot.returnsFrom {@code return 13;}"
3334
3435 val methodName1 = " testSimpleSwitch_Return10"
@@ -37,7 +38,7 @@ class SummarySwitchTest : SummaryTestCaseGeneratorTest(
3738 val methodName4 = " testSimpleSwitch_Return13"
3839
3940 val displayName1 = " switch(x) case: 10 -> return 10"
40- val displayName2 = " switch(x) case: Default -> return -1"
41+ val displayName2 = " switch(x) case: default -> return -1"
4142 val displayName3 = " switch(x) case: 12 -> return 12"
4243 val displayName4 = " switch(x) case: 13 -> return 13"
4344
@@ -73,40 +74,39 @@ class SummarySwitchTest : SummaryTestCaseGeneratorTest(
7374 fun testCharToIntSwitch () {
7475 val summary1 = " @utbot.classUnderTest {@link Switch}\n " +
7576 " @utbot.methodUnderTest {@link org.utbot.examples.controlflow.Switch#charToIntSwitch(char)}\n " +
76- " @utbot.activatesSwitch {@code case 'C'}\n " +
77+ " @utbot.activatesSwitch {@code switch(c) case: 'C'}\n " +
7778 " @utbot.returnsFrom {@code return 100;}\n "
7879 val summary2 = " @utbot.classUnderTest {@link Switch}\n " +
7980 " @utbot.methodUnderTest {@link org.utbot.examples.controlflow.Switch#charToIntSwitch(char)}\n " +
80- " @utbot.activatesSwitch {@code case 'V'}\n " +
81+ " @utbot.activatesSwitch {@code switch(c) case: 'V'}\n " +
8182 " @utbot.returnsFrom {@code return 5;}\n "
8283 val summary3 = " @utbot.classUnderTest {@link Switch}\n " +
8384 " @utbot.methodUnderTest {@link org.utbot.examples.controlflow.Switch#charToIntSwitch(char)}\n " +
84- " @utbot.activatesSwitch {@code case 'I'}\n " +
85+ " @utbot.activatesSwitch {@code switch(c) case: 'I'}\n " +
8586 " @utbot.returnsFrom {@code return 1;}\n "
8687 val summary4 = " @utbot.classUnderTest {@link Switch}\n " +
8788 " @utbot.methodUnderTest {@link org.utbot.examples.controlflow.Switch#charToIntSwitch(char)}\n " +
88- " @utbot.activatesSwitch {@code case 'X'}\n " +
89+ " @utbot.activatesSwitch {@code switch(c) case: 'X'}\n " +
8990 " @utbot.returnsFrom {@code return 10;}\n "
9091 val summary5 = " @utbot.classUnderTest {@link Switch}\n " +
9192 " @utbot.methodUnderTest {@link org.utbot.examples.controlflow.Switch#charToIntSwitch(char)}\n " +
92- " @utbot.activatesSwitch {@code case 'M'}\n " +
93+ " @utbot.activatesSwitch {@code switch(c) case: 'M'}\n " +
9394 " @utbot.returnsFrom {@code return 1000;}\n "
9495 val summary6 = " @utbot.classUnderTest {@link Switch}\n " +
9596 " @utbot.methodUnderTest {@link org.utbot.examples.controlflow.Switch#charToIntSwitch(char)}\n " +
96- " @utbot.activatesSwitch {@code case 'D'}\n " +
97+ " @utbot.activatesSwitch {@code switch(c) case: 'D'}\n " +
9798 " @utbot.returnsFrom {@code return 500;}\n "
9899 val summary7 = " @utbot.classUnderTest {@link Switch}\n " +
99100 " @utbot.methodUnderTest {@link org.utbot.examples.controlflow.Switch#charToIntSwitch(char)}\n " +
100- " @utbot.activatesSwitch {@code case 'L'}\n " +
101+ " @utbot.activatesSwitch {@code switch(c) case: 'L'}\n " +
101102 " @utbot.returnsFrom {@code return 50;}\n "
102103 val summary8 = " @utbot.classUnderTest {@link Switch}\n " +
103104 " @utbot.methodUnderTest {@link org.utbot.examples.controlflow.Switch#charToIntSwitch(char)}\n " +
104105 " @utbot.invokes {@link java.lang.StringBuilder#append(java.lang.String)}\n " +
105106 " @utbot.invokes {@link java.lang.StringBuilder#append(char)}\n " +
106107 " @utbot.invokes {@link java.lang.StringBuilder#toString()}\n " +
107- " @utbot.activatesSwitch {@code case default}\n " +
108- " @utbot.throwsException {@link java.lang.IllegalArgumentException} in: default:\n " +
109- " throw new IllegalArgumentException(\" Unrecognized symbol: \" + c);\n "
108+ " @utbot.activatesSwitch {@code switch(c) case: default}\n " +
109+ " @utbot.throwsException {@link java.lang.IllegalArgumentException} when: switch(c) case: default\n "
110110
111111 val methodName1 = " testCharToIntSwitch_Return100"
112112 val methodName2 = " testCharToIntSwitch_Return5"
@@ -115,7 +115,7 @@ class SummarySwitchTest : SummaryTestCaseGeneratorTest(
115115 val methodName5 = " testCharToIntSwitch_Return1000"
116116 val methodName6 = " testCharToIntSwitch_Return500"
117117 val methodName7 = " testCharToIntSwitch_Return50"
118- val methodName8 = " testCharToIntSwitch_StringBuilderToString "
118+ val methodName8 = " testCharToIntSwitch_ThrowIllegalArgumentException "
119119
120120 val displayName1 = " switch(c) case: 'C' -> return 100"
121121 val displayName2 = " switch(c) case: 'V' -> return 5"
@@ -124,7 +124,7 @@ class SummarySwitchTest : SummaryTestCaseGeneratorTest(
124124 val displayName5 = " switch(c) case: 'M' -> return 1000"
125125 val displayName6 = " switch(c) case: 'D' -> return 500"
126126 val displayName7 = " switch(c) case: 'L' -> return 50"
127- val displayName8 = """ default: throw new IllegalArgumentException("Unrecognized symbol: " + c) -> ThrowIllegalArgumentException"" "
127+ val displayName8 = " switch( c) case: default -> ThrowIllegalArgumentException"
128128
129129 val summaryKeys = listOf (
130130 summary1,
@@ -165,4 +165,34 @@ class SummarySwitchTest : SummaryTestCaseGeneratorTest(
165165
166166 summaryCheck(method, mockStrategy, coverage, summaryKeys, methodNames, displayNames)
167167 }
168- }
168+
169+ @Test
170+ fun testThrowExceptionInSwitchArgument () {
171+ val summary1 = " @utbot.classUnderTest {@link Switch}\n " +
172+ " @utbot.methodUnderTest {@link org.utbot.examples.controlflow.Switch#throwExceptionInSwitchArgument()}\n " +
173+ " @utbot.invokes org.utbot.examples.controlflow.Switch#getChar()\n " +
174+ " @utbot.throwsException {@link java.lang.RuntimeException} in: switch(getChar())\n "
175+
176+ val methodName1 = " testThrowExceptionInSwitchArgument_ThrowRuntimeException"
177+
178+ val displayName1 = " switch(getChar()) -> ThrowRuntimeException"
179+
180+ val summaryKeys = listOf (
181+ summary1,
182+ )
183+
184+ val displayNames = listOf (
185+ displayName1,
186+ )
187+
188+ val methodNames = listOf (
189+ methodName1,
190+ )
191+
192+ val method = Switch ::throwExceptionInSwitchArgument
193+ val mockStrategy = MockStrategyApi .NO_MOCKS
194+ val coverage = DoNotCalculate
195+
196+ summaryCheck(method, mockStrategy, coverage, summaryKeys, methodNames, displayNames)
197+ }
198+ }
0 commit comments