### Question:
ParseService { public <T> List<T> convertFileToTargetObject(MultipartFile file, Class<T> target) { if (file == null) { throw new TppException("No file uploaded!", 400); } try { InputStreamReader streamReader = new InputStreamReader(file.getInputStream(), StandardCharsets.UTF_8); CsvToBean<T> csvToBean = new CsvToBeanBuilder<T>(streamReader) .withType(target) .withIgnoreLeadingWhiteSpace(true) .build(); return csvToBean.parse(); } catch (IOException e) { log.error("Can't convert file to target class: {}", target.getSimpleName(), e); throw new TppException("Can't convert file to target class", 400); } }  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 convertFileToTargetObject_failure() throws IOException { MockMultipartFile mock = mock(MockMultipartFile.class); when(mock.getInputStream()).thenThrow(IOException.class); assertThrows(TppException.class, () -> parseService.convertFileToTargetObject(mock, UserTransaction.class)); }
@Test void convertMultiPartToFile() throws IOException { List<UserTransaction> transactions = parseService.convertFileToTargetObject(resolveMultipartFile("transactions_template.csv"), UserTransaction.class); assertThat(transactions).isNotEmpty(); assertEquals(buildSingleUserTransaction(), transactions.get(0)); }
@Test void convertMultiPartToFile_fileNull() { assertThrows(TppException.class, () -> parseService.convertFileToTargetObject(null, UserTransaction.class)); }