UTBotJava icon indicating copy to clipboard operation
UTBotJava copied to clipboard

Fuzzing Spring class with protected default constructor leads to compilation error

Open EgorkaKulikov opened this issue 3 years ago • 0 comments

Description

Consider generating integration tests with application configuration from spring-boot-testing for the method

public boolean isNotEmpty() {
        List<Order> orders = orderRepository.findAll();
        return orders.size() > 0;
    }

where Order has the following constructors:

protected Order() {}

public Order(Long id, String buyer, int price, int qty) {
        this.id = id;
        this.buyer = buyer;
        this.price = price;
        this.qty = qty;
}

Expected behaviour

Generated tests can be successfully compiled and run.

Actual behaviour

The following uncompilable test is generated. The problem is in line with order1 definition.

@Test
@DisplayName("isNotEmpty:  -> return true")
public void testIsNotEmptyReturnsTrue() throws InstantiationException, IllegalAccessException, InvocationTargetException {
        Object[] orderConstructorArguments1 = new Object[0];
        Order order1 = ((Order) orderConstructor.newInstance(orderConstructorArguments1));
        entityManager1.persist(order1);
        entityManager1.flush();

        boolean actual = orderService.isNotEmpty();

        assertTrue(actual);
}

EgorkaKulikov avatar Aug 28 '23 08:08 EgorkaKulikov