Unit tests cherry-picked from Nitin