Fix unit test error by changing metadata creation from constructor to factory method