1

I am trying to mock generics I am able to mock some of the generic expression but I have no idea how to mock generic initialization

Jim Garrison
  • 85,615
  • 20
  • 155
  • 190
  • See http://stackoverflow.com/questions/1652692/using-mockito-to-mock-classes-with-generic-parameters – RCB Jun 30 '16 at 15:27

1 Answers1

0

Generic in java are a compiler trick implemented using erasure (with the option of some runtime artifacts, true). So there isn't really a separate class definition for HttpEntity<String> vs HttpEntity<Foo>.

So you would simply need to (A) simply cast and (B) make sure a mock that represents a certain type is only used with that type and not cast and re-used for another type.

If this is not answering your question, please paste the exact source code you are trying to unit test and indicate which component are you testing and which ones you are trying to mock.

Creos
  • 2,445
  • 3
  • 27
  • 45