@@ -23,67 +23,22 @@ class ObjectValueProvider(
23
23
NumberValueProvider .classId
24
24
)
25
25
26
- override fun accept (type : FuzzedType ) = ! shouldPass (type.classId)
26
+ override fun accept (type : FuzzedType ) = ! isIgnored (type.classId)
27
27
28
28
override fun generate (
29
29
description : FuzzedDescription ,
30
30
type : FuzzedType
31
31
) = sequence {
32
32
val classId = type.classId
33
- // this adds mock support, but we should discuss first if mock is really needed
34
- // if (description.description.shouldMock(classId)) {
35
- // yield(createMock(classId, description))
36
- // } else {
37
- // prefer constructors without recursion call, but use them if no other options
38
- val constructors = findTypesOfNonRecursiveConstructor(type, description.description.packageName)
39
- .takeIf { it.isNotEmpty() }
40
- ?.asSequence()
41
- ? : classId.allConstructors.filter {
42
- isAccessible(it.constructor , description.description.packageName)
43
- }
44
- constructors.forEach { constructorId ->
45
- yield (createValue(classId, constructorId, description))
46
- }
47
- // }
48
- }
49
-
50
- @Suppress(" unused" )
51
- private fun createMock (classId : ClassId , description : FuzzedDescription ): Seed .Recursive <FuzzedType , FuzzedValue > {
52
- return Seed .Recursive (
53
- construct = Routine .Create (emptyList()) {
54
- UtCompositeModel (
55
- id = idGenerator.createId(),
56
- classId = classId,
57
- isMock = true ,
58
- ).fuzzed {
59
- summary = " %var% = mock"
60
- }
61
- },
62
- modify = sequence {
63
- findSuitableFields(classId, description.description.packageName).forEach { fd ->
64
- when {
65
- fd.canBeSetDirectly -> {
66
- yield (Routine .Call (listOf (FuzzedType (fd.classId))) { self, values ->
67
- val model = self.model as UtCompositeModel
68
- model.fields[FieldId (classId, fd.name)] = values.first().model
69
- })
70
- }
71
-
72
- fd.setter != null && fd.getter != null -> {
73
- yield (Routine .Call (listOf (FuzzedType (fd.classId))) { self, values ->
74
- val model = self.model as UtCompositeModel
75
- model.mocks[fd.getter.executableId] = values.map { it.model }
76
- })
77
- }
78
- }
79
- }
80
- },
81
- empty = Routine .Empty {
82
- UtNullModel (classId).fuzzed {
83
- summary = " %var% = null"
84
- }
33
+ val constructors = findTypesOfNonRecursiveConstructor(type, description.description.packageName)
34
+ .takeIf { it.isNotEmpty() }
35
+ ?.asSequence()
36
+ ? : classId.allConstructors.filter {
37
+ isAccessible(it.constructor , description.description.packageName)
85
38
}
86
- )
39
+ constructors.forEach { constructorId ->
40
+ yield (createValue(classId, constructorId, description))
41
+ }
87
42
}
88
43
89
44
private fun createValue (classId : ClassId , constructorId : ConstructorId , description : FuzzedDescription ): Seed .Recursive <FuzzedType , FuzzedValue > {
@@ -104,7 +59,7 @@ class ObjectValueProvider(
104
59
}
105
60
},
106
61
modify = sequence {
107
- findSuitableFields (classId, description.description.packageName).forEach { fd ->
62
+ findAccessibleModifableFields (classId, description.description.packageName).forEach { fd ->
108
63
when {
109
64
fd.canBeSetDirectly -> {
110
65
yield (Routine .Call (listOf (FuzzedType (fd.classId))) { self, values ->
@@ -137,8 +92,9 @@ class ObjectValueProvider(
137
92
)
138
93
}
139
94
140
- private fun shouldPass (type : ClassId ): Boolean {
95
+ private fun isIgnored (type : ClassId ): Boolean {
141
96
return unwantedConstructorsClasses.contains(type)
97
+ || type.isIterableOrMap
142
98
|| type.isPrimitiveWrapper
143
99
|| type.isEnum
144
100
|| type.isAbstract
@@ -193,7 +149,7 @@ internal class FieldDescription(
193
149
val getter : Method ?
194
150
)
195
151
196
- internal fun findSuitableFields (classId : ClassId , packageName : String? ): List <FieldDescription > {
152
+ internal fun findAccessibleModifableFields (classId : ClassId , packageName : String? ): List <FieldDescription > {
197
153
val jClass = classId.jClass
198
154
return jClass.declaredFields.map { field ->
199
155
val setterAndGetter = jClass.findPublicSetterGetterIfHasPublicGetter(field, packageName)
0 commit comments