Skip to content

Asserts are missing for anonymous class #1034

Description

@alisevych

Description

If a method returns an anonymous class, the generated test method contains actual and expected, but doesn't assert them to be equal.

To Reproduce

  1. Run a project in IntelliJ Idea 2022.1.4 with one of the latest plugin builds from main branch
  2. Add the following code:
publicclassA {
publicinterfaceDriver {
publicintgetNumber(intn);
}
publicDrivergetDriver() {
returnnewDriver() {
@OverridepublicintgetNumber(intn) {
return2 * n - 1 ;
}
};
}
}
  1. Use plugin to generate tests for getDriver() method.
  2. Open the generated test

Expected behavior

Test is supposed to contain assert of expected and actual value.

Actual behavior

Test contains actual and expected fields, but there is no assertion.

Visual proofs (screenshots, logs, images)

importorg.junit.jupiter.api.Test;
importorg.junit.jupiter.api.DisplayName;
importstaticorg.utbot.runtime.utils.UtUtils.createInstance;
importstaticorg.utbot.runtime.utils.UtUtils.setField;
publicclassATest {
///region Test suites for executable A.getDriver///region FUZZER: SUCCESSFUL EXECUTIONS for method getDriver()@Test@DisplayName("getDriver: arg_0 = A()")
publicvoidtestGetDriver() throwsException {
Aa = newA();
A.Driveractual = a.getDriver();
A.Driverexpected = ((A.Driver) createInstance("A$1"));
setField(expected, "A$1", "this$0", a);
}
///endregion///endregion
}

Environment

Windows 10 Pro
JDK 8

Additional context

The same issue can be seen for generating tests for the following code:

publicclassA {
publicinta, b = 10;
publicList<Integer> integerStream (intc) {
returnArrays.asList(a, b, c);
}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    comp-codegenIssue is related to code generatorctg-bugIssue is a bug

    Type

    No type

    Projects

    Status
    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions