Need to generate correct data for Iterable<? extends ClassName>.
Currently the generated Collection contains not only objects of the required class, but also arrays with such objects.
So iterating over this collection fails with ClassCastException.
The issue is actual for common classes and Enums.
Generate tests with UnitTestBot for enum ThreeState
or for the following code example:
public class A {
public class B {
public int getNumber(int n) {
return n * 2 - 1;
}
}
public B findTheLimit(Iterable<? extends B> drivers) {
int i = 0;
int result = 0;
for (B b : drivers) {
result += b.getNumber(i + 10);
if (result > 40) {
return b;
}
}
throw new IllegalStateException("Not found anything valuable");
}
}
Expected behavior
Input data for public static ThreeState mostPositive(@NotNull Iterable<? extends ThreeState> states)
should represent a Collection of ThreeState objects.
Actual behavior
There are two tests generated - for merge() and mostPositive() - that put an array as an element of a Collection.
These tests fail with ClassCastException.
Visual proofs (screenshots, logs, images)
@Test
public void testMerge5() {
HashSet states = new HashSet();
states.add(null);
B[] threeStateArray = {};
states.add(threeStateArray);
states.add(threeStateArray);
/* This test fails because method [com.intellij.util.B.findTheLimit] produces [java.lang.ClassCastException: class [Lcom.intellij.util.B; cannot be cast to class com.intellij.util.B([Lcom.intellij.util.B; and com.intellij.util.Bare in unnamed module of loader org.utbot.instrumentation.process.HandlerClassesLoader @294975c8)]
com.intellij.util.B.findTheLimit(A.java:55) */
B.findTheLimit(states);
}
Environment
Windows 10 Pro
IntelliJ IDEA 2022.2.4 (not the last)
Additional context
Also there is one test with correct input data but
Description
Need to generate correct data for Iterable<? extends ClassName>. Currently the generated Collection contains not only objects of the required class, but also arrays with such objects. So iterating over this collection fails with ClassCastException. The issue is actual for common classes and Enums.
To Reproduce
lrs
project in IntelliJ Ideaenum ThreeState
Expected behavior
Input data for
public static ThreeState mostPositive(@NotNull Iterable<? extends ThreeState> states)
should represent a Collection of ThreeState objects.Actual behavior
There are two tests generated - for
merge()
andmostPositive()
- that put an array as an element of a Collection. These tests fail with ClassCastException.Visual proofs (screenshots, logs, images)
Environment
Windows 10 Pro IntelliJ IDEA 2022.2.4 (not the last)
Additional context
Also there is one test with correct input data but