Suppose I have this:
@Transactional(rollbackFor = NotificationException.class) public interface PersonManagerService { public void addPerson(Person person); }
and implementation:
public class PersonManagerServiceImpl implements PersonManagerService { public OtherService otherService; public void addPerson(Person person) {
How could I make fun of the otherService dependency when using the addPerson method in the database?
My scenario is that I want to verify that a specific exception causes the save of the added face to be rolled back. This exception comes from the OtherService class, which I do not want to call the real version. I am currently using Spring Transaction annotations, so I have a test like this:
@RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = {various locations}) public class Test() { @Autowired PersonManagerService service; @Test public void test() {
If I try to use an auto wired bean, I get an IllegalArgumentException because it is a proxy. If I made Impl not use the interface, I could use CGLIB, but I do not want to do this. If I create the program code, then it is not tied to the transaction flow. What other options do I have?
source share