17
@Transactional(propagation = Propagation.REQUIRED)
public void exe() {
try {
Reserve reserveInfo = newTransactionTemplate.execute(new TransactionCallback<Reserve>() {
@Override
public Reserve doInTransaction(TransactionStatus status) {
return reserveService.callReserve(reserveDetails);
}
});
if(reserveInfo != null && reserveInfo.getStatus()=="DONE") {
someOtherService.doSomething();
}
} finally {
if(reserveInfo!= null && reserveInfo.getStatus().equals("DONE")){
final String id = reserveInfo.getId();
Release releaseInfo = newTransactionTemplate.execute(new TransactionCallback<Release>() {
@Override
public Release doInTransaction(TransactionStatus status) {
return reserveService.callRelease(id);
}
});
if (releaseInfo.getStatus() != "RELEASED") {
throw new RuntimeException("Problem in releaseing");
}
}
}
}
This is the sample code I want to test. I couldn't find much on testing anonymous class on net. I want to test the exe() method, go through newTransactionTemplate.execute method and mock the call to reserveService.callReserve(reserveDetails).
Can any body please suggest how can I test this situation?
here is the sample how i'm trying to test:
private SomeService someService = null;
@Mock
private ReserveService mockReserveService;
@Mock
private ReleaseService mockReleaseService;
@Mock
private TransactionTemplate mockTransactionTemplate;
@Mock
private SomeOtherService mockSomeOtherService;
@BeforeMethod
public void setup(