forked from pgjdbc/pgjdbc
/
CommandCompleteParserNegativeTest.java
49 lines (41 loc) · 1.19 KB
/
CommandCompleteParserNegativeTest.java
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/*
* Copyright (c) 2018, PostgreSQL Global Development Group
* See the LICENSE file in the project root for more information.
*/
package org.postgresql.core;
import org.postgresql.util.PSQLException;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import java.util.Arrays;
@RunWith(Parameterized.class)
public class CommandCompleteParserNegativeTest {
@Parameterized.Parameter(0)
public String input;
@Parameterized.Parameters(name = "input={0}")
public static Iterable<Object[]> data() {
return Arrays.asList(new Object[][]{
{"SELECT 0_0 42"},
{"SELECT 42 0_0"},
{"SELECT 0_0 0_0"},
});
}
@Test
public void run() throws PSQLException {
CommandCompleteParser parser = new CommandCompleteParser();
try {
parser.parse(input);
Assert.fail("CommandCompleteParser should throw NumberFormatException for " + input);
} catch (PSQLException e) {
Throwable cause = e.getCause();
if (cause == null) {
throw e;
}
if (!(cause instanceof NumberFormatException)) {
throw e;
}
// NumerFormatException is expected
}
}
}