title: How to test an array of objects with junit in java
body: <p>I'm new here, and I'm new to programming too.
  This is the code I'm writing, this is one of the two classes in the project, "Student":</p>
  
  <pre><code>interface Comparable{
      public boolean youngerThan(Comparable c);
  }
  
  public class Student implements Comparable{
        private String name;
        private int age;
  
  
    public Student(String n, int a){
      this.name=n;
      this.age=a;
  }
  
    public String getName(){
        return this.name;
    }
  
    public int getAge(){
        return this.age;
    }
    public void setStudent(String n, int a){
        this.name=n;
        this.age=a;
    }
    public String toString() {
  
        return this.getName()+" ("+this.getAge()+"years)";
    }
    public boolean youngerThan(Comparable c){
        Student s;
        s=(Student)c;
        if(this.getAge()&gt;s.getAge())
            return false;
        if (this.getAge()==s.getAge())
            return false;
        else 
            return true;
    }
  
    public static void main(String[] args){
      Student[] student= new Student[5];
  
      student[0].setStudent("Marco", 20);
      student[1].setStudent("Giacomo", 19);
      student[2].setStudent("Susan", 24);
      student[3].setStudent("Billie", 25);
      student[4].setStudent("Max", 18);
  
  
     }
  
   }
  
  
   }
  </code></pre>
  
  <p>And the other one, which consists of the method "Ordinator", that uses the bubble sort to put in order the "Students" based on the age, from the younger to the older:</p>
  
  <pre><code>public class Ordinator {
      public static void order(Comparable[]list){
          int imin;
          for(int ord=0; ord&lt;list.length-1;ord++){
              imin=ord;
              for(int i=ord +1; i&lt;list.length; i++){
                  if(list[i].youngerThan(list[imin]));
                    Comparable temp=list[i];
                    list[i]=list[imin];
                    list[imin]=temp;
              }
          }
      }
  }
  </code></pre>
  
  <p>Now I have to test the method order with Junit to see if it works. But I don't know how to test an array of objects, in particular in this situation. Hope someone can help! Thanks in advance :)</p>