title: EasyMock: Mock out a constructor call in java
body: <p>I have a looked at similar questions on this board, but none of them answer my question. This sound strange, but is it possible to mock out a constructor call on the object you're mocking.</p>
  
  <p>Example:</p>
  
  <pre><code>class RealGuy {
  
     ....
     public void someMethod(Customer customer) {
       Customer customer = new Customer(145);
     }
  }
  class MyUnitTest() {
    public Customer customerMock = createMock(Customer.class)
    public void test1() {
      //i can inject the mock object, but it's still calling the constuctor
      realGuyobj.someMethod(customerMock);
      //the constructor call for constructor makes database connections, and such.
    }
  }
  </code></pre>
  
  <p>How can I expect a constructor call? I can change the Customer constructor call to use newInstance, but im not sure if that will help. I have no control over what the body of the <code>new Customer(145)</code> constructor does.</p>
  
  <p>Is this possible?</p>