How to do it...

  1. 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"); 
    } 
} 
  1. Execute the tests by running ./gradlew clean test and the tests should continue to pass
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.221.53.5