SWE 619 In Class Exercise Number 0B
August 29, 2017


This may look like (just) a testing exercise, but I want us to view it as a specification exercise.

  /**
    * Returns the mininum element in a list
    * @param list Comparable list of elements to search
    * @return the minimum element in the list
    * @throws NullPointerException if list is null or
    *         if any list elements are null
    * @throws ClassCastException if list elements are not mutually comparable
    * @throws IllegalArgumentException if list is empty
    */
    public static <T extends Comparable<? super T>> T min (List<? extends T> list) {
       if (list.size() == 0) {
          throw new IllegalArgumentException ("Min.min");
       }

       T result = list.get(0);

       for (T comp : list) {
           if (comp.compareTo(result) < 0) {    // throws NPE, CCE as needed
               result = comp;
           }
       }
       return result;
    }
Identify tests you think are necessary for this code. Justify each test.

How do we transform these tests into JUnit?