BS-11338 : Sonar : Reduce complexity

- Refactor the code to reduce the duplication
- Rewrite some tests to replace old waiting mechanism by the waiting mechanism by event