Fix for a slightly unreliable unit test as well as reduced unit test code duplication.