Skip to content

Enum class is addressed incorrectly #1210

Closed

Description

@alisevych

Description

When Enum class is created by className, it addresses not class but the Enum constant.

To Reproduce

  1. Run the 'UTBotJava' project in IntelliJ Idea
  2. Install plugin build or one of the latest builds from main. Reproducing on more early build too
  3. Generate tests for utbot-sample/src/main/java/org/utbot/examples/enums
    with No mocks, No parameterization.
  4. Run the generated tests

Expected behavior

Assertions in generated tests are supposed to pass.

Actual behavior

There are assertion errors in tests - for every class in the package.
Please see the Class creation: State$3 is addressing not the State enum, but the third constant in it.

Visual proofs (screenshots, logs, images)

    ///region Test suites for executable org.utbot.examples.enums.ComplexEnumExamples.findState

    ///region FUZZER: SUCCESSFUL EXECUTIONS for method findState(int)

    @Test
    @DisplayName("findState: code > 0")
    public void testFindState() throws ClassNotFoundException, IllegalAccessException {
        ComplexEnumExamples complexEnumExamples = new ComplexEnumExamples();

        State actual = complexEnumExamples.findState(1);

        Class anonymousStateClazz = Class.forName("org.utbot.examples.enums.State$3");
        Object expected = getEnumConstantByName(anonymousStateClazz, "UNKNOWN");
        assertEquals(expected, actual);
    }

same for Symbolic execution:

    ///region Test suites for executable org.utbot.examples.enums.State.findStateByCode

    ///region SYMBOLIC EXECUTION: SUCCESSFUL EXECUTIONS for method findStateByCode(int)

    /**
     * @utbot.classUnderTest {@link State}
     * @utbot.methodUnderTest {@link State#findStateByCode(int)}
     */
    @Test
    @DisplayName("findStateByCode: ")
    public void testFindStateByCode() throws ClassNotFoundException, IllegalAccessException {
        State actual = State.findStateByCode(255);

        Class anonymousStateClazz = Class.forName("org.utbot.examples.enums.State$1");
        Object expected = getEnumConstantByName(anonymousStateClazz, "OPEN");
        assertEquals(expected, actual);
    }

Additional context

Same issue with Fuzzing and / or Symbolic execution.
These tests are also failing when running in debug IDEA with runIde.

Activity

  1. added
    ctg-bug
    comp-codegen
    on Oct 21, 2022
  2. added this to the 2022.11 Release milestone on Oct 21, 2022
  3. moved this to Todo in UTBot Javaon Oct 21, 2022
  4. Repository owner moved this from Todo to Done in UTBot Javaon Nov 23, 2022
  5. added
    status-verified
    priority-top-focus
    on Nov 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

comp-codegenctg-bugpriority-top-focusstatus-verified

Type

No type

Projects

Relationships

None yet

Development

No branches or pull requests

Issue actions