Add unit tests
(cherry picked from commit 7f1a0fc2b257e8e578a1905072eba144ea8f5571)