title: Having helper methods in junit class
body: <p>I want to unit test a class, <code>Class A</code>, but it has a dependency on another class that uses a <code>user session</code> method.  The method that I want to test does not involve <code>user session</code>. Can I make helper method in <code>Class A</code> that would replicate the behavior of the <code>Class B</code> method that I need?</p>
  
  <p>I know it's not clear, let's dig some code to get clear understanding....</p>
  
  <pre><code>public void testDetails() throws Exception
  {
      //Some logic that generates DetailsTOList
      saveDetailsHelper(DetailsTOList);
      int detailsSize = getDetailsSize();
      assertNotNull(detailsSize);
  }
  </code></pre>
  
  <p>Now <code>getDetailsSize()</code> get size information from a database. <code>Class B</code> has this method, but I cannot create an object of <code>Class B</code> and test this method since <code>Class B</code> gets session information from User, and I can set session information from JUnit class. </p>
  
  <p>I have created <code>saveDetailsHelper</code> method that replicates behavior of <code>Class B - saveDetails()</code> method, and am calling that in <code>testDetails()</code> method as shown above. </p>
  
  <p>My question: </p>
  
  <ol>
  <li>can we have helper methods in <code>junit class</code>?</li>
  <li>What is best approach to deal with this situation?</li>
  </ol>