title: Mocking factory pattern in Java
body: <p>It may look similar to my <a href="https://stackoverflow.com/questions/28539036/java-mocking-custom-objects/28539229?noredirect=1#comment45418054_28539229">question</a>. I have a simple animal factory.</p>
  
  <pre><code>public class AnimalFactory {
  
      public Animal getAnimal(String type) {
          if ("canine".equals(type)) {
              return new Dog();
          } else {
              return new Cat();
          }
      }
  
  }
  </code></pre>
  
  <p>and class for </p>
  
  <pre><code>public interface Animal {
      void makeSound();
  }
  
  public class Dog extends Animal {
      void makeSound() {
      }
  }
  
  public class Dog extends Animal {
      void makeSound() {
      }
  }
  </code></pre>
  
  <p>I have some doubts. Does <code>AnimalFactory</code> violate the dependency inversion principle? Is it possible to unit test <code>AnimalFactory</code> without making calls to the actual <code>Dog</code> and <code>Cat</code> classes or do I have to refactor my code?</p>