Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
EgorkaKulikov opened this issue Aug 28, 2023 · 0 comments
Assignees
Labels
comp-codegen Issue is related to code generator comp-spring Issue is related to Spring projects support ctg-bug Issue is a bug

Comments

@EgorkaKulikov
Copy link
Collaborator

EgorkaKulikov commented Aug 28, 2023

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 EgorkaKulikov added the ctg-bug Issue is a bug label Aug 28, 2023
@EgorkaKulikov EgorkaKulikov added comp-codegen Issue is related to code generator comp-spring Issue is related to Spring projects support labels Aug 28, 2023
@EgorkaKulikov EgorkaKulikov changed the title Fuzzing Spring class with private default constructor leads to compilation error Fuzzing Spring class with protected default constructor leads to compilation error Sep 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
comp-codegen Issue is related to code generator comp-spring Issue is related to Spring projects support ctg-bug Issue is a bug
Projects
Status: Todo
Development

No branches or pull requests

2 participants