title: JUnit & warning exporting non public type through public api
body: <p>My unit test uses an enum as datapoints (see <a href="https://github.com/junit-team/junit/wiki/Theories" rel="nofollow noreferrer">JUnit Theories</a>).</p>
  
  <p>This enum is only used in the test, therefore I prefer it to be encapsulated and a private nested class.  JUnit requires test methods to be public.  The test methods have the private enum as argument:</p>
  
  <pre><code>@RunWith(Theories.class)
  class ExampleTest {
      private enum Lists {
          EMPTY,
          SINGLE_ELEMENT,
          OTHER_ELEMENT,
          TWO_ELEMENTS;
  
          public Object createElements() {
              // Imagine createElements being abstract and 
              // implemented in each enum constant.
          }
      }
  
      @DataPoints
      public static final Lists[] ALL_LISTS = Lists.values();
  
      private List&lt;Object&gt; tested;
  
      @Theory
      public void add_sizeIncreased(Lists elementsToAdd) {
          int oldSize = tested.size();
          int nElementsAdded = elementsToAdd.size();
  
          tested.addAll(elementsToAdd);
  
          assertThat(tested.size(), is(equalTo(oldSize + nElementsAdded));
      }
  }
  </code></pre>
  
  <p>This rightly causes the warning/hint: "Exporting non-public type through public API" (in Netbeans at least).</p>
  
  <p>What is the correct way to solve this?</p>
  
  <ul>
  <li>I have not found a 'SuppressWarnings'-annotation for it;</li>
  <li>The answers to related SO questions <a href="https://stackoverflow.com/questions/2659936/exporting-a-non-public-type-through-public-api">Sachin</a>, <a href="https://stackoverflow.com/questions/2744851/exporting-non-public-type-through-public-api">Aselivanov</a>, and <a href="https://stackoverflow.com/questions/2937589/exporting-non-public-type-through-public-api">user329820</a> argue that the warning is correct and that you should make the types public.  The unittest differs from these other situations in that the test's public methods are not called by any other code.<br/>
  <em>(I admit the testframework calls them, but I hope you see my point).</em></li>
  <li>As far as I know, JUnit will not invoke private test methods, in fact it throws an error when it sees a private method annotated with 'Theory'.</li>
  </ul>