Skip to content

Commit 9134330

Browse files
committed
Add test for list generatings
1 parent 25fc246 commit 9134330

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package org.utbot.fuzzing.samples;
2+
3+
import java.util.List;
4+
5+
@SuppressWarnings("unused")
6+
public class FailToGenerateListGeneric {
7+
8+
interface Something {}
9+
10+
int func(List<Something> x) {
11+
return x.size();
12+
}
13+
14+
}

utbot-fuzzers/src/test/kotlin/org/utbot/fuzzing/JavaFuzzingTest.kt

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,16 @@ package org.utbot.fuzzing
33
import kotlinx.coroutines.runBlocking
44
import org.junit.jupiter.api.Assertions.*
55
import org.junit.jupiter.api.Test
6-
import org.junit.jupiter.api.assertDoesNotThrow
76
import org.utbot.framework.plugin.api.MethodId
87
import org.utbot.framework.plugin.api.TestIdentityPreservingIdGenerator
8+
import org.utbot.framework.plugin.api.UtAssembleModel
99
import org.utbot.framework.plugin.api.UtPrimitiveModel
1010
import org.utbot.framework.plugin.api.util.*
1111
import org.utbot.fuzzer.FuzzedConcreteValue
1212
import org.utbot.fuzzing.samples.DeepNested
1313
import org.utbot.fuzzer.FuzzedType
1414
import org.utbot.fuzzing.samples.AccessibleObjects
15+
import org.utbot.fuzzing.samples.FailToGenerateListGeneric
1516
import org.utbot.fuzzing.samples.Stubs
1617
import org.utbot.fuzzing.utils.Trie
1718
import java.lang.reflect.GenericArrayType
@@ -214,6 +215,30 @@ class JavaFuzzingTest {
214215
assertEquals(0, exec) { "Fuzzer should not create any values of private classes" }
215216
}
216217

218+
@Test
219+
fun `fuzzing generate single test in case of collection with fail-to-generate generic type`() {
220+
val size = 100
221+
var exec = size
222+
val collections = ArrayList<Any?>(exec)
223+
runBlockingWithContext {
224+
runJavaFuzzing(
225+
TestIdentityPreservingIdGenerator,
226+
methodUnderTest = FailToGenerateListGeneric::class.java.declaredMethods.first { it.name == "func" }.executableId,
227+
constants = emptyList(),
228+
names = emptyList()
229+
) { _, _, v ->
230+
collections.add(v.first().model as? UtAssembleModel)
231+
BaseFeedback(Trie.emptyNode(), if (--exec > 0) Control.CONTINUE else Control.STOP)
232+
}
233+
}
234+
assertEquals(0, exec) { "Total fuzzer run number must be 0" }
235+
assertEquals(size, collections.size) { "Total generated values number must be $size" }
236+
assertEquals(size, collections.count { it is UtAssembleModel }) { "Total assemble models size must be $size" }
237+
collections.filterIsInstance<UtAssembleModel>().forEach {
238+
assertEquals(0, it.modificationsChain.size)
239+
}
240+
}
241+
217242
private fun <T> runBlockingWithContext(block: suspend () -> T) : T {
218243
return withUtContext(UtContext(this::class.java.classLoader)) {
219244
runBlocking {

0 commit comments

Comments
 (0)