### Question:
ParseService { public <T> Optional<T> getDataFromFile(MultipartFile input, TypeReference<T> typeReference) { try { return Optional.ofNullable(objectMapper.readValue(input.getInputStream(), typeReference)); } catch (IOException e) { log.error("Could not map file to Object. \n {}", e.getMessage()); return Optional.empty(); } }  Optional<T> getDataFromFile(MultipartFile input, TypeReference<T> typeReference); Optional<DataPayload> getDefaultData(); byte[] generateFileByPayload(DataPayload data); List<T> convertFileToTargetObject(MultipartFile file, Class<T> target);  }### Answer:
@Test void getDataFromFile_Consents() throws IOException { MultipartFile multipartFile = resolveMultipartFile("consents_template.yml"); Optional<List<AisConsent>> data = parseService.getDataFromFile(multipartFile, new TypeReference<>() { }); assertTrue(data.isPresent()); data.get().forEach(this::assertNoNullFields); }
@Test void getDataFromFile_Consents_fail() throws IOException { MultipartFile multipartFile = resolveMultipartFile("consents_template_error.yml"); Optional<List<AisConsent>> data = parseService.getDataFromFile(multipartFile, new TypeReference<>() { }); assertTrue(data.isEmpty()); }
@Test void getDataFromFile_DataPayload() throws IOException { MultipartFile multipartFile = resolveMultipartFile("data_payload_template.yml"); Optional<DataPayload> data = parseService.getDataFromFile(multipartFile, new TypeReference<>() { }); validateDataPayload(data); }