1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30 package com.jcabi.log;
31
32 import java.util.ArrayList;
33 import java.util.Arrays;
34 import java.util.Collection;
35 import java.util.Locale;
36 import org.hamcrest.MatcherAssert;
37 import org.hamcrest.Matchers;
38 import org.junit.jupiter.params.ParameterizedTest;
39 import org.junit.jupiter.params.provider.MethodSource;
40
41
42
43
44
45
46
47 final class ListDecorTest {
48
49 @ParameterizedTest
50 @MethodSource("params")
51 void testPrintsRight(final Object list, final String text,
52 final int flags, final int width, final int precision) throws DecorException {
53 Locale.setDefault(Locale.US);
54 MatcherAssert.assertThat(
55 new Printed(new ListDecor(list), flags, width, precision),
56 Matchers.hasToString(text)
57 );
58 }
59
60 @ParameterizedTest
61 @MethodSource("params")
62 void testLogsRight(final Object list, final String text,
63 final int flags, final int width, final int precision) throws DecorException {
64 Locale.setDefault(Locale.US);
65 MatcherAssert.assertThat(
66 new Logged(new ListDecor(list), flags, width, precision),
67 Matchers.hasToString(text)
68 );
69 }
70
71
72
73
74
75 @SuppressWarnings("PMD.UnusedPrivateMethod")
76 private static Collection<Object[]> params() {
77 return Arrays.asList(
78 new Object[][] {
79
80 {null, "[NULL]", 0, 0, 0},
81 {new String[] {}, "[]", 0, 0, 0},
82 {new String[] {"a"}, "[\"a\"]", 0, 0, 0},
83 {new Long[] {2L, 1L}, "[\"2\", \"1\"]", 0, 0, 0},
84 {new Object[] {"b", "c"}, "[\"b\", \"c\"]", 0, 0, 0},
85 {new Object[] {"foo", 2L}, "[\"foo\", \"2\"]", 0, 0, 0},
86 {new ArrayList<String>(0), "[]", 0, 0, 0},
87 {Arrays.asList(new String[] {"x"}), "[\"x\"]", 0, 0, 0},
88 {Arrays.asList(new Long[] {1L, 2L}), "[\"1\", \"2\"]", 0, 0, 0},
89 }
90 );
91 }
92 }