Open alisevych opened 1 year ago
I created the non-Spring project containing two classes:
public class Pet {
public String name;
}
2.Service
import java.util.ArrayList;
public class Service {
public ArrayList<Pet> pets;
public void addPet(Pet pet) {
pets.add(pet);
}
}
and generated tests for addPet
method.
The following tests were generated:
public final class ServiceTest {
@Test
@DisplayName("addPet: -> ArrayListAdd")
public void testAddPet_ArrayListAdd() {
Service service = new Service();
ArrayList arrayList = new ArrayList();
arrayList.add(null);
arrayList.add(null);
arrayList.add(null);
service.pets = arrayList;
service.addPet(null);
}
@Test
@DisplayName("addPet: pets.add(pet) : True -> ThrowNullPointerException")
public void testAddPet_ArrayListAdd_1() {
Service service = new Service();
/* This test fails because method [pack.Service.addPet] produces [java.lang.NullPointerException]
pack.Service.addPet(Service.java:10) */
service.addPet(null);
}
}
There are no asserts on pets
field state...
It would be great to check if UtExecution contains the information on changing field with Collection.
It can be accessed by method Owner#getPets()
call to validate the changes from the test.
Description
No validation of a Collection of elements in Spring No configuration test
To Reproduce
spring-petclinic
projectOwner
class(pet.isNew()): True
branchExpected behavior
Assert added Pet exists in
owner.pets
fieldActual behavior
List of null values is created. No checks for the List are made.
Screenshots, logs
Environment
IntelliJ IDEA version - Ultimate 2023.1.3 Project - Gradle JDK - 17