Home / Class/ TestableInitialContextFactory Class — spring-boot Architecture

TestableInitialContextFactory Class — spring-boot Architecture

Architecture documentation for the TestableInitialContextFactory class in TestableInitialContextFactory.java from the spring-boot codebase.

Entity Profile

Relationship Graph

Source Code

core/spring-boot-autoconfigure/src/testFixtures/java/org/springframework/boot/autoconfigure/jndi/TestableInitialContextFactory.java lines 33–97

public class TestableInitialContextFactory implements InitialContextFactory {

	private static TestableContext context;

	@Override
	public Context getInitialContext(Hashtable<?, ?> environment) {
		return getContext();
	}

	public static void bind(String name, Object obj) {
		try {
			getContext().bind(name, obj);
		}
		catch (NamingException ex) {
			throw new IllegalStateException(ex);
		}
	}

	public static void clearAll() {
		getContext().clearAll();
	}

	private static TestableContext getContext() {
		if (context == null) {
			try {
				context = new TestableContext();
			}
			catch (NamingException ex) {
				throw new IllegalStateException(ex);
			}
		}
		return context;
	}

	private static final class TestableContext extends InitialContext {

		private final Map<String, Object> bindings = new HashMap<>();

		private TestableContext() throws NamingException {
			super(true);
		}

		@Override
		public void bind(String name, Object obj) throws NamingException {
			this.bindings.put(name, obj);
		}

		@Override
		public Object lookup(String name) {
			return this.bindings.get(name);
		}

		@Override
		public Hashtable<?, ?> getEnvironment() throws NamingException {
			return new Hashtable<>(); // Used to detect if JNDI is
										// available
		}

		void clearAll() {
			this.bindings.clear();
		}

	}

}

Domain

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free