|
4 | 4 | import java.sql.ResultSet; |
5 | 5 | import java.sql.SQLException; |
6 | 6 | import java.sql.Statement; |
7 | | -import java.util.ArrayList; |
8 | | -import java.util.Collection; |
9 | 7 |
|
10 | 8 | public class QueryAdapter extends Query { |
11 | 9 |
|
12 | 10 | private final String query; |
13 | | - private final Collection<String> expectedErrors; |
| 11 | + private final ExpectedErrors expectedErrors; |
14 | 12 | private final boolean couldAffectSchema; |
15 | 13 |
|
16 | 14 | public QueryAdapter(String query) { |
17 | | - this(query, new ArrayList<>()); |
| 15 | + this(query, new ExpectedErrors()); |
18 | 16 | } |
19 | 17 |
|
20 | 18 | public QueryAdapter(String query, boolean couldAffectSchema) { |
21 | | - this(query, new ArrayList<>(), couldAffectSchema); |
| 19 | + this(query, new ExpectedErrors(), couldAffectSchema); |
22 | 20 | } |
23 | 21 |
|
24 | | - public QueryAdapter(String query, Collection<String> expectedErrors) { |
25 | | - this.query = canonicalizeString(query); |
26 | | - this.expectedErrors = expectedErrors; |
27 | | - this.couldAffectSchema = false; |
28 | | - checkQueryString(); |
| 22 | + public QueryAdapter(String query, ExpectedErrors expectedErrors) { |
| 23 | + this(query, expectedErrors, false); |
29 | 24 | } |
30 | 25 |
|
31 | | - public QueryAdapter(String query, Collection<String> expectedErrors, boolean couldAffectSchema) { |
| 26 | + public QueryAdapter(String query, ExpectedErrors expectedErrors, boolean couldAffectSchema) { |
32 | 27 | this.query = canonicalizeString(query); |
33 | 28 | this.expectedErrors = expectedErrors; |
34 | 29 | this.couldAffectSchema = couldAffectSchema; |
@@ -84,14 +79,7 @@ public boolean execute(GlobalState<?, ?> globalState, String... fills) throws SQ |
84 | 79 | } |
85 | 80 |
|
86 | 81 | public void checkException(Exception e) throws AssertionError { |
87 | | - boolean isExcluded = false; |
88 | | - for (String expectedError : expectedErrors) { |
89 | | - if (e.getMessage().contains(expectedError)) { |
90 | | - isExcluded = true; |
91 | | - break; |
92 | | - } |
93 | | - } |
94 | | - if (!isExcluded) { |
| 82 | + if (!expectedErrors.errorIsExpected(e.getMessage())) { |
95 | 83 | throw new AssertionError(query, e); |
96 | 84 | } |
97 | 85 | } |
@@ -133,7 +121,7 @@ public boolean couldAffectSchema() { |
133 | 121 | } |
134 | 122 |
|
135 | 123 | @Override |
136 | | - public Collection<String> getExpectedErrors() { |
| 124 | + public ExpectedErrors getExpectedErrors() { |
137 | 125 | return expectedErrors; |
138 | 126 | } |
139 | 127 |
|
|
0 commit comments