Skip to content

Fuzzing Spring class with protected default constructor leads to compilation error #2559

Open
@EgorkaKulikov

Description

@EgorkaKulikov

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);
}

Metadata

Metadata

Assignees

Labels

comp-codegenIssue is related to code generatorcomp-springIssue is related to Spring projects supportctg-bugIssue is a bug

Type

No type

Projects

Status

Todo

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions