-
Notifications
You must be signed in to change notification settings - Fork 192
Expand file tree
/
Copy pathTestUtil.java
More file actions
57 lines (52 loc) · 1.87 KB
/
TestUtil.java
File metadata and controls
57 lines (52 loc) · 1.87 KB
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
50
51
52
53
54
55
56
57
package net.snowflake.client;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import net.snowflake.client.core.SFException;
import net.snowflake.client.log.SFLogger;
import net.snowflake.client.log.SFLoggerFactory;
import org.junit.jupiter.api.Assertions;
public class TestUtil {
private static final SFLogger logger = SFLoggerFactory.getLogger(TestUtil.class);
/**
* Util function to assert a piece will throw exception and assert on the error code
*
* @param errorCode expected error code
* @param testCode the code that will run and throws exception
*/
public static void assertSFException(int errorCode, TestRunInterface testCode) {
try {
testCode.run();
Assertions.fail();
} catch (SFException e) {
assertThat(e.getVendorCode(), is(errorCode));
}
}
/** Functional interface used to run a piece of code which throws SFException */
@FunctionalInterface
public interface TestRunInterface {
void run() throws SFException;
}
/**
* System.getenv wrapper. If System.getenv raises an SecurityException, it is ignored and returns
* null.
* @deprecated This method should be replaced by SnowflakeUtil.systemGetEnv.
* <p>This is replicated from SnowflakeUtil.systemGetEnv, because the old driver doesn't have that
* function for the tests to use it. Replace this function call with SnowflakeUtil.systemGetEnv
* when it is available.
*
* @param env the environment variable name.
* @return the environment variable value if set, otherwise null.
*/
@Deprecated
public static String systemGetEnv(String env) {
try {
return System.getenv(env);
} catch (SecurityException ex) {
logger.debug(
"Failed to get environment variable {}. Security exception raised: {}",
env,
ex.getMessage());
}
return null;
}
}