如何在Testcase中为IOUtils手动创建IOException?

时间:2019-05-07 15:12:26

标签: kotlin ioexception testcase

如何创建kotlin测试用例来为下面的Java代码重现IOException。

public Student studencreateFlow(MyClass input) {
    try {
      map.add("file", new ByteArrayResource(
      IOUtils.toByteArray(input.getfile().getInputStream()))
      );
    } catch (IOException e) {
    throw new StudentException(INTEGRATION_STATUS_CODE_ERROR);
    }
}

和我的测试用例

@Test
  fun `student ioexception testcase`() {

    this.templateServer
      .expect(requestTo("${templateClientProperties.url}/account/1235698/flow/fileurl"))
      .andExpect { HttpMethod.POST }
      .andRespond(withNoContent())
    val templateFileByteArray = ClassLoader.getSystemResource("OnBoardFile.xlsx").readBytes();
    val mockFile = MockPart("test", templateFileByteArray);
    val input = MyClass("1235698", "456", mockFile, AddressInput("test", "test", "test", "ind", "2563", "demo", "demo"), OnboardingFlowTemplate.MULTI)

    assertThatExceptionOfType(StudentException::class.java)
      .isThrownBy { service.studencreateFlow(input)}


    this.templateServer.verify()
  }

我无法通过测试用例创建IO异常。请帮助解决此问题。

0 个答案:

没有答案