BS-11252 : Sonar : Reduce complexity & Add unit tests

- Refactor the code to reduce the complexity