title: Overriding src clases with test classes for java unit testing
body: <p>I am trying to understand the JUnit way of imports classes at test time.<br>
  I noticed that creating a mock class with the same name of a src class, and the same package, will cause a test to import that one instead of the real src class.<br>
  For example :  </p>
  
  <pre><code>src/main/java/MyObject.java
  src/main/java/ObjectPrinter.java
  
  src/test/java/MyObject.java
  src/test/java/ObjectPrinterTest.java
  </code></pre>
  
  <p>Where both the <code>main/java/MyObject.java</code> and the <code>test/java/MyObject.java</code> declares the same package (both files starts with the same <code>package XXX</code> decleration).
  The <code>ObjectPrinter.java</code> (which is called by <code>ObjectPrinterTest.java</code> at test time) will have an <code>import XXX.MyObject</code> decleration.  </p>
  
  <p>How is it that in test time the <code>import XXX.MyObject</code> will import the <code>test/java/MyObject.java</code> and a 'production' call will call the <code>src/java/MyObject.java</code>?.<br>
  Is this kind of directory building safe? Is it common usage?<br>
  Where can i read more about this specific flow?  </p>
  
  <p>Thanks!</p>