title: jmockit mocked constructor not returning expected value
body: <p>I am trying to unit test a class where one of its methods returns an instance of a collaborator class: depending on the values of its arguments it either returns a newly created instance, or a saved, previously created instance.</p>
  
  <p>I mock the constructor call in an Expectations and set the result to a value that is a mocked instance of the collaborator. But when I test the method with parameter values that cause it to create a new instance, the mocked constructor, and therefore the method, does not return the expected value.</p>
  
  <p>I have simplified this down to the following:</p>
  
  <pre><code>package com.mfluent;
  import junit.framework.TestCase;
  import mockit.Expectations;
  import mockit.Mocked;
  import mockit.Tested;
  import org.junit.Assert;
  import org.junit.Test;
  
  public class ConstructorTest extends TestCase {
  
      static class Collaborator {
      }
  
      static class ClassUnderTest {
          Collaborator getCollaborator() {
              return new Collaborator();
          }
      }
  
      @Tested
      ClassUnderTest classUnderTest;
  
      @Mocked
      Collaborator collaborator;
  
      @Test
      public void test() {
          new Expectations() {
              {
                  new Collaborator();
                  result = ConstructorTest.this.collaborator;
              }
          };
  
          Collaborator collaborator = this.classUnderTest.getCollaborator();
          Assert.assertTrue("incorrect collaborator returned", collaborator == this.collaborator);
      }
  }
  </code></pre>
  
  <p>Any ideas on why this test fails and how to make it work would br greatly appreciated.</p>
  
  <p>Thanks in advance,</p>
  
  <p>Jim Renkel
  Senior Technical Staff
  mFluent, Inc. LLC</p>