Home / Class/ Log4J2RuntimeHintsTests Class — spring-boot Architecture

Log4J2RuntimeHintsTests Class — spring-boot Architecture

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

Entity Profile

Source Code

core/spring-boot/src/test/java/org/springframework/boot/logging/log4j2/Log4J2RuntimeHintsTests.java lines 41–97

class Log4J2RuntimeHintsTests {

	private static final ReflectionHintsPredicates reflectionHints = RuntimeHintsPredicates.reflection();

	private static final ResourceHintsPredicates resourceHints = RuntimeHintsPredicates.resource();

	@Test
	void registersHintsForTypesCheckedByLog4J2LoggingSystem() {
		RuntimeHints runtimeHints = registerHints();
		assertThat(reflectionHints.onType(Log4jContextFactory.class)).accepts(runtimeHints);
		assertThat(reflectionHints.onType(Log4jBridgeHandler.class)).accepts(runtimeHints);
		assertThat(reflectionHints.onType(LogManager.class)).accepts(runtimeHints);
	}

	@Test
	void registersHintsForLog4j2DefaultConfigurationFiles() {
		RuntimeHints runtimeHints = registerHints();
		assertThat(resourceHints.forResource("org/springframework/boot/logging/log4j2/log4j2.xml"))
			.accepts(runtimeHints);
		assertThat(resourceHints.forResource("org/springframework/boot/logging/log4j2/log4j2-file.xml"))
			.accepts(runtimeHints);
		assertThat(resourceHints.forResource("log4j2.springboot")).accepts(runtimeHints);
	}

	@Test
	void doesNotRegisterHintsWhenLog4jCoreIsNotAvailable() {
		RuntimeHints runtimeHints = new RuntimeHints();
		new Log4J2RuntimeHints().registerHints(runtimeHints, new HidePackagesClassLoader("org.apache.logging.log4j"));
		assertThat(runtimeHints.reflection().typeHints()).isEmpty();
	}

	private RuntimeHints registerHints() {
		RuntimeHints hints = new RuntimeHints();
		new Log4J2RuntimeHints().registerHints(hints, getClass().getClassLoader());
		return hints;
	}

	static final class HidePackagesClassLoader extends URLClassLoader {

		private final String[] hiddenPackages;

		HidePackagesClassLoader(String... hiddenPackages) {
			super(new URL[0], HidePackagesClassLoader.class.getClassLoader());
			this.hiddenPackages = hiddenPackages;
		}

		@Override
		protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException {
			if (Arrays.stream(this.hiddenPackages).anyMatch(name::startsWith)) {
				throw new ClassNotFoundException();
			}
			return super.loadClass(name, resolve);
		}

	}

}

Analyze Your Own Codebase

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

Try Supermodel Free