File tree 3 files changed +39
-5
lines changed
main/kotlin/org/utbot/fuzzing/providers
java/org/utbot/fuzzing/samples
3 files changed +39
-5
lines changed Original file line number Diff line number Diff line change @@ -20,11 +20,14 @@ class EnumValueProvider(
20
20
description : FuzzedDescription ,
21
21
type : FuzzedType
22
22
) = sequence<Seed <FuzzedType , FuzzedValue >> {
23
- type.classId.jClass.enumConstants.filterIsInstance<Enum <* >>().forEach { enum ->
24
- val id = idGenerator.getOrCreateIdForValue(enum)
25
- yield (Seed .Simple (UtEnumConstantModel (id, type.classId, enum).fuzzed {
26
- summary = " %var% = $enum "
27
- }))
23
+ val jClass = type.classId.jClass
24
+ if (isAccessible(jClass, description.description.packageName)) {
25
+ jClass.enumConstants.filterIsInstance<Enum <* >>().forEach { enum ->
26
+ val id = idGenerator.getOrCreateIdForValue(enum)
27
+ yield (Seed .Simple (UtEnumConstantModel (id, type.classId, enum).fuzzed {
28
+ summary = " %var% = $enum "
29
+ }))
30
+ }
28
31
}
29
32
}
30
33
}
Original file line number Diff line number Diff line change @@ -16,4 +16,18 @@ public Node() {
16
16
}
17
17
}
18
18
}
19
+
20
+ public int ordinal (InnEn val ) {
21
+ switch (val ) {
22
+ case ONE :
23
+ return 0 ;
24
+ case TWO :
25
+ return 1 ;
26
+ }
27
+ return -1 ;
28
+ }
29
+
30
+ private enum InnEn {
31
+ ONE , TWO
32
+ }
19
33
}
Original file line number Diff line number Diff line change @@ -216,6 +216,23 @@ class JavaFuzzingTest {
216
216
assertEquals(0 , exec) { " Fuzzer should not create any values of private classes" }
217
217
}
218
218
219
+ @Test
220
+ fun `fuzzing should not generate values of private enums` () {
221
+ var exec = 0
222
+ runBlockingWithContext {
223
+ runJavaFuzzing(
224
+ TestIdentityPreservingIdGenerator ,
225
+ methodUnderTest = AccessibleObjects ::class .java.declaredMethods.first { it.name == " ordinal" }.executableId,
226
+ constants = emptyList(),
227
+ names = emptyList(),
228
+ ) { _, _, _ ->
229
+ exec + = 1
230
+ BaseFeedback (Trie .emptyNode(), Control .STOP )
231
+ }
232
+ }
233
+ assertEquals(0 , exec) { " Fuzzer should not create any values of private classes" }
234
+ }
235
+
219
236
@Test
220
237
fun `fuzzing generate single test in case of collection with fail-to-generate generic type` () {
221
238
val size = 100
You can’t perform that action at this time.
0 commit comments