title: How to mock a object which created using new method
body: <p>We are using Mockito to mock objects. How do I mock an object that is created in service code? Below is the service code and test code. Any help?  Also I don't want to use Powermock now.</p>
  
  <pre><code>public class EventPublisher  {
      public void publishEvent(final String eventJson) {
  
          try {
              ObjectMapper objectMapper = getObjectMapper(true);
              Test testJson = objectMapper.writeValueAsString(event);
              testJson.getName();
          } catch (JsonProcessingException e) {
  
              return;
          }
          //publish();  some external call
      }
      private ObjectMapper getObjectMapper(boolean enableRootElement) {
          ObjectMapper objectMapper = new ObjectMapper();
          objectMapper.configure(SerializationFeature.WRAP_ROOT_VALUE, enableRootElement);
          return objectMapper;
      }
  }
  </code></pre>
  
  <p>test code:</p>
  
  <pre><code>   public void testPublishEvent() throws Exception {
              ObjectMapper objectMapper = mock(ObjectMapper.class);
                  when(objectMapper.writeValueAsString(json))
  .thenThrow(mock(JsonProcessingException.class));  //this is not getting invoked
  
  
  }
  </code></pre>