0

I have a scenario where I want to reference a private class - not test that class.

I am using Spring JDBCTemplate to query db and using a row mapper (which is private class of dao) for mapping the resultset to my object.

Test case is mocking like when(dao.method(query, rowmapper, param)).thenReturn(something)

Possible solutions: Make rowmapper default access and keep test case in the same package.

However my belief is that why to make code changes for the sake of test cases?

I was wondering if Java reflection can be of any use in this or not ? I couldn't find any thing on that so if someone has already been through such thing then please share.

Vikrant Kashyap
  • 6,398
  • 3
  • 32
  • 52
Ketan
  • 738
  • 2
  • 9
  • 20
  • See http://stackoverflow.com/questions/11483647/how-to-access-private-methods-and-private-data-members-via-reflection – PM 77-1 Apr 05 '16 at 02:54

1 Answers1

1

You can use Java reflection in initial method to get the reference to private class.

Ha Doan
  • 135
  • 1
  • 11