### Question:
DaylightOffsetCalculator { Calendar calculate(final TimeZone tz, final Calendar target) { final Calendar targetWithDSTOffset = Calendar.getInstance(); targetWithDSTOffset.setTimeInMillis(target.getTime().getTime() + getDSTOffset(tz, startMatdTime, endMatdTime)); return targetWithDSTOffset; } DaylightOffsetCalculator(final Date startMatdTime, final Date endMatdTime);   }### Answer:
@Test public void testCalculateBetweenNonDSTStartAndEndGivesZeroOffset() throws ParseException { final DaylightOffsetCalculator nonDSTStartAndEndCalculator = new DaylightOffsetCalculator( DateUtils.parseDateOozieTZ("2013-01-18T00:00Z"), DateUtils.parseDateOozieTZ("2014-01-18T00:00Z")); final Calendar target = Calendar.getInstance(); target.setTime(DateUtils.parseDateOozieTZ("2014-01-18T00:00Z")); assertEquals(nonDSTStartAndEndCalculator.calculate(TZ_DST, target), target); }
@Test public void testCalculateBetweenDSTStartAndStandardEndGivesPositiveOffset() throws ParseException { final DaylightOffsetCalculator dstStartAndStandardEndCalculator = new DaylightOffsetCalculator( DateUtils.parseDateOozieTZ("2013-07-18T00:00Z"), DateUtils.parseDateOozieTZ("2014-01-18T00:00Z")); final Calendar standardEnd = Calendar.getInstance(); standardEnd.setTime(DateUtils.parseDateOozieTZ("2014-01-18T00:00Z")); final Calendar standardEndPlusOneHour = (Calendar) standardEnd.clone(); standardEndPlusOneHour.add(Calendar.HOUR, 1); assertEquals(dstStartAndStandardEndCalculator.calculate(TZ_DST, standardEnd), standardEndPlusOneHour); }
@Test public void testCalculateBetweenStandardStartAndDSTEndGivesNegativeOffset() throws ParseException { final DaylightOffsetCalculator standardStartAndDSTEndCalculator = new DaylightOffsetCalculator( DateUtils.parseDateOozieTZ("2013-01-18T00:00Z"), DateUtils.parseDateOozieTZ("2013-07-18T00:00Z")); final Calendar standardEnd = Calendar.getInstance(); standardEnd.setTime(DateUtils.parseDateOozieTZ("2013-07-18T00:00Z")); final Calendar standardEndMinusOneHour = (Calendar) standardEnd.clone(); standardEndMinusOneHour.add(Calendar.HOUR, -1); assertEquals(standardStartAndDSTEndCalculator.calculate(TZ_DST, standardEnd), standardEndMinusOneHour); }
@Test public void testCalculateGivenStandardTZGivesZeroOffset() throws ParseException { final DaylightOffsetCalculator standardStartAndDSTEndCalculator = new DaylightOffsetCalculator( DateUtils.parseDateOozieTZ("2013-01-18T00:00Z"), DateUtils.parseDateOozieTZ("2013-07-18T00:00Z")); final Calendar dstStart = Calendar.getInstance(); dstStart.setTime(DateUtils.parseDateOozieTZ("2013-01-18T00:00Z")); final Calendar standardEnd = Calendar.getInstance(); standardEnd.setTime(DateUtils.parseDateOozieTZ("2013-07-18T00:00Z")); assertEquals(standardStartAndDSTEndCalculator.calculate(TZ_STANDARD, standardEnd), standardEnd); }