This is Johan Haleby's Typepad Profile.
Join Typepad and start following Johan Haleby's activity
Join Now!
Already a member? Sign In
Johan Haleby
Recent Activity
Another thing you can do (if you're not willing to refactor your code) is to simply use PowerMock which allows you to mock static methods using an EasyMock or Mockito like syntax.
@Marco: It represents the value to set. Whitebox tries to figure out which field to assign the value to. If it's unable to do so an exception is thrown. /Johan
PowerMock contains reflection utilities in its Whitebox class. Besides providing something similar to Spring's ReflectionTestUtil: Whitebox.setInternalState(instance, "fieldName", objectToSet); you can also do: Whitebox.setInternalState(instance, objectToSet); to make your code more refactor friendly. I use this from time to time when I'm in your situation. Whitebox is available in the Maven central repo (powermock-reflect). /Johan
Johan Haleby is now following The Typepad Team
Mar 17, 2011