Remove duplicated code in unit test.