title: How to inject mocked dependencies with jmockit
body: <p>Currently I try to understand how the <code>@Injectable</code> and <code>@Tested</code> annotations are working. I already did some tests and understood the concept but I didn't get how I can use those annotations in real world applications.</p>
  
  <p>Let's say we are developing a language translator class which depends on a web service. The web service methods are encapsulated in a separate class:</p>
  
  <pre><code>// class to test
  public class Translator() {
      private TranslatorWebService webService;
  
      public String translateEnglishToGerman(String word){
          webService = new TranslatorWebService();
          return webService.performTranslation(word);
      }
  }
  
  // dependency
  public class TranslatorWebService {
      public String performTranslation(String word){
      // perform API calls    
      return "German Translation";
      }
  }
  </code></pre>
  
  <p>To test the <code>Translator</code> class independently, we would like to mock the <code>TranslatorWebService</code> class. According to my understanding, the test class should look like:</p>
  
  <pre><code>public class TranslatorTest {
      @Tested private Translator tested;
      @Injectable private TranslatorWebService transWebServiceDependency;
  
      @Test public void translateEnglishToGerman() {
          new Expectations() {{
              transWebServiceDependency.performTranslation("House");
              result = "Haus";
          }};
  
          System.out.println(tested.translateEnglishToGerman("House"));
      }
  }
  </code></pre>
  
  <p>When I executed this test case for the first time, I expected the result "Haus". At second glance I saw that the line </p>
  
  <pre><code>webService = new TranslatorWebService();
  </code></pre>
  
  <p>will always override the injected mock instance with a real instance. But how can I avoid this behavior without changing the business logic?</p>