Advertisement
ILyaCyclone

Untitled

Apr 12th, 2019
260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.76 KB | None | 0 0
  1. @Repository
  2. @Transactional(readOnly = true)
  3. public class BookRepositoryJpa implements BookRepository {
  4.  
  5.     @PersistenceContext
  6.     private EntityManager em;
  7.  
  8.     @Transactional // тест проходит, даже если я забуду @Transactional - как это проверить?
  9.     public void delete(Book book) {
  10.       em.remove(book);
  11.     }
  12. }
  13.  
  14.  
  15. @DataJpaTest
  16. @ComponentScan("my.package.jpa")
  17. class BookRepositoryJpaTest {
  18.     @Autowired
  19.     BookDao bookDao;
  20.  
  21.     @Autowired
  22.     TestEntityManager tem;
  23.  
  24.     @Test
  25.     void testDelete() {
  26.         Book bookToDelete = tem.find(Book.class, BOOK2.getBookId());
  27.  
  28.         bookDao.delete(bookToDelete);
  29.         assertThat(bookDao.findAll()).containsExactly(BOOK5, BOOK4, BOOK3, BOOK1);
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement