-
Notifications
You must be signed in to change notification settings - Fork 45
Closed
Labels
ctg-bugIssue is a bugIssue is a bugspec-release-tailingsFailed to include in the current release, let's include it in the next oneFailed to include in the current release, let's include it in the next one
Milestone
Description
Description
When Mocking strategy is set to "Other classes: Mockito" - other classes should be mocked in all tests.
To Reproduce
Steps to reproduce the behavior:
- Run IntelliJ IDEA 2022.1.4 with one of the latest builds of UTBot plugin from main branch installed.
- Open UTBotJava project
- Find utbot-sample/src/main/java/org/utbot/examples/mock/CommonMocksExample.java
- Generate tests for nextValue() method with Mocking strategy is set to "Other classes: Mockito"
- Open the generated test
Expected behavior
RecursiveTypeClass used as the input parameter of the method is supposed to be mocked in all tests - except the one with null used.
Actual behavior
There are 4 tests generated. RecursiveTypeClass is mocked only in one test.
Visual proofs (screenshots, logs, images)
public class CommonMocksExampleTest {
@Test
public void testNextValue() {
CommonMocksExample commonMocksExample = new CommonMocksExample();
RecursiveTypeClass node = new RecursiveTypeClass();
RecursiveTypeClass recursiveTypeClass = new RecursiveTypeClass();
recursiveTypeClass.next = null;
recursiveTypeClass.value = 0;
node.next = recursiveTypeClass;
node.value = 0;
RecursiveTypeClass actual = commonMocksExample.nextValue(node);
RecursiveTypeClass nodeNext = node.next;
RecursiveTypeClass actualNext = actual.next;
RecursiveTypeClass actualNextNext = actualNext.next;
assertNull(actualNextNext);
int nodeNextValue = nodeNext.value;
int actualNextValue = actualNext.value;
assertEquals(nodeNextValue, actualNextValue);
int nodeValue = node.value;
int actualValue = actual.value;
assertEquals(nodeValue, actualValue);
}
@Test
public void testNextValueThrowsNPE() {
CommonMocksExample commonMocksExample = new CommonMocksExample();
RecursiveTypeClass node = new RecursiveTypeClass();
/* This test fails because method [org.utbot.examples.mock.CommonMocksExample.nextValue] produces [java.lang.NullPointerException]
org.utbot.examples.mock.CommonMocksExample.nextValue(CommonMocksExample.java:25) */
commonMocksExample.nextValue(node);
}
@Test
public void testNextValue_NodeNextEqualsNode() {
CommonMocksExample commonMocksExample = new CommonMocksExample();
RecursiveTypeClass nodeMock = mock(RecursiveTypeClass.class);
nodeMock.next = nodeMock;
RecursiveTypeClass actual = commonMocksExample.nextValue(nodeMock);
int nodeMockValue = nodeMock.value;
int actualValue = actual.value;
assertEquals(nodeMockValue, actualValue);
}
@Test
public void testNextValue_ThrowNullPointerException() {
CommonMocksExample commonMocksExample = new CommonMocksExample();
/* This test fails because method [org.utbot.examples.mock.CommonMocksExample.nextValue] produces [java.lang.NullPointerException]
org.utbot.examples.mock.CommonMocksExample.nextValue(CommonMocksExample.java:21) */
commonMocksExample.nextValue(null);
}
}
Environment
Windows 10 Pro
Gradle project
JDK 8
Additional context
When generating tests for MockWithFieldExample with same setting : Other classes : Mockito - VersionStamp is not mocked either
Metadata
Metadata
Assignees
Labels
ctg-bugIssue is a bugIssue is a bugspec-release-tailingsFailed to include in the current release, let's include it in the next oneFailed to include in the current release, let's include it in the next one
Type
Projects
Status
Done