DateUtils { public static Date getFirstDayOfYear(Date date) { Calendar firstDayOfYear = Calendar.getInstance(); firstDayOfYear.setTime(DateUtils.getFirstDayOfMonth(date)); firstDayOfYear.set(Calendar.MONTH, firstDayOfYear.getMinimum(Calendar.MONTH)); return firstDayOfYear.getTime(); }  static Date timeToDate(int hour, int minutes); static Date minHourInDate(Date d); static Date addDays2Date(Date d, int days); static Date maxHourInDate(Date d); static Date getFirstDayOfMonth(Date date); static Date getLastDayOfMonth(Date date); static Date getFirstDayOfYear(Date date); static Date getLastDayOfYear(Date date);  }
@Test public void shouldReturnFirstDayOfYear() { final Date testDate = new GregorianCalendar(2019, Calendar.JULY, 17).getTime(); final Date result = DateUtils.getFirstDayOfYear(testDate); final Date expectedDate = new GregorianCalendar(2019, Calendar.JANUARY, 1).getTime(); assertThat(result, is(expectedDate)); }