RunningMedian { public double getMedian() { if (upperHalf.isEmpty() && lowerHalf.isEmpty()) { throw new RuntimeException("Add values before getting the median"); } if (upperHalf.size() > lowerHalf.size()) { return upperHalf.peek(); } else if (lowerHalf.size() > upperHalf.size()) { return lowerHalf.peek(); } else { return 0.5 * (lowerHalf.peek() + upperHalf.peek()); } }  void add(double value); double getMedian();  }
@Test(expected = RuntimeException.class) public void testGetMedian_empty() { runningMedian.getMedian(); }