I was trying to mock findOne & findByHeaderId methods of all the implementation of two repository interfaces as below. It was successfully mocked with Jmockit version 1.17 or greater.
when I changed the version to less than 1.17, DetailsRepo is unable to mock. But still Header repo method is mocked. Why mocking is not happening for Details repo method?
@Test
@Rollback(true)
public <T extends JpaRepository<Header, Long>, U extends DetailsRepository> void mock_test() {
// --mocking Header repo
new MockUp<T>() {
@Mock
public Header findOne(Long id) {
// -- mocking logic
Header header = new Header();
header.setId(Long.MAX_VALUE);
header.setRemarks("testing");
System.out.println("********** HeaderRepository Mocked ***********");
return header;
}
};
// --mocking Details repo
new MockUp<U>() {
@Mock
public List<Details> findByHeaderId(Long id) {
List<Details> list = new ArrayList<Details>();
// -- mocking logic here
System.out.println("********** DetailsRepository Mocked ***********");
return list;
}
};
Details detailsTO = detailsServicesImpl.getDetails(Long.valueOf(Long.MAX_VALUE));
Assert.assertEquals(Long.MAX_VALUE, detailsTO.getId().longValue());
}
@Repository
public interface DetailsRepository extends JpaRepository<Details, Long>, BatchRepository<Details> {
List<Details> findByHeaderId(Long id);
}
Aucun commentaire:
Enregistrer un commentaire