Open
Description
To Reproduce
Consider the following class under test
import java.util.OptionalInt;
public class OrderService {
private final OrderRepository orderRepository;
public OrderService(OrderRepository orderRepository) {
this.orderRepository = orderRepository;
}
public int methodUnderTest(int id) {
OptionalInt res = orderRepository.findById(id);
if (res == null || res.isEmpty()) {
return 1;
} else {
return 2;
}
}
}
Another mentioned class looks as follows:
import java.util.OptionalInt;
public class OrderRepository {
public OptionalInt findById(int id) {
if (id > 0) {
return OptionalInt.of(id);
} else {
return null;
}
}
}
Generate tests with
- mock strategy
mock everything outside class
- 100% of Symbolic engine
Expected behavior
Two tests for both branches of method under test were generated.
Actual behavior
Only one test was generated:
@Test
public void testMethodUnderTest1() {
OrderRepository orderRepositoryMock = mock(OrderRepository.class);
OptionalInt optionalInt = empty();
(when(orderRepositoryMock.findById(anyInt()))).thenReturn(optionalInt);
OrderService orderService = new OrderService(orderRepositoryMock);
int actual = orderService.methodUnderTest(0);
assertEquals(1, actual);
}
Additional context
Replacing OptionalInt
with Optional<Integer>
does not change the behavior.
Metadata
Metadata
Assignees
Type
Projects
Status
Todo