refactored test - copypaste replaced by function

If this pull request will be accepted, I would refactor other tests similarly.