Calculator { public Double average() throws NoElementsException { Double total = 0.0; if(values.isEmpty()) { throw new NoElementsException(); } for (Double value : values) { total += value; } return total/(double)values.size(); } Calculator(); void add(Double value); Double average(); Double median();  }
@Test void testAverage() { try { assertEquals(1007.00/4, calculator.average(), .01); } catch (NoElementsException e) { fail("Caught NoElementsException"); e.printStackTrace(); } }
@Test void testEmpty() { Calculator calculator = new Calculator(); try { calculator.average(); fail("Should have had an exception"); } catch(NoElementsException e) { } }