UTBotJava icon indicating copy to clipboard operation
UTBotJava copied to clipboard

Variable `objectType` with Class is used but not created

Open alisevych opened this issue 3 years ago • 2 comments

Description

Variable objectType with Class is used but not created.

To Reproduce

  1. Install UnitTestBot plugin built from main in IntelliJ IDEA
  2. Open sm***t project
  3. Press Ctrl+Shift+N, input rdi
  4. Generate tests for all methods of the class with @SpringBootApplication and Unit tests selected

Expected behavior

  1. Variable objectType is initialized with object's class. Or Object.class should be used instead.
  2. Assert of finalObjectType is (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 avatar Jul 17 '23 15:07 alisevych

@alisevych Can you still reproduce it?

EgorkaKulikov avatar Aug 03 '23 15:08 EgorkaKulikov

@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;

}

alisevych avatar Aug 04 '23 09:08 alisevych