UTBotJava
UTBotJava copied to clipboard
Variable `objectType` with Class is used but not created
Description
Variable objectType with Class is used but not created.
To Reproduce
- Install UnitTestBot plugin built from main in IntelliJ IDEA
- Open
sm***tproject - Press Ctrl+Shift+N, input
rdi - Generate tests for all methods of the class with
@SpringBootApplicationandUnit testsselected
Expected behavior
- Variable
objectTypeis initialized with object's class. OrObject.classshould be used instead. - Assert of
finalObjectTypeis (probably) expected.
Actual behavior
Variable objectType with Class is used to pass the Class of the first object.
finalObjectType is created, but not checked
Screenshots, logs
///region OTHER: EXPLICITLY THROWN UNCHECKED EXCEPTIONS for method query(java.lang.Object, java.lang.Class)
@Test
public void testQuery1() {
Object value = new Object();
assertThrows(IllegalArgumentException.class, () -> rdi.query(value, Object.class));
Class finalObjectType = objectType;
}
///endregion
Environment
IntelliJ IDEA version - Ultimate 2023.1.4 Project - Maven JDK - 1.8
@alisevych Can you still reproduce it?
@EgorkaKulikov Partially. Now the following test is generated - on latest main in IDEA 2023.2:
@Test
public void testQuery3() {
Object value = new Object();
Class clazz = Object.class;
assertThrows(IllegalArgumentException.class, () -> rdi.query(value, clazz));
Class finalClazz = clazz;
}