سؤال

I have a REST service class in which uriInfo object is automatically injected through @UriInfo annotation. Now, while writing JUnit for this class, I want to get a mock object created for this UriInfo object without introducing any new setter methods into the tested class just for the sake of setting the mocked UriInfo into it. Kindly let me know if you have any suggestions. We are using EasyMock and PowerMock.

هل كانت مفيدة؟

المحلول

You can use Powermock's Whitebox to modify the internal state of an object. One of the simplest invocations is:

Whitebox.setInternalState(tested, myMock);

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top