refactoring lock for unit test