### Question:
TimePeriod implements Comparable<TimePeriod> { @Override public int compareTo(TimePeriod other) { int start = startTime.compareTo(other.startTime); if (start != 0) { return start; } int end = endTime.compareTo(other.endTime); return end; } TimePeriod(long startTime, long endTime);  TimePeriod(Calendar startTime, Calendar endTime);  TimePeriod(Calendar startTime, long seconds);  TimePeriod(Calendar startTime, int time, TimeUnit sourceUnit);  TimePeriod(int time, TimeUnit sourceUnit); long getDuration(); static long convertToMinutes(TimePeriod duration); static long convertToHours(TimePeriod duration); static long convertToDays(TimePeriod duration); Calendar getStartTime(); long getStartTimeInSeconds(); Calendar getEndTime(); long getEndTimeInSeconds(); @Override boolean equals(Object obj); @Override int hashCode(); @Override int compareTo(TimePeriod other); @Override String toString(); boolean isValid();  }### Answer:
@Test public void testCompareTo() { System.out.println("compareTo"); TimePeriod time = new TimePeriod(time1, time2); TimePeriod instance = new TimePeriod(time1, time2); int expResult = 0; int result = instance.compareTo(time); assertEquals(expResult, result); GregorianCalendar cal = new GregorianCalendar(); cal.setTimeInMillis(time2.getTimeInMillis() - (1000 * (timeAgoSeconds / 2))); time = new TimePeriod(cal, time2); expResult = -1; result = instance.compareTo(time); assertEquals(expResult, result); cal = new GregorianCalendar(); cal.setTimeInMillis(time2.getTimeInMillis() - (1000 * timeAgoSeconds * 2)); time = new TimePeriod(cal, time2); expResult = 1; result = instance.compareTo(time); assertEquals(expResult, result); }