title: How do I test local inner class methods in java?
body: <p>In many application I often have algorithms which make use of dedicated sub-algorithms (or simply well defined pieces of code). </p>
  
  <p>Till now, when I wrote the main algorithm, i created a private method for each sub-algorithm like in the example below (OldStyle):</p>
  
  <pre><code>public class OldStyle {
  
      public int mainAlg() {
          int x = subAlg01();
          int y = subAlg02();
          int z = x * y;
          return z;
      }
  
      private int subAlg01() {
          return 3;
      }
  
      private int subAlg02() {
          return 5;
      }
  }
  </code></pre>
  
  <p>This worked fine but I didn't like having a proliferation of methods (subAlg01 and subAlg02) which, even if private, were only used by one method (mainAlg).</p>
  
  <p>Recently I dicovered the use of local inner classes and now my example is (NewStyle):</p>
  
  <pre><code>public class NewStyle {
  
      public int mainAlg() {
          class Nested {
  
              public int subAlg01() {
                  return 3;
              }
  
              public int subAlg02() {
                  return 5;
              }
          }
          Nested n = new Nested();
          int x = n.subAlg01();
          int y = n.subAlg02();
          int z = x * y;
          return z;
      }
  }
  </code></pre>
  
  <p>I like it very much but now I have the following problem: how do I test subAlg01 and subAlg02 using JUnit?</p>
  
  <p>By the way: I'm using eclipse.</p>
  
  <p>Thanks for you help.</p>
  
  <p><strong>Edit</strong>: I try to explain better: I have, let's say, a sorting algorithm and I want to test it to be sure it runs as expected. This sorting algorithms is used by only method m of class X. I could make it a private method of class X but class X usually has nothing to do with sorting, so why "spoil" class X with the sorting method? So I put it inside method m. Some time later I want to improve my sorting algorithm (I make it faster) but I want to be sure that it's behavior is as expected, so I want to re-test it with the original tests.</p>
  
  <p>That's what I want to do, maybe there is no solution, I hope someone may help me.</p>
  
  <p><strong>Edit after answer choice</strong>. I selected Rodney answer because his solution is the one I adopted:  a standalone helper class helps me (it's a helper!) to have a clear view of what are the sub methods and it also gives me the ability to test them. </p>