|
1 | 1 | // SPDX-License-Identifier: BSD-3-Clause |
2 | 2 | package org.xbill.DNS; |
3 | 3 |
|
| 4 | +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; |
4 | 5 | import static org.junit.jupiter.api.Assertions.assertEquals; |
5 | 6 | import static org.junit.jupiter.api.Assertions.assertFalse; |
6 | 7 | import static org.junit.jupiter.api.Assertions.assertTrue; |
|
13 | 14 | import java.lang.reflect.Field; |
14 | 15 | import java.net.InetSocketAddress; |
15 | 16 | import java.util.Arrays; |
| 17 | +import org.junit.jupiter.api.AfterEach; |
16 | 18 | import org.junit.jupiter.api.Test; |
17 | 19 | import org.junit.jupiter.api.condition.DisabledOnOs; |
18 | 20 | import org.junit.jupiter.api.condition.EnabledOnOs; |
|
25 | 27 | import org.xbill.DNS.config.WindowsResolverConfigProvider; |
26 | 28 |
|
27 | 29 | class ResolverConfigTest { |
28 | | - @Test |
29 | | - void testSkipInit() throws Exception { |
| 30 | + @AfterEach |
| 31 | + void afterEach() throws Exception { |
| 32 | + // make sure the ResolverConfig providers are not staying initialized after a test |
30 | 33 | Field configProvidersField = ResolverConfig.class.getDeclaredField("configProviders"); |
31 | 34 | configProvidersField.setAccessible(true); |
32 | 35 | configProvidersField.set(null, null); |
| 36 | + Field currentConfigField = ResolverConfig.class.getDeclaredField("currentConfig"); |
| 37 | + currentConfigField.setAccessible(true); |
| 38 | + currentConfigField.set(null, null); |
| 39 | + } |
| 40 | + |
| 41 | + @Test |
| 42 | + void testSkipInit() { |
33 | 43 | try { |
34 | 44 | System.setProperty(ResolverConfig.CONFIGPROVIDER_SKIP_INIT, Boolean.TRUE.toString()); |
35 | 45 | assertTrue(ResolverConfig.getConfigProviders().isEmpty()); |
36 | 46 | } finally { |
37 | 47 | System.setProperty(ResolverConfig.CONFIGPROVIDER_SKIP_INIT, Boolean.FALSE.toString()); |
38 | | - configProvidersField.set(null, null); |
39 | 48 | } |
40 | 49 | } |
41 | 50 |
|
@@ -199,4 +208,9 @@ void windowsServersContainedInJndi() throws InitializationException { |
199 | 208 | winServer + " not found in JNDI, " + win.servers() + "; " + jndi.servers()); |
200 | 209 | } |
201 | 210 | } |
| 211 | + |
| 212 | + @Test |
| 213 | + void refreshAsFirstCall() { |
| 214 | + assertDoesNotThrow(ResolverConfig::refresh); |
| 215 | + } |
202 | 216 | } |
0 commit comments