1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package nl.altindag.ssl.util;
18
19 import nl.altindag.ssl.exception.GenericIOException;
20 import org.junit.jupiter.api.Test;
21 import org.junit.jupiter.api.extension.ExtendWith;
22 import org.mockito.Mockito;
23 import org.mockito.junit.jupiter.MockitoExtension;
24
25 import java.io.ByteArrayInputStream;
26 import java.io.IOException;
27
28 import static org.assertj.core.api.Assertions.assertThat;
29 import static org.assertj.core.api.Assertions.assertThatThrownBy;
30 import static org.mockito.Mockito.doThrow;
31
32
33
34
35 @ExtendWith(MockitoExtension.class)
36 class IOUtilsShould {
37
38 @Test
39 void getContent() {
40 ByteArrayInputStream inputStream = new ByteArrayInputStream("Hello".getBytes());
41 String content = IOUtils.getContent(inputStream);
42 assertThat(content).isEqualTo("Hello");
43 }
44
45 @Test
46 void bla() throws IOException {
47 ByteArrayInputStream inputStream = Mockito.spy(new ByteArrayInputStream("Hello".getBytes()));
48 doThrow(new IOException("Could not read the content")).when(inputStream).close();
49
50 assertThatThrownBy(() -> IOUtils.getContent(inputStream))
51 .isInstanceOf(GenericIOException.class)
52 .hasRootCauseMessage("Could not read the content");
53 }
54
55 }