title: The best way to test classes implementing the same interface
body: <p>So, for example I have a few classes implementing the <code>List&lt;T&gt;</code> interface. How to test them - whether they implement the methods correctly?</p>
  
  <p>Now I only see one way to do so:</p>
  
  <pre><code>public class MyListImplementationsTest {
      private Collection&lt;List&lt;Integer&gt;&gt; listImplementations;
  
      @BeforeClass
      public static void setUp() throws Exception {
          listImplementations = Arrays.asList(
              new QuickList&lt;Integer&gt;(), new EfficientMemoryList&lt;Integer&gt;()
          );
      }
  
      @Test
      public void testIsEmptyAfterCreationEmptyList() {
          // Use forEachList(handler) in order to not iterate
          // the lists manually every time.
          // May be there is no need to do so,
          // because using &lt;&lt;for (item : items)&gt;&gt; instead of
          // iterating using index prevents from OutOfBounds errors
          forEachList(new OnEachListHandler&lt;Integer&gt;() {
              @Override
              public void onEach(List&lt;Integer&gt; list) {
                  assertTrue(list.isEmpty());
              }
          });
      }
  
      private &lt;T&gt; void forEachList(OnEachListHandler&lt;T&gt; handler) {
          for (List&lt;T&gt; each : listImplementations) {
              handler.onEach(each);
          }
      }
  
      private static interface OnEachListHandler&lt;T&gt; {
          void onEach(List&lt;T&gt; each);
      }
  }
  </code></pre>
  
  <p>But in my opinion it's complicated to iterate lists in every test.</p>
  
  <p>Is there more elegant way to test classes implementing the same interface in <code>JUnit4</code>?</p>