-
Notifications
You must be signed in to change notification settings - Fork 46
Handle RecursionAssignment, SwitchCase, and CaughtException statement types in CustomJavaDocCommentBuilder #888
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
71 changes: 71 additions & 0 deletions
71
utbot-summary-tests/src/test/kotlin/examples/controlflow/SummarySwitchTest.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package examples.controlflow | ||
|
||
import examples.CustomJavaDocTagsEnabler | ||
import examples.SummaryTestCaseGeneratorTest | ||
import org.junit.jupiter.api.Test | ||
import org.junit.jupiter.api.extension.ExtendWith | ||
import org.utbot.examples.controlflow.Switch | ||
import org.utbot.framework.plugin.api.MockStrategyApi | ||
import org.utbot.tests.infrastructure.DoNotCalculate | ||
|
||
@ExtendWith(CustomJavaDocTagsEnabler::class) | ||
class SummarySwitchTest : SummaryTestCaseGeneratorTest( | ||
Switch::class | ||
) { | ||
@Test | ||
fun testDifferentExceptions() { | ||
val summary1 = "@utbot.classUnderTest {@link Switch}\n" + | ||
"@utbot.methodUnderTest {@link org.utbot.examples.controlflow.Switch#simpleSwitch(int)}\n" + | ||
"@utbot.activatesSwitch {@code case 10}\n" + | ||
"@utbot.returnsFrom {@code return 10;}" | ||
val summary2 = "@utbot.classUnderTest {@link Switch}\n" + | ||
"@utbot.methodUnderTest {@link org.utbot.examples.controlflow.Switch#simpleSwitch(int)}\n" + | ||
"@utbot.activatesSwitch {@code case default}\n" + | ||
"@utbot.returnsFrom {@code return -1;}" | ||
val summary3 = "@utbot.classUnderTest {@link Switch}\n" + | ||
"@utbot.methodUnderTest {@link org.utbot.examples.controlflow.Switch#simpleSwitch(int)}\n" + | ||
"@utbot.activatesSwitch {@code case 12}\n" + | ||
"@utbot.returnsFrom {@code return 12;}" | ||
val summary4 = "@utbot.classUnderTest {@link Switch}\n" + | ||
"@utbot.methodUnderTest {@link org.utbot.examples.controlflow.Switch#simpleSwitch(int)}\n" + | ||
"@utbot.activatesSwitch {@code case 13}\n" + | ||
"@utbot.returnsFrom {@code return 13;}" | ||
|
||
val methodName1 = "testSimpleSwitch_Return10" | ||
val methodName2 = "testSimpleSwitch_ReturnNegative1" | ||
val methodName3 = "testSimpleSwitch_Return12" | ||
val methodName4 = "testSimpleSwitch_Return13" | ||
|
||
val displayName1 = "switch(x) case: 10 -> return 10" | ||
val displayName2 = "switch(x) case: Default -> return -1" | ||
val displayName3 = "switch(x) case: 12 -> return 12" | ||
val displayName4 = "switch(x) case: 13 -> return 13" | ||
|
||
val summaryKeys = listOf( | ||
summary1, | ||
summary2, | ||
summary3, | ||
summary4 | ||
) | ||
|
||
val displayNames = listOf( | ||
displayName1, | ||
displayName2, | ||
displayName3, | ||
displayName4 | ||
) | ||
|
||
val methodNames = listOf( | ||
methodName1, | ||
methodName2, | ||
methodName3, | ||
methodName4 | ||
) | ||
|
||
val method = Switch::simpleSwitch | ||
val mockStrategy = MockStrategyApi.NO_MOCKS | ||
val coverage = DoNotCalculate | ||
|
||
summaryCheck(method, mockStrategy, coverage, summaryKeys, methodNames, displayNames) | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
utbot-summary-tests/src/test/kotlin/examples/exceptions/SummaryExceptionExampleTest.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package examples.exceptions | ||
|
||
import examples.CustomJavaDocTagsEnabler | ||
import examples.SummaryTestCaseGeneratorTest | ||
import org.junit.jupiter.api.Test | ||
import org.junit.jupiter.api.extension.ExtendWith | ||
import org.utbot.examples.exceptions.ExceptionExamples | ||
import org.utbot.framework.plugin.api.MockStrategyApi | ||
import org.utbot.tests.infrastructure.DoNotCalculate | ||
|
||
@ExtendWith(CustomJavaDocTagsEnabler::class) | ||
class SummaryExceptionExampleTest : SummaryTestCaseGeneratorTest( | ||
ExceptionExamples::class | ||
) { | ||
@Test | ||
fun testDifferentExceptions() { | ||
val summary1 = "@utbot.classUnderTest {@link ExceptionExamples}\n" + | ||
"@utbot.methodUnderTest {@link org.utbot.examples.exceptions.ExceptionExamples#nestedExceptions(int)}\n" + | ||
"@utbot.returnsFrom {@code return checkAll(i);}" | ||
val summary2 = "@utbot.classUnderTest {@link ExceptionExamples}\n" + | ||
"@utbot.methodUnderTest {@link org.utbot.examples.exceptions.ExceptionExamples#nestedExceptions(int)}\n" + | ||
"@utbot.returnsFrom {@code return -100;}\n" + | ||
"@utbot.caughtException {@code RuntimeException e}" | ||
val summary3 = "@utbot.classUnderTest {@link ExceptionExamples}\n" + | ||
"@utbot.methodUnderTest {@link org.utbot.examples.exceptions.ExceptionExamples#nestedExceptions(int)}\n" + | ||
"@utbot.returnsFrom {@code return 100;}\n" + | ||
"@utbot.caughtException {@code NullPointerException e}" | ||
|
||
val methodName1 = "testNestedExceptions_ReturnCheckAll" | ||
val methodName2 = "testNestedExceptions_CatchRuntimeException" | ||
val methodName3 = "testNestedExceptions_CatchNullPointerException" | ||
|
||
val displayName1 = "-> return checkAll(i)" | ||
val displayName2 = "Catch (RuntimeException e) -> return -100" | ||
val displayName3 = "Catch (NullPointerException e) -> return 100" | ||
|
||
val summaryKeys = listOf( | ||
summary1, | ||
summary2, | ||
summary3 | ||
) | ||
|
||
val displayNames = listOf( | ||
displayName1, | ||
displayName2, | ||
displayName3 | ||
) | ||
|
||
val methodNames = listOf( | ||
methodName1, | ||
methodName2, | ||
methodName3 | ||
) | ||
|
||
val method = ExceptionExamples::nestedExceptions | ||
val mockStrategy = MockStrategyApi.NO_MOCKS | ||
val coverage = DoNotCalculate | ||
|
||
summaryCheck(method, mockStrategy, coverage, summaryKeys, methodNames, displayNames) | ||
} | ||
} |
124 changes: 124 additions & 0 deletions
124
utbot-summary-tests/src/test/kotlin/examples/recursion/SummaryRecursionTest.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
package examples.recursion | ||
|
||
import examples.CustomJavaDocTagsEnabler | ||
import examples.SummaryTestCaseGeneratorTest | ||
import org.junit.jupiter.api.Test | ||
import org.junit.jupiter.api.extension.ExtendWith | ||
import org.utbot.examples.recursion.Recursion | ||
import org.utbot.framework.plugin.api.MockStrategyApi | ||
import org.utbot.tests.infrastructure.DoNotCalculate | ||
|
||
@ExtendWith(CustomJavaDocTagsEnabler::class) | ||
class SummaryRecursionTest : SummaryTestCaseGeneratorTest( | ||
Recursion::class | ||
) { | ||
@Test | ||
fun testFib() { | ||
val summary1 = "@utbot.classUnderTest {@link Recursion}\n" + | ||
"@utbot.methodUnderTest {@link org.utbot.examples.recursion.Recursion#fib(int)}\n" + | ||
"@utbot.executesCondition {@code (n == 0): False},\n" + | ||
"{@code (n == 1): True}\n" + | ||
"@utbot.returnsFrom {@code return 1;}" | ||
val summary2 = "@utbot.classUnderTest {@link Recursion}\n" + | ||
"@utbot.methodUnderTest {@link org.utbot.examples.recursion.Recursion#fib(int)}\n" + | ||
"@utbot.executesCondition {@code (n == 0): True}\n" + | ||
"@utbot.returnsFrom {@code return 0;}\n" | ||
val summary3 = "@utbot.classUnderTest {@link Recursion}\n" + | ||
"@utbot.methodUnderTest {@link org.utbot.examples.recursion.Recursion#fib(int)}\n" + | ||
"@utbot.executesCondition {@code (n == 1): False}\n" + | ||
"@utbot.returnsFrom {@code return fib(n - 1) + fib(n - 2);}" | ||
val summary4 = "@utbot.classUnderTest {@link Recursion}\n" + | ||
"@utbot.methodUnderTest {@link org.utbot.examples.recursion.Recursion#fib(int)}\n" + | ||
"@utbot.executesCondition {@code (n < 0): True}\n" + | ||
"@utbot.throwsException {@link java.lang.IllegalArgumentException} in: n < 0" | ||
|
||
val methodName1 = "testFib_Return1" | ||
val methodName2 = "testFib_ReturnZero" | ||
val methodName3 = "testFib_NNotEquals1" | ||
val methodName4 = "testFib_NLessThanZero" | ||
|
||
val displayName1 = "n == 0 : False -> return 1" | ||
val displayName2 = "n == 0 : True -> return 0" | ||
val displayName3 = "return 1 -> return 0" //it looks weird | ||
val displayName4 = "n < 0 -> ThrowIllegalArgumentException" | ||
|
||
val summaryKeys = listOf( | ||
summary1, | ||
summary2, | ||
summary3, | ||
summary4 | ||
) | ||
|
||
val displayNames = listOf( | ||
displayName1, | ||
displayName2, | ||
displayName3, | ||
displayName4 | ||
) | ||
|
||
val methodNames = listOf( | ||
methodName1, | ||
methodName2, | ||
methodName3, | ||
methodName4 | ||
) | ||
|
||
val method = Recursion::fib | ||
val mockStrategy = MockStrategyApi.NO_MOCKS | ||
val coverage = DoNotCalculate | ||
|
||
summaryCheck(method, mockStrategy, coverage, summaryKeys, methodNames, displayNames) | ||
} | ||
|
||
@Test | ||
fun testFactorial() { | ||
val summary1 = "@utbot.classUnderTest {@link Recursion}\n" + | ||
"@utbot.methodUnderTest {@link org.utbot.examples.recursion.Recursion#factorial(int)}\n" + | ||
//TODO: Lost information about executed condition, | ||
// see [issue-900](https://github.com/UnitTestBot/UTBotJava/issues/900) | ||
//"@utbot.executesCondition {@code (n == 0): True}\n" | ||
"@utbot.returnsFrom {@code return 1;}" | ||
val summary2 = "@utbot.classUnderTest {@link Recursion}\n" + | ||
"@utbot.methodUnderTest {@link org.utbot.examples.recursion.Recursion#factorial(int)}\n" + | ||
"@utbot.executesCondition {@code (n == 0): False}\n" + | ||
"@utbot.returnsFrom {@code return n * factorial(n - 1);}" | ||
val summary3 = "@utbot.classUnderTest {@link Recursion}\n" + | ||
"@utbot.methodUnderTest {@link org.utbot.examples.recursion.Recursion#factorial(int)}\n" + | ||
"@utbot.executesCondition {@code (n < 0): True}\n" + | ||
"@utbot.throwsException {@link java.lang.IllegalArgumentException} after condition: n < 0" | ||
|
||
val methodName1 = "testFactorial_Return1" | ||
val methodName2 = "testFactorial_NNotEqualsZero" | ||
val methodName3 = "testFactorial_NLessThanZero" | ||
|
||
//TODO: Display names are not complete, see [issue-899](https://github.com/UnitTestBot/UTBotJava/issues/899). | ||
//they should be equal "n == 0 : True -> return 1" and "n == 0 : False -> return n * factorial(n - 1)" respectively | ||
onewhl marked this conversation as resolved.
Show resolved
Hide resolved
|
||
val displayName1 = "-> return 1" | ||
val displayName2 = "-> return 1" | ||
val displayName3 = "n < 0 -> ThrowIllegalArgumentException" | ||
|
||
val summaryKeys = listOf( | ||
summary1, | ||
summary2, | ||
summary3 | ||
) | ||
|
||
val displayNames = listOf( | ||
displayName1, | ||
displayName2, | ||
displayName3 | ||
) | ||
|
||
val methodNames = listOf( | ||
methodName1, | ||
methodName2, | ||
methodName3 | ||
) | ||
|
||
val method = Recursion::factorial | ||
val mockStrategy = MockStrategyApi.NO_MOCKS | ||
val coverage = DoNotCalculate | ||
|
||
summaryCheck(method, mockStrategy, coverage, summaryKeys, methodNames, displayNames) | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just thought that in future we could have something like testing dsl
javadoc {
methodUnderTest = "org.utbot.examples.recursion.Recursion#fib(int)"
executesCondition = "(n == 0): False"
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yesss, it would be awesome!