How to disable/mock Spring EntityListener in JUnit test

1.8k views Asked by At

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);
    }
}
0

There are 0 answers