Hello, I have problem with database or smth like that with testing springboot
I get error that user is not found but this user should exists with specified id
On normal api testing with postman it works correctly
@Test
final void testAddRental() {
User user = new User();
user.setId(1);
user.setName("as");
user.setSurname("sa");
user.setEmail("@");
userRepository.save(user);
Worker worker = new Worker();
worker.setId(1);
worker.setName("as");
worker.setSurname("sa");
worker.setEmail("@");
workerRepository.save(worker);
Vehicle vehicle = new Vehicle();
vehicle.setId(1);
vehicle.setMake("sa");
vehicle.setModel("as");
vehicle.setYear(1990);
vehicle.setPlate("GWE 1111");
vehicle.setCategory("sa");
vehicleRepository.save(vehicle);
when(userRepository.findById(1)).thenReturn(Optional.of(user));
when(vehicleRepository.findById(1)).thenReturn(Optional.of(vehicle));
when(workerRepository.findById(1)).thenReturn(Optional.of(worker));
Rental res = rentalService.CreateRental(1,1,1,1683703611000L,1715326005000L);
assertNotNull(res);
}
Tysm for help!