title: Unit: How to write test case using jUnit and Mockito
body: <p>I am very new to Mockito and jUnit and TDD in general and I try to learn the right way to do TDD. I need couples of example to kick start my brain. SO please help me</p>
  
  <p>So I have a method <code>getNameInc(String dirPath, String filenName)</code>. So given a fileName like <code>bankAccount.pdf</code>, and if in this folder, no file name <code>bankAccount.pdf</code>, then return <code>bankAccountAA.pdf</code>. If there is exist one <code>bankAccount.pdf</code> then <code>return bankAccountBB.pdf</code> The <code>increment</code> is <code>AA-ZZ</code>. When it reach <code>ZZ</code> then it roll back to <code>AA</code>. I already implement the logic of this method. How do I unit test this method using Mockiti and jUnit?</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>Here is the class and methods that are involved.</p>
  
  <pre><code>public class PProcessor{
  
      private final Map&lt;Integer, String&gt; incMap = new HashMap&lt;Integer, String&gt;();
  
      private String getNameInc(String dirPath, String filenName){
           String[] nameList = new File(dirPath).list(new FilenameFilter(){
              public boolean accept(File file, String name) {
                  //only load pdf files
                  return (name.toLowerCase().endsWith(".pdf"));
              }
          });
          //Return the number of occurance that a given file name appear
          //inside the output folder.
          int freq = 0;
          for(int i=0; i&lt;nameList.length; i++){
  
              if(fileName.equals(nameList[i].substring(0, 8))){
                  freq++;
              }
          }
          return incMap.get(freq);
      }
  
      private void generateIncHashMap(){
          incMap.put(new Integer(0), "AA");
          incMap.put(new Integer(1), "BB");
          incMap.put(new Integer(2), "CC");
          ...
      }
  }
  </code></pre>
  
  <p><code>generateIncHashMap()</code> will be called in the constructor to pre-generate the hash map</p>