1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.imaging;
18
19 import static org.junit.jupiter.api.Assertions.assertEquals;
20 import static org.junit.jupiter.api.Assertions.assertNotNull;
21 import static org.junit.jupiter.api.Assertions.assertNull;
22
23 import java.util.stream.Stream;
24
25 import org.junit.jupiter.api.Test;
26 import org.junit.jupiter.params.ParameterizedTest;
27 import org.junit.jupiter.params.provider.MethodSource;
28
29
30
31
32 public class TestImageWriteException {
33
34 public static Stream<Object[]> data() {
35 final ImagingException exception = new ImagingException((String) null);
36
37 return Stream.of(
38 new Object[] {null, "null"},
39 new Object[] {new Object[] {Integer.valueOf(1)}, "[Object[]: 1]"},
40 new Object[] {new char[] {'a', 'b', 'c'}, "[char[]: 3]"},
41 new Object[] {new byte[] {0, 1}, "[byte[]: 2]"},
42 new Object[] {new short[] {0}, "[short[]: 1]"},
43 new Object[] {new int[] {-1, -2, 4, 100}, "[int[]: 4]"},
44 new Object[] {new long[] {-1, -2, 4, 100}, "[long[]: 4]"},
45 new Object[] {new float[] {-1.0f, 2.0f}, "[float[]: 2]"},
46 new Object[] {new double[] {-1.0d, 2.0d}, "[double[]: 2]"},
47 new Object[] {new boolean[] {true, false, true}, "[boolean[]: 3]"},
48 new Object[] {exception, exception.getClass().getName()}
49 );
50
51 }
52
53 @ParameterizedTest
54 @MethodSource("data")
55 public void testCreateExceptionWithData(final Object data, final String expectedType) {
56 final ImagingException exception = new ImagingException("imaging", data);
57 assertEquals(String.format("imaging: %s (%s)", data, expectedType), exception.getMessage());
58 }
59
60 @Test
61 public void testCreateExceptionWithMessage() {
62 final ImagingException exception = new ImagingException("imaging");
63 assertEquals("imaging", exception.getMessage());
64 assertNull(exception.getCause());
65 }
66
67 @Test
68 public void testCreateExceptionWithMessageAndCause() {
69 final ImagingException exception = new ImagingException("imaging", new Exception("cause"));
70 assertEquals("imaging", exception.getMessage());
71 assertNotNull(exception.getCause());
72 }
73 }