1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.commons.io;
19
20 import static org.junit.jupiter.api.Assertions.assertEquals;
21 import static org.junit.jupiter.api.Assertions.assertSame;
22
23 import java.io.IOException;
24
25 import org.junit.jupiter.api.Test;
26
27
28
29
30 public class IOExceptionWithCauseTest {
31
32
33
34
35 @Test
36 public void testIOExceptionStringThrowable() {
37 final Throwable cause = new IllegalArgumentException("cause");
38 final IOException exception = new IOException("message", cause);
39 this.validate(exception, cause, "message");
40 }
41
42
43
44
45
46 @Test
47 public void testIOExceptionThrowable() {
48 final Throwable cause = new IllegalArgumentException("cause");
49 final IOException exception = new IOException(cause);
50 this.validate(exception, cause, "java.lang.IllegalArgumentException: cause");
51 }
52
53 void validate(final Throwable throwable, final Throwable expectedCause, final String expectedMessage) {
54 assertEquals(expectedMessage, throwable.getMessage());
55 assertEquals(expectedCause, throwable.getCause());
56 assertSame(expectedCause, throwable.getCause());
57 }
58 }