Defensive reset/restore of JNDI environment (avoiding test side effects)
Issue: SPR-12223
This commit is contained in:
parent
237b50a9c8
commit
7f8d611598
|
|
@ -16,22 +16,35 @@
|
||||||
|
|
||||||
package org.springframework.jndi;
|
package org.springframework.jndi;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import javax.naming.spi.NamingManager;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import static org.hamcrest.Matchers.*;
|
import static org.hamcrest.Matchers.*;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for {@link JndiLocatorDelegate}.
|
* Tests for {@link JndiLocatorDelegate}.
|
||||||
*
|
*
|
||||||
* @author Phillip Webb
|
* @author Phillip Webb
|
||||||
|
* @author Juergen Hoeller
|
||||||
*/
|
*/
|
||||||
public class JndiLocatorDelegateTests {
|
public class JndiLocatorDelegateTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void isDefaultJndiEnvironmentAvailableFalse() {
|
public void isDefaultJndiEnvironmentAvailableFalse() throws Exception {
|
||||||
assertThat(JndiLocatorDelegate.isDefaultJndiEnvironmentAvailable(), equalTo(false));
|
Field builderField = NamingManager.class.getDeclaredField("initctx_factory_builder");
|
||||||
|
builderField.setAccessible(true);
|
||||||
|
Object oldBuilder = builderField.get(null);
|
||||||
|
builderField.set(null, null);
|
||||||
|
|
||||||
|
try {
|
||||||
|
assertThat(JndiLocatorDelegate.isDefaultJndiEnvironmentAvailable(), equalTo(false));
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
builderField.set(null, oldBuilder);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue