UserDetailService { public UserDetail getUserDetail(Long userId) { EntityManager newEm = emf.createEntityManager(); EntityTransaction newTx = newEm.getTransaction(); newTx.begin(); UserDetail userDetail = newEm.find(UserDetail.class, userId); newTx.commit(); return userDetail; } UserDetailService(); UserDetail getUserDetail(Long userId); void saveUserDetail(UserDetail userDetail); List<UserDetail> getAllUsers();  }
@Test public void shouldGetUserDetail() throws Exception { UserDetail userDetail = userDetailService.getUserDetail(1L); assertNotNull(userDetail); assertSame(1L, userDetail.getId()); assertEquals("Got " + userDetail.getName(), "user1", userDetail.getName()); }