-
Notifications
You must be signed in to change notification settings - Fork 45
Expand file tree
/
Copy pathJavaValueProviderTest.kt
More file actions
61 lines (56 loc) · 2.48 KB
/
JavaValueProviderTest.kt
File metadata and controls
61 lines (56 loc) · 2.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package org.utbot.fuzzing
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
import org.utbot.framework.plugin.api.Instruction
import org.utbot.framework.plugin.api.util.collectionClassId
import org.utbot.framework.plugin.api.util.id
import org.utbot.framework.plugin.api.util.stringClassId
import org.utbot.framework.plugin.api.util.voidClassId
import org.utbot.fuzzer.FuzzedMethodDescription
import org.utbot.fuzzer.FuzzedType
import org.utbot.fuzzing.providers.ListSetValueProvider
import org.utbot.fuzzing.providers.MapValueProvider
import org.utbot.fuzzing.samples.ConcreateMap
import org.utbot.fuzzing.samples.ConcreteList
import org.utbot.fuzzing.utils.Trie
import java.lang.reflect.Type
import kotlin.random.Random
fun emptyFuzzerDescription(typeCache: MutableMap<Type, FuzzedType>) = FuzzedDescription(
FuzzedMethodDescription("no name", voidClassId, emptyList()),
Trie(Instruction::id),
typeCache,
Random(42)
)
class JavaValueProviderTest {
@Test
fun `collection value provider correctly resolves types for concrete types of map`() {
val typeCache = mutableMapOf<Type, FuzzedType>()
runBlockingWithContext {
val seed = MapValueProvider(TestIdentityPreservingIdGenerator).generate(
emptyFuzzerDescription(typeCache),
toFuzzerType(ConcreateMap::class.java, typeCache)
).first()
val collection = seed as Seed.Collection
val types = collection.modify.types
Assertions.assertEquals(2, types.size)
Assertions.assertEquals(types[0].classId, stringClassId)
Assertions.assertEquals(types[1].classId, java.lang.Number::class.java.id)
}
}
@Test
fun `collection value provider correctly resolves types for concrete types of list`() {
val typeCache = mutableMapOf<Type, FuzzedType>()
runBlockingWithContext {
val seed = ListSetValueProvider(TestIdentityPreservingIdGenerator).generate(
emptyFuzzerDescription(typeCache),
toFuzzerType(ConcreteList::class.java, typeCache)
).first()
val collection = seed as Seed.Collection
val types = collection.modify.types
Assertions.assertEquals(1, types.size)
Assertions.assertEquals(types[0].classId, collectionClassId)
Assertions.assertEquals(1, types[0].generics.size)
Assertions.assertEquals(types[0].generics[0].classId, stringClassId)
}
}
}