Refactor test code to reduce duplication

Change-Id: Ie196e02926bd0a38277eee93c3c2063337ff2b25
Closes-bug: 1365959
Merge "Refactor test code to reduce duplication"