Add unit tests.

Uses rewire for mocking private module members.