Home / Class/ IgnoreTopLevelConverterNotFoundBindHandlerTests Class — spring-boot Architecture

IgnoreTopLevelConverterNotFoundBindHandlerTests Class — spring-boot Architecture

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

Entity Profile

Relationship Graph

Source Code

core/spring-boot/src/test/java/org/springframework/boot/context/properties/bind/handler/IgnoreTopLevelConverterNotFoundBindHandlerTests.java lines 41–113

class IgnoreTopLevelConverterNotFoundBindHandlerTests {

	private final List<ConfigurationPropertySource> sources = new ArrayList<>();

	private Binder binder;

	@BeforeEach
	void setup() {
		MockConfigurationPropertySource source = new MockConfigurationPropertySource();
		source.put("example", "bar");
		this.sources.add(source);
		this.binder = new Binder(this.sources);
	}

	@Test
	void bindWhenHandlerNotPresentShouldFail() {
		assertThatExceptionOfType(BindException.class)
			.isThrownBy(() -> this.binder.bind("example", Bindable.of(Example.class)))
			.withCauseInstanceOf(ConverterNotFoundException.class);
	}

	@Test
	void bindWhenTopLevelContextAndExceptionIgnorableShouldNotFail() {
		this.binder.bind("example", Bindable.of(Example.class), new IgnoreTopLevelConverterNotFoundBindHandler());
	}

	@Test
	void bindWhenExceptionNotIgnorableShouldFail() {
		MockConfigurationPropertySource source = new MockConfigurationPropertySource();
		source.put("example.foo", "1");
		this.sources.add(source);
		assertThatExceptionOfType(BindException.class)
			.isThrownBy(() -> this.binder.bind("example", Bindable.of(Example.class),
					new IgnoreTopLevelConverterNotFoundBindHandler()))
			.withCauseInstanceOf(IllegalStateException.class);
	}

	@Test
	void bindWhenExceptionInNestedContextShouldFail() {
		MockConfigurationPropertySource source = new MockConfigurationPropertySource();
		source.put("example.map", "hello");
		this.sources.add(source);
		assertThatExceptionOfType(BindException.class)
			.isThrownBy(() -> this.binder.bind("example", Bindable.of(Example.class),
					new IgnoreTopLevelConverterNotFoundBindHandler()))
			.withCauseInstanceOf(ConverterNotFoundException.class);
	}

	static class Example {

		private int foo;

		private @Nullable Map<String, String> map;

		int getFoo() {
			return this.foo;
		}

		void setFoo(int foo) {
			throw new IllegalStateException();
		}

		@Nullable Map<String, String> getMap() {
			return this.map;
		}

		void setMap(@Nullable Map<String, String> map) {
			this.map = map;
		}

	}

}

Domain

Analyze Your Own Codebase

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

Try Supermodel Free