title: Java Unit testing path matching
body: <p>I am trying to understand Unit testing and how the correct classes are being fetched on test time,
  I'm having a hard time understanding exactly what is going on behind the scenes and how safe/correct my usages for this are.</p>
  
  <p>This is a very simple example of what i am trying to do, i wrote it here inline so it probably contains some errors, please try to ignore them, as stupid as they may be.  </p>
  
  <p>A very simple project directory:</p>
  
  <p><code>ba/src/main/java/utils/BaUtils.java
  ba/test/main/java/utils/BaUtilsTest.java
  notBa/src/main/java/im/BaObj.java</code></p>
  
  <p>BaUtils.java code:  </p>
  
  <pre><code>package com.ba.utils;
  import notBa.im.BaObj;
  public class BaUtils{
      public String doSomething(BaObj obj){
          obj.doSomething();
      }
  }
  </code></pre>
  
  <p>I would like to test BaUtils wihtout actually calling doSomething, and i can't change anything on <code>BaObj</code> class or <code>notBa</code> package. I know that i can (by 'can' i mean it will work) add a new java file to 'ba' project (<code>ba/test/java/notBa/main/java/im/BaObj.java</code>) that will have the same package as the original BaObj, and at runtime the test will import this one instead of the real one, so <code>BaUtils</code> code is tested but <code>BaObj</code> code is not excecuted.<br>
  that should look something like like : </p>
  
  <pre><code>package notBa.im.Baobj
  public class BaObj{
      public void doSomething(){
          System.out.println("Did something");
      }
  }
  </code></pre>
  
  <p>My questions are (And thank you for reaching this far):</p>
  
  <p>How does this work (Reading references would be great).<br>
  Is this kind of test building considered 'good' or 'safe' ?</p>
  
  <p>Thanks!</p>