title: How do i test my for-loops and arraylist with JUnit in java
body: <p>hey i'm newbie when it comes to testing with JUnit and i dont know how to test for-loops/ Loops. In my code you can see some of the for-loops i have to test. I mostly want to test the top5 list method and the printListOfResults. Please help a friend in need </p>
  
  <pre><code>import java.util.ArrayList;
  import java.util.Comparator;
  import java.util.Collections;
  import java.util.HashMap;
  import java.util.Iterator;
  import java.util.LinkedHashMap;
  import java.util.List;
  import java.util.Map;
  import java.util.Map.Entry;
  import java.util.Set;
  /**
   * Write a description of class Discipline here.
   * 
   * @author (your name) 
   * @version (a version number or a date)
   */
  public class Discipline 
  {
      private String disciplineName;
      private HashMap &lt;EliteSwimmer, Result&gt; eliteResults;  
  
      /**
       * Constructor for objects of class Discipline.
       * @param disciplineName The discipline name.
       */
      public Discipline(String disciplineName)
      {
          this.disciplineName = disciplineName;
          eliteResults = new HashMap&lt;EliteSwimmer, Result&gt; () ;
      }
  
      /**
       * Get the value of disciplineName.
       * @return the value of disciplineName.
       */
      public String getDisciplineName ()
      {
          return disciplineName;
      }
  
      /**
       * Add the elite swimmer's best training result.
       * @param elite The elite member.
       * @param res The elite member's best training result.
       */
      public void addEliteResults(EliteSwimmer elite, Result res)
      {
          if (res.getType() == 0) {
              eliteResults.put(elite, res);
          }
          else {
              System.out.println("Not a training result");
          }
      }
  
      /**
       * Print a list with the elite swimmers' best training results. 
       */
      public void printListofResults()
      {
          Set set = eliteResults.entrySet();
          Iterator iterator = set.iterator();
          while(iterator.hasNext()) {
              Map.Entry mentry = (Map.Entry)iterator.next();
              System.out.println("Elite Swimmer: "+ ((EliteSwimmer)mentry.getKey()).getName());
              System.out.println("Result: " + ((Result) mentry.getValue()).getTime());
  
          }
  
      }
  
      /**
       * Print a list with the top 5 elite swimmers, based on their training results.
       */
      public void Top5List()
      {
          Set&lt;Entry&lt;EliteSwimmer,Result&gt;&gt; set = eliteResults.entrySet();
          List&lt;Entry&lt;EliteSwimmer,Result&gt;&gt; list = new ArrayList&lt;Entry&lt;EliteSwimmer,Result&gt;&gt;(set);
          Collections.sort( list, new Comparator&lt;Map.Entry&lt;EliteSwimmer,Result&gt;&gt;()
              {
                  @Override
                  public int compare( Map.Entry&lt;EliteSwimmer,Result&gt; o1, Map.Entry&lt;EliteSwimmer,Result&gt; o2 )
                  {          return Double.compare(o1.getValue().getTime(), o2.getValue().getTime() ); }
              });
  
          LinkedHashMap&lt;EliteSwimmer,Result&gt; sortedHashMap=new LinkedHashMap&lt;EliteSwimmer,Result&gt;();  
          for (Map.Entry&lt;EliteSwimmer,Result&gt; entry: list) {  
              sortedHashMap.put(entry.getKey(), entry.getValue());  
          }  
          int counter = 0;
          for(Map.Entry&lt;EliteSwimmer,Result&gt; entry: list)
          {counter ++;
              System.out.println("Elite swimmer: " + entry.getKey().getName()+"        Result: " +entry.getValue().getTime());
              if (counter == 5)
                  break;
          }
      }
  }
  </code></pre>