Pulled duplicate code out into seperate method.

This eliminates duplicate code in the tests.