### Question:
ICalController { @GetMapping(value = "/{user_id}.ics") public @ResponseBody HttpEntity<byte[]> getCalByUserId(@PathVariable(value = "user_id") String userId) { Cal cal = iCalService.getCalByUserId(userId); byte[] calBytes = cal.build().getBytes(); HttpHeaders header = new HttpHeaders(); header.setContentType(new MediaType("application", "calendar", Charset.forName("UTF-8"))); header.set("Content-Disposition", "attachment; filename="+userId+".ics"); header.setContentLength(calBytes.length); return new HttpEntity<>(calBytes, header); }  @GetMapping(value = "/{user_id}.ics") @ResponseBody HttpEntity<byte[]> getCalByUserId(@PathVariable(value = "user_id") String userId);  }### Answer:
@Test public void testGetCalByUserId() throws Exception { String companyId = UUID.randomUUID().toString(); String teamId = UUID.randomUUID().toString(); String userId = UUID.randomUUID().toString(); String jobId = UUID.randomUUID().toString(); WorkerDto workerDto = WorkerDto.builder() .userId(userId) .teamId(teamId) .companyId(companyId) .build(); GenericWorkerResponse genericWorkerResponse = new GenericWorkerResponse(workerDto); when(companyClient.getWorkerTeamInfo(AuthConstant.AUTHORIZATION_ICAL_SERVICE, null, userId)) .thenReturn(genericWorkerResponse); CompanyDto companyDto = CompanyDto.builder() .id(companyId) .defaultDayWeekStarts(TimeZone.getDefault().getID()) .defaultDayWeekStarts("Monday") .name("i_cool_company") .build(); GenericCompanyResponse genericCompanyResponse = new GenericCompanyResponse(companyDto); when(companyClient.getCompany(AuthConstant.AUTHORIZATION_ICAL_SERVICE, companyId)) .thenReturn(genericCompanyResponse); ShiftDto shiftDto1 = ShiftDto.builder() .id(UUID.randomUUID().toString()) .companyId(companyId) .teamId(teamId) .jobId(jobId) .published(true) .userId(userId) .start(Instant.now().plus(2, ChronoUnit.DAYS)) .stop(Instant.now().plus(3, ChronoUnit.DAYS)) .build(); ShiftDto shiftDto2 = ShiftDto.builder() .id(UUID.randomUUID().toString()) .companyId(companyId) .teamId(teamId) .jobId(jobId) .published(true) .userId(userId) .start(Instant.now().plus(4, ChronoUnit.DAYS)) .stop(Instant.now().plus(5, ChronoUnit.DAYS)) .build(); ShiftList shiftList = ShiftList.builder() .shiftStartAfter(Instant.now().minus(30, ChronoUnit.DAYS)) .shiftStartBefore(Instant.now().plus(90, ChronoUnit.DAYS)) .build(); shiftList.getShifts().add(shiftDto1); shiftList.getShifts().add(shiftDto2); GenericShiftListResponse genericShiftListResponse = new GenericShiftListResponse(shiftList); when(companyClient.listWorkerShifts(anyString(), any(WorkerShiftListRequest.class))) .thenReturn(genericShiftListResponse); MvcResult mvcResult = mockMvc.perform(get("/" + userId + ".ics")) .andExpect(status().isOk()) .andReturn(); assertThat(mvcResult.getResponse().getContentType()).isEqualTo("application/calendar;charset=UTF-8"); assertThat(mvcResult.getResponse().getHeader("Content-Disposition")).contains(userId); log.info(mvcResult.getResponse().getContentAsString()); assertThat(mvcResult.getResponse().getContentAsString()).contains(userId, companyDto.getName()); }