-
Notifications
You must be signed in to change notification settings - Fork 46
Add unit tests for builders #543 #734
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
5 commits
Select commit
Hold shift + click to select a range
8da8ce9
Configured unit tests with mockito
onewhl 68277d4
Add unit tests for SimpleNameBuilderTest #543
onewhl a754c4c
Add unit tests for SimpleClusterCommentBuilderTest.kt and SimpleComme…
onewhl 18fca9c
change mockito version, fix broken test, add tests for buildDocStmts
onewhl 5f24300
add tests for invokeDescription method
onewhl 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
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
62 changes: 62 additions & 0 deletions
62
utbot-summary/src/test/kotlin/org/utbot/summary/comment/SimpleClusterCommentBuilderTest.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,62 @@ | ||
package org.utbot.summary.comment | ||
|
||
import org.junit.jupiter.api.Assertions.assertEquals | ||
import org.junit.jupiter.api.BeforeAll | ||
import org.junit.jupiter.api.Test | ||
import org.junit.jupiter.api.TestInstance | ||
import org.mockito.Mockito.mock | ||
import org.mockito.Mockito.`when` | ||
import org.utbot.framework.plugin.api.Step | ||
import org.utbot.framework.plugin.api.UtOverflowFailure | ||
import org.utbot.summary.ast.JimpleToASTMap | ||
import org.utbot.summary.tag.StatementTag | ||
import org.utbot.summary.tag.TraceTag | ||
import soot.SootMethod | ||
import soot.jimple.Stmt | ||
import soot.jimple.internal.JReturnStmt | ||
|
||
@TestInstance(TestInstance.Lifecycle.PER_CLASS) | ||
class SimpleClusterCommentBuilderTest { | ||
private lateinit var traceTag: TraceTag | ||
private lateinit var jimpleToASTMap: JimpleToASTMap | ||
private lateinit var sootToAst: MutableMap<SootMethod, JimpleToASTMap> | ||
private lateinit var sootMethod: SootMethod | ||
private lateinit var statementTag: StatementTag | ||
private lateinit var step: Step | ||
private lateinit var statement: Stmt | ||
|
||
@BeforeAll | ||
fun setUp() { | ||
traceTag = mock(TraceTag::class.java) | ||
sootMethod = mock(SootMethod::class.java) | ||
jimpleToASTMap = mock(JimpleToASTMap::class.java) | ||
statementTag = mock(StatementTag::class.java) | ||
step = mock(Step::class.java) | ||
statement = mock(JReturnStmt::class.java) | ||
sootToAst = mutableMapOf() | ||
|
||
`when`(statementTag.step).thenReturn(step) | ||
`when`(step.stmt).thenReturn(statement) | ||
`when`(traceTag.path).thenReturn(listOf(step)) | ||
`when`(traceTag.rootStatementTag).thenReturn(statementTag) | ||
`when`(traceTag.result).thenReturn(UtOverflowFailure(Throwable())) | ||
|
||
sootToAst[sootMethod] = jimpleToASTMap | ||
} | ||
|
||
@Test | ||
fun `builds empty comment if execution result is null`() { | ||
val commentBuilder = SimpleClusterCommentBuilder(traceTag, sootToAst) | ||
val comment = commentBuilder.buildString(sootMethod) | ||
assertEquals(" ", comment) | ||
} | ||
|
||
@Test | ||
fun `builds empty doc statement if execution result is null`() { | ||
val commentBuilder = SimpleClusterCommentBuilder(traceTag, sootToAst) | ||
val statements = commentBuilder.buildDocStmts(sootMethod) | ||
assertEquals(statements.size, 1) | ||
assertEquals(statements[0].toString(), " ") | ||
} | ||
|
||
} |
84 changes: 84 additions & 0 deletions
84
utbot-summary/src/test/kotlin/org/utbot/summary/comment/SimpleCommentBuilderTest.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,84 @@ | ||
package org.utbot.summary.comment | ||
|
||
import org.junit.jupiter.api.Assertions.assertEquals | ||
import org.junit.jupiter.api.BeforeAll | ||
import org.junit.jupiter.api.Test | ||
import org.junit.jupiter.api.TestInstance | ||
import org.mockito.Mockito.mock | ||
import org.mockito.Mockito.`when` | ||
import org.utbot.framework.plugin.api.Step | ||
import org.utbot.framework.plugin.api.UtOverflowFailure | ||
import org.utbot.summary.ast.JimpleToASTMap | ||
import org.utbot.summary.tag.StatementTag | ||
import org.utbot.summary.tag.TraceTag | ||
import soot.SootMethod | ||
import soot.jimple.Stmt | ||
import soot.jimple.internal.JReturnStmt | ||
|
||
@TestInstance(TestInstance.Lifecycle.PER_CLASS) | ||
class SimpleCommentBuilderTest { | ||
onewhl marked this conversation as resolved.
Show resolved
Hide resolved
|
||
private lateinit var traceTag: TraceTag | ||
private lateinit var jimpleToASTMap: JimpleToASTMap | ||
private lateinit var sootToAst: MutableMap<SootMethod, JimpleToASTMap> | ||
private lateinit var sootMethod: SootMethod | ||
private lateinit var statementTag: StatementTag | ||
private lateinit var step: Step | ||
private lateinit var statement: Stmt | ||
|
||
@BeforeAll | ||
fun setUp() { | ||
traceTag = mock(TraceTag::class.java) | ||
sootMethod = mock(SootMethod::class.java) | ||
jimpleToASTMap = mock(JimpleToASTMap::class.java) | ||
statementTag = mock(StatementTag::class.java) | ||
step = mock(Step::class.java) | ||
statement = mock(JReturnStmt::class.java) | ||
sootToAst = mutableMapOf() | ||
|
||
`when`(statementTag.step).thenReturn(step) | ||
`when`(step.stmt).thenReturn(statement) | ||
`when`(traceTag.path).thenReturn(listOf(step)) | ||
`when`(traceTag.rootStatementTag).thenReturn(statementTag) | ||
`when`(traceTag.result).thenReturn(UtOverflowFailure(Throwable())) | ||
|
||
sootToAst[sootMethod] = jimpleToASTMap | ||
} | ||
|
||
@Test | ||
fun `throws throwable if execution result is null`() { | ||
val commentBuilder = SimpleCommentBuilder(traceTag, sootToAst) | ||
val comment = commentBuilder.buildString(sootMethod) | ||
val expectedComment = "<pre>\n" + | ||
"Test throws Throwable \n" + | ||
"</pre>" | ||
assertEquals(expectedComment, comment) | ||
} | ||
|
||
@Test | ||
fun `builds one doc statement`() { | ||
val commentBuilder = SimpleCommentBuilder(traceTag, sootToAst) | ||
val statements = commentBuilder.buildDocStmts(sootMethod) | ||
val expectedDocStatement = "Test \n" + | ||
"throws Throwable \n" | ||
assertEquals(statements.size, 1) | ||
assertEquals(statements[0].toString(), expectedDocStatement) | ||
} | ||
|
||
@Test | ||
fun `builds inline link for method`() { | ||
val commentBuilder = SimpleCommentBuilder(traceTag, sootToAst) | ||
val methodReference = commentBuilder.invokeDescription("org.utbot.ClassName", "methodName", listOf()) | ||
val expectedMethodReference = "{@link org.utbot.ClassName#methodName()}" | ||
assertEquals(methodReference, expectedMethodReference) | ||
} | ||
|
||
@Test | ||
fun `builds inline link for method in nested class`() { | ||
val commentBuilder = SimpleCommentBuilder(traceTag, sootToAst) | ||
val methodReference = | ||
commentBuilder.invokeDescription("org.utbot.ClassName\$NestedClassName", "methodName", listOf()) | ||
val expectedMethodReference = "{@link org.utbot.ClassName.NestedClassName#methodName()}" | ||
assertEquals(methodReference, expectedMethodReference) | ||
} | ||
|
||
} |
74 changes: 74 additions & 0 deletions
74
utbot-summary/src/test/kotlin/org/utbot/summary/name/SimpleNameBuilderTest.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,74 @@ | ||
package org.utbot.summary.name | ||
|
||
import org.junit.jupiter.api.Assertions.assertEquals | ||
import org.junit.jupiter.api.BeforeAll | ||
import org.junit.jupiter.api.Test | ||
import org.junit.jupiter.api.TestInstance | ||
import org.mockito.Mockito.mock | ||
import org.mockito.Mockito.`when` | ||
import org.utbot.framework.plugin.api.UtOverflowFailure | ||
import org.utbot.summary.ast.JimpleToASTMap | ||
import org.utbot.summary.tag.TraceTag | ||
import org.utbot.summary.tag.UniquenessTag | ||
import soot.SootMethod | ||
|
||
@TestInstance(TestInstance.Lifecycle.PER_CLASS) | ||
class SimpleNameBuilderTest { | ||
private lateinit var traceTag: TraceTag | ||
private lateinit var jimpleToASTMap: JimpleToASTMap | ||
private lateinit var sootToAst: MutableMap<SootMethod, JimpleToASTMap> | ||
private lateinit var sootMethod: SootMethod | ||
|
||
@BeforeAll | ||
fun setUp() { | ||
traceTag = mock(TraceTag::class.java) | ||
sootMethod = mock(SootMethod::class.java) | ||
jimpleToASTMap = mock(JimpleToASTMap::class.java) | ||
sootToAst = mutableMapOf() | ||
|
||
`when`(traceTag.result).thenReturn(UtOverflowFailure(Throwable())) | ||
|
||
sootToAst[sootMethod] = jimpleToASTMap | ||
} | ||
|
||
@Test | ||
fun `method name should start with test`() { | ||
`when`(sootMethod.name).thenReturn("methodName") | ||
|
||
val simpleNameBuilder = SimpleNameBuilder(traceTag, sootToAst, sootMethod) | ||
val methodName = simpleNameBuilder.name | ||
assert(methodName.startsWith("test")) | ||
} | ||
|
||
@Test | ||
fun `creates a name pair with a candidate with a bigger index`() { | ||
`when`(sootMethod.name).thenReturn("") | ||
|
||
val simpleNameBuilder = SimpleNameBuilder(traceTag, sootToAst, sootMethod) | ||
val fromCandidateName = DisplayNameCandidate("fromCandidate", UniquenessTag.Unique, 3) | ||
|
||
val toCandidate1 = DisplayNameCandidate("candidate1", UniquenessTag.Common, 2) | ||
val toCandidate2 = DisplayNameCandidate("candidate2", UniquenessTag.Common, 4) | ||
|
||
val candidate = simpleNameBuilder.buildCandidate(fromCandidateName, toCandidate1, toCandidate2) | ||
|
||
val resultPair = Pair(fromCandidateName.name, toCandidate2.name) | ||
assertEquals(candidate, resultPair) | ||
} | ||
|
||
@Test | ||
fun `returns null if candidates are equal`() { | ||
`when`(sootMethod.name).thenReturn("") | ||
|
||
val simpleNameBuilder = SimpleNameBuilder(traceTag, sootToAst, sootMethod) | ||
val fromCandidateName = DisplayNameCandidate("candidate", UniquenessTag.Unique, 0) | ||
|
||
// two equal candidates | ||
val toCandidate1 = DisplayNameCandidate("candidate", UniquenessTag.Common, 1) | ||
val toCandidate2 = DisplayNameCandidate("candidate", UniquenessTag.Common, 1) | ||
|
||
val candidate = simpleNameBuilder.buildCandidate(fromCandidateName, toCandidate1, toCandidate2) | ||
|
||
assertEquals(candidate, null) | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
utbot-summary/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker
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 @@ | ||
mock-maker-inline |
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.