CA-142451: Unit tests

Factor code for clarity.

Signed-off-by: Flavien Quesnel <flavien.quesnel@citrix.com>