Skip to content

Enum class is addressed incorrectly #1210

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
alisevych opened this issue Oct 21, 2022 · 0 comments · Fixed by #1408
Closed

Enum class is addressed incorrectly #1210

alisevych opened this issue Oct 21, 2022 · 0 comments · Fixed by #1408
Assignees
Labels
comp-codegen Issue is related to code generator ctg-bug Issue is a bug priority-top-focus Top priority chosen by dev team status-verified Bug fix is verified

Comments

@alisevych
Copy link
Member

alisevych commented Oct 21, 2022

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.

@alisevych alisevych added ctg-bug Issue is a bug comp-codegen Issue is related to code generator labels Oct 21, 2022
@alisevych alisevych added this to the 2022.11 Release milestone Oct 21, 2022
@korifey korifey moved this to Todo in UTBot Java Oct 21, 2022
Repository owner moved this from Todo to Done in UTBot Java Nov 23, 2022
@alisevych alisevych added status-verified Bug fix is verified priority-top-focus Top priority chosen by dev team labels Nov 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
comp-codegen Issue is related to code generator ctg-bug Issue is a bug priority-top-focus Top priority chosen by dev team status-verified Bug fix is verified
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants