1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.dbunit.dataset;
22
23 import static org.assertj.core.api.Assertions.assertThat;
24
25 import java.util.Arrays;
26 import java.util.List;
27
28
29
30
31
32
33 public abstract class AbstractTest
34 {
35 private static final String[] TABLE_NAMES =
36 {"TEST_TABLE", "SECOND_TABLE", "EMPTY_TABLE", "PK_TABLE",
37 "ONLY_PK_TABLE", "EMPTY_MULTITYPE_TABLE",};
38 private static final String[] DUPLICATE_TABLE_NAMES =
39 {"DUPLICATE_TABLE", "EMPTY_TABLE", "DUPLICATE_TABLE",};
40 private static final String EXTRA_TABLE_NAME = "EXTRA_TABLE";
41
42
43
44
45
46
47
48
49
50
51
52 protected String convertString(final String str) throws Exception
53 {
54 return str;
55 }
56
57 protected String[] getExpectedNames() throws Exception
58 {
59 return (String[]) AbstractTest.TABLE_NAMES.clone();
60 }
61
62 protected String[] getExpectedLowerNames() throws Exception
63 {
64 String[] names = (String[]) AbstractTest.TABLE_NAMES.clone();
65 for (int i = 0; i < names.length; i++)
66 {
67 names[i] = names[i].toLowerCase();
68 }
69
70 return names;
71 }
72
73 protected String[] getExpectedDuplicateNames()
74 {
75 return (String[]) AbstractTest.DUPLICATE_TABLE_NAMES.clone();
76 }
77
78 protected String getDuplicateTableName()
79 {
80 return "DUPLICATE_TABLE";
81 }
82
83 public String getExtraTableName()
84 {
85 return AbstractTest.EXTRA_TABLE_NAME;
86 }
87
88 public void assertEqualsIgnoreCase(final String message,
89 final String expected, final String actual)
90 {
91 if (!expected.equalsIgnoreCase(actual))
92 {
93 assertThat(actual).as(message).isEqualTo(expected);
94 }
95 }
96
97 public void assertContains(final String message, final Object[] expected,
98 final Object[] actual)
99 {
100 final List<Object> expectedList = Arrays.asList(expected);
101 final List<Object> actualList = Arrays.asList(actual);
102
103 assertThat(actualList)
104 .as(message + " expected contains:<" + expectedList
105 + "> but was:<" + actualList + ">")
106 .containsAll(expectedList);
107 }
108
109 public void assertContainsIgnoreCase(final String message,
110 final String[] expected, final String[] actual)
111 {
112 final String[] expectedLowerCase = new String[expected.length];
113 for (int i = 0; i < expected.length; i++)
114 {
115 expectedLowerCase[i] = expected[i].toLowerCase();
116 }
117
118 final String[] actualLowerCase = new String[actual.length];
119 for (int i = 0; i < actual.length; i++)
120 {
121 actualLowerCase[i] = actual[i].toLowerCase();
122 }
123
124 assertContains(message, expectedLowerCase, actualLowerCase);
125 }
126
127 }