Home / Class/ LogbackRuntimeHintsTests Class — spring-boot Architecture

LogbackRuntimeHintsTests Class — spring-boot Architecture

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

Entity Profile

Source Code

core/spring-boot/src/test/java/org/springframework/boot/logging/logback/LogbackRuntimeHintsTests.java lines 46–114

class LogbackRuntimeHintsTests {

	@Test
	void registersHintsForTypesCheckedByLogbackLoggingSystem() {
		ReflectionHints reflection = registerHints();
		assertThat(reflection.getTypeHint(LoggerContext.class)).isNotNull();
		assertThat(reflection.getTypeHint(SLF4JBridgeHandler.class)).isNotNull();
	}

	@Test
	void registersHintsForBuiltInLogbackConverters() {
		ReflectionHints reflection = registerHints();
		assertThat(logbackConverters()).allSatisfy(registeredForPublicConstructorInvocation(reflection));
	}

	@Test
	void registersHintsForSpringBootConverters() throws IOException {
		ReflectionHints reflection = registerHints();
		assertThat(converterClasses()).allSatisfy(registeredForPublicConstructorInvocation(reflection));
	}

	@SuppressWarnings("unchecked")
	private Stream<Class<Converter<?>>> converterClasses() throws IOException {
		PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
		return Stream.of(resolver.getResources("classpath:org/springframework/boot/logging/logback/*.class"))
			.filter(Resource::isFile)
			.map(this::loadClass)
			.filter(Converter.class::isAssignableFrom)
			.map((type) -> (Class<Converter<?>>) type);
	}

	private Class<?> loadClass(Resource resource) {
		try {
			String filename = resource.getFilename();
			assertThat(filename).isNotNull();
			return getClass().getClassLoader()
				.loadClass("org.springframework.boot.logging.logback." + filename.replace(".class", ""));
		}
		catch (ClassNotFoundException ex) {
			throw new RuntimeException(ex);
		}
	}

	@Test
	void doesNotRegisterHintsWhenLoggerContextIsNotAvailable() {
		RuntimeHints hints = new RuntimeHints();
		new LogbackRuntimeHints().registerHints(hints, ClassLoader.getPlatformClassLoader());
		assertThat(hints.reflection().typeHints()).isEmpty();
	}

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

	private Consumer<Class<?>> registeredForPublicConstructorInvocation(ReflectionHints reflection) {
		return (converter) -> {
			TypeHint typeHint = reflection.getTypeHint(converter);
			assertThat(typeHint).isNotNull();
			assertThat(typeHint.getMemberCategories()).containsExactly(MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS);
		};
	}

	private List<Class<?>> logbackConverters() {
		return List.of(DateTokenConverter.class, IntegerTokenConverter.class, SyslogStartConverter.class);
	}

}

Analyze Your Own Codebase

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

Try Supermodel Free