Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions utbot-summary/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,7 @@ dependencies {

implementation group: 'com.github.javaparser', name: 'javaparser-core', version: '3.22.1'

testImplementation 'org.mockito:mockito-core:4.7.0'

testImplementation("org.junit.jupiter:junit-jupiter:$junit5_version")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package org.utbot.summary.comment

import org.junit.jupiter.api.Assertions
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 `throws throwable if execution result is null`() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test fails on my side with

expected: <<pre>
Test throws Throwable 
</pre>> but was: < >

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i didn't expect these two builders have different behavior, but now we know. I fixed test

val commentBuilder = SimpleClusterCommentBuilder(traceTag, sootToAst)
val comment = commentBuilder.buildString(sootMethod)
val expectedComment = "<pre>\n" +
"Test throws Throwable \n" +
"</pre>"
Assertions.assertEquals(expectedComment, comment)
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
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 {
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)
}

}
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)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mock-maker-inline