Complete the code to annotate the test class for JPA repository testing.
@[1] public class UserRepositoryTest { // test methods }
The @DataJpaTest annotation is used to configure a test class for JPA repository testing in Spring Boot.
Complete the code to inject the repository into the test class.
@Autowired
private [1] userRepository;The repository interface, typically named UserRepository, is injected to test its methods.
Fix the error in the test method to save and verify a user entity.
@Test
void testSaveUser() {
User user = new User();
user.setName("Alice");
userRepository.[1](user);
assertNotNull(user.getId());
}The save method persists the entity and assigns an ID.
Fill both blanks to write a query method test that finds a user by name.
@Test
void testFindByName() {
User user = new User();
user.setName("Bob");
userRepository.save(user);
Optional<User> found = userRepository.[1]("Bob");
assertTrue(found.[2]());
}The repository method findByName returns an Optional. Use isPresent() to check if a user was found.
Fill all three blanks to create a test that deletes a user and verifies it no longer exists.
@Test
void testDeleteUser() {
User user = new User();
user.setName("Carol");
userRepository.save(user);
userRepository.[1](user);
Boolean exists = userRepository.[2](user.getId());
assertFalse(exists.[3]());
}Use delete to remove the entity, existsById to check if it still exists, and booleanValue() to get the primitive boolean for assertion.