title: Mocking Generic types using Mockito
body: <p>I am writing a test case using JUnit and Mockito for the REST services using jersey. I am getting a null object instead of a mocked object for the Response class.</p>
  
  <p>Code under test</p>
  
  <pre><code>Response response = builder
                          .put( Entity.entity( new ByteArrayInputStream( jsonObj.toString().getBytes() ), MediaType.APPLICATION_JSON ), Response.class );
  </code></pre>
  
  <p>Test case:</p>
  
  <pre><code>private Invocation.Builder builder; 
  private Entity&lt;ByteArrayInputStream&gt; inputStream;
  private Response response;
  @Before
  public void setUp() throws Exception {
      builder = mock( Invocation.Builder.class );
      inputStream = (Entity&lt;ByteArrayInputStream&gt;)mock( Entity.class );
      response = mock( Response.class );
  }
  
  @Test
  public void myTest() {
  when( builder.put( inputStream, Response.class ) ).thenReturn( response );
  }
  </code></pre>
  
  <p>So this line of code gives me a null response. Is there any other way to do this. </p>
  
  <p>Thanks.</p>