Merged test classes

Merged test classes with the upstream changes, however, they can not be
properly tested until remaining merge conflicts fixed.