2

In a JUnit test that persists entities, how can I disable or mock a registered EntityListener?

@Entity
@EntityListeners(Listener.class)
public class Entity {}

public class Listener {
    @PostPersist
    public void postPersist(Entity entity) {...}
}

@RunWith(SpringRunner.class)
@SpringBootTest
public class Tests {

    //how to disable or mock Listener here?

    @Test
    public void test() {
         ...
         entityRepository.save(entity);
    }
}
cnmuc
  • 6,025
  • 2
  • 24
  • 29
  • Have you seen this post? https://stackoverflow.com/questions/47590917/entitylisteners-injection-junit-testing – Francis Robitaille Jul 31 '19 at 20:07
  • 1
    @FrancisRobitaille sure, but I don't want to inject something to my listener. I want to disable the listener while running my Junit tests. – cnmuc Jul 31 '19 at 20:14
  • @cnmuc have you able to handle this to disable/mock the listeners? – NHS Oct 11 '21 at 09:06

0 Answers0