title: How to mock array of class using Mockito
body: <p>I want to mock Order array class  Order[].class.  below mockMapper reads Order[].class and need to return Order[].class.  </p>
  
  <p>Service class</p>
  
  <pre><code>public class OrdersConnectorImpl {
      public Order getOrderById(String Id, OrderType orderType) throws Exception {
  
          Response response = null;
          response = orderServiceTarget.queryParam("ID", Id).queryParam(ORDER_TYPE, orderType).request().accept(MediaType.APPLICATION_JSON)
                  .get();
          final StatusType responseStatus = response.getStatusInfo();
          final String serverResponseStr = response.readEntity(String.class);
          if (responseStatus.equals(Response.Status.OK)) {
              objectMapper = getObjectMapper(); // we have a private method in this class
              Order[]  orders = objectMapper.readValue(serverResponseStr, Order[].class);
              if(orders.length&gt;0) {
                  return orders[0];
              }
          }
      }
  }
  </code></pre>
  
  <p>Test class</p>
  
  <pre><code>      public class OrdersConnectorImplTest {
  
          private ObjectMapper mockMapper;
  
          private class MockOrdersConnectorImpl extends OrdersConnectorImpl {
  
              @Override
              protected ObjectMapper getObjectMapper() {
                  return mockMapper;
              }
          }
  
  
      }
        @Test
  public void test_getRenewalOrderForContract() throws Exception {
      Response mockResponse = mock(javax.ws.rs.core.Response.class);
      Order mockOrder = mock(Order.class);
      when(mockResponse.getStatusInfo()).thenReturn(Status.OK);
      when(mockResponse.readEntity(String.class)).thenReturn("{}");
      when(mockBuilder.get()).thenReturn(mockResponse);
      when(mockMapper.readValue("{}", Order[].class)).thenReturn(mockOrder); // this is the problem line
      orderConnector.getOrderById("id", OrderType.NEW);
  
  }
  }
  </code></pre>
  
  <p>Please correct me here how to return expected.</p>