Let's create a new JpaAuthorRepositoryTests test class in the src/test/java/com/example/bookpub directory at the root of our project with the following content:
import static org.assertj.core.api.Assertions.assertThat;
@RunWith(SpringRunner.class)
@DataJpaTest
public class JpaAuthorRepositoryTests {
@Autowired
private TestEntityManager mgr;
@Autowired
private AuthorRepository repository;
@Test
public void testAuthorEntityBinding() {
Long id = mgr.persistAndGetId(createAuthor(),
Long.class);
Author author = repository.findById(id).get();
assertThat(author.getFirstName()).
isEqualTo("Mark");
assertThat(author.getLastName()).
isEqualTo("Twain");
}
private Author createAuthor() {
return new Author("Mark", "Twain");
}
}
Execute the tests by running ./gradlew clean test and the tests should continue to pass