-
Notifications
You must be signed in to change notification settings - Fork 45
Closed
Labels
comp-symbolic-engineIssue is related to the symbolic execution engineIssue is related to the symbolic execution enginectg-bugIssue is a bugIssue is a bug
Milestone
Description
Description
assertEquals(expectedMock, actual) is failing when both Objects are mocks.
When only one of them is a mock - the test passes.
To Reproduce
- Install one of the latest plugin builds from main into IntelliJ Idea 2022.2.*
- Open/clone "utbot" project
- Use plugin to generate tests for
org.utbot.examples.mock.provider.impl.ProviderImpl#provideObject - Run the generated test
- Open the test failed on assertion
Expected behavior
If actual OR expected Object is a mock, need to compare them by field values using deepEquals.
Actual behavior
ExampleClass has overridden equals and hashCode methods.
In this example both actual and expected Objects are mocks of ExampleClass.
assertEquals(expectedMock, actual) is failing because mocks have their own equals and hashcode implementations.
Visual proofs (screenshots, logs, images)
///region SYMBOLIC EXECUTION: SUCCESSFUL EXECUTIONS for method provideObject()
/**
* @utbot.classUnderTest {@link ProviderImpl}
* @utbot.methodUnderTest {@link ProviderImpl#provideObject()}
* @utbot.returnsFrom {@code return new ExampleClass(0);}
*/
@Test
@DisplayName("provideObject: -> return new ExampleClass(0)")
public void testProvideObject_Return() {
org.mockito.MockedConstruction mockedConstruction = null;
try {
java.util.concurrent.atomic.AtomicInteger mockClassCounter = new java.util.concurrent.atomic.AtomicInteger();
mockedConstruction = mockConstruction(ExampleClass.class, (ExampleClass ExampleClassMock, org.mockito.MockedConstruction.Context context) -> {
switch (mockClassCounter.get()) {
case 0:
break;
}
mockClassCounter.getAndIncrement();
});
ProviderImpl providerImpl = new ProviderImpl();
ExampleClass actual = providerImpl.provideObject();
ExampleClass expectedMock = mock(ExampleClass.class);
expectedMock.field = 0;
// org.utbot.examples.mock.service.impl.ExampleClass has overridden equals method
assertEquals(expectedMock, actual);
} finally {
mockedConstruction.close();
}
}
///endregionEnvironment
Windows 10 Pro
IntelliJ IDEA 2022.2.4
org.mockito:mockito-core:4.2.0
Additional context
The following test generated by Fuzzing is passing:
///region FUZZER: SUCCESSFUL EXECUTIONS for method provideObject()
/**
* @utbot.classUnderTest {@link ProviderImpl}
* @utbot.methodUnderTest {@link ProviderImpl#provideObject()}
*/
@Test
@DisplayName("provideObject: ")
public void testProvideObject() {
ProviderImpl providerImpl = new ProviderImpl();
ExampleClass actual = providerImpl.provideObject();
ExampleClass expected = new ExampleClass(0);
// org.utbot.examples.mock.service.impl.ExampleClass has overridden equals method
assertEquals(expected, actual);
}
///endregionReactions are currently unavailable
Metadata
Metadata
Assignees
Labels
comp-symbolic-engineIssue is related to the symbolic execution engineIssue is related to the symbolic execution enginectg-bugIssue is a bugIssue is a bug
Type
Projects
Status
Done