Home / Class/ PropertiesPropertySourceLoaderTests Class — spring-boot Architecture

PropertiesPropertySourceLoaderTests Class — spring-boot Architecture

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

Entity Profile

Source Code

core/spring-boot/src/test/java/org/springframework/boot/env/PropertiesPropertySourceLoaderTests.java lines 35–134

class PropertiesPropertySourceLoaderTests {

	private final PropertiesPropertySourceLoader loader = new PropertiesPropertySourceLoader();

	@Test
	void getFileExtensions() {
		assertThat(this.loader.getFileExtensions()).isEqualTo(new String[] { "properties", "xml" });
	}

	@Test
	@WithResource(name = "test.properties", content = "test=properties")
	void loadProperties() throws Exception {
		List<PropertySource<?>> loaded = this.loader.load("test.properties", new ClassPathResource("test.properties"));
		PropertySource<?> source = loaded.get(0);
		assertThat(source.getProperty("test")).isEqualTo("properties");
	}

	@Test
	@WithResource(name = "test.properties", content = """
			#---
			#test
			blah=hello world
			bar=baz
			hello=world
			#---
			foo=bar
			bling=biz
			#comment1
			#comment2
			""")
	void loadMultiDocumentPropertiesWithSeparatorAtTheBeginningOfFile() throws Exception {
		List<PropertySource<?>> loaded = this.loader.load("test.properties", new ClassPathResource("test.properties"));
		assertThat(loaded).hasSize(2);
		PropertySource<?> source1 = loaded.get(0);
		PropertySource<?> source2 = loaded.get(1);
		assertThat(source1.getProperty("blah")).isEqualTo("hello world");
		assertThat(source2.getProperty("foo")).isEqualTo("bar");
	}

	@Test
	@WithResource(name = "test.properties", content = """
			#test
			blah=hello world
			bar=baz
			hello=world
			#---
			foo=bar
			bling=biz
			#comment1
			#comment2
			#---
			""")
	void loadMultiDocumentProperties() throws Exception {
		List<PropertySource<?>> loaded = this.loader.load("test.properties", new ClassPathResource("test.properties"));
		assertThat(loaded).hasSize(2);
		PropertySource<?> source1 = loaded.get(0);
		PropertySource<?> source2 = loaded.get(1);
		assertThat(source1.getProperty("blah")).isEqualTo("hello world");
		assertThat(source2.getProperty("foo")).isEqualTo("bar");
	}

	@Test
	@WithResource(name = "test.properties", content = """

			#---
			#test
			blah=hello world
			bar=baz
			hello=world
			#---
			#---
			foo=bar
			bling=biz
			#comment1
			#comment2
			""")
	void loadMultiDocumentPropertiesWithEmptyDocument() throws Exception {
		List<PropertySource<?>> loaded = this.loader.load("test.properties", new ClassPathResource("test.properties"));
		assertThat(loaded).hasSize(2);
		PropertySource<?> source1 = loaded.get(0);
		PropertySource<?> source2 = loaded.get(1);
		assertThat(source1.getProperty("blah")).isEqualTo("hello world");
		assertThat(source2.getProperty("foo")).isEqualTo("bar");
	}

	@Test
	@WithResource(name = "test.xml", content = """
			<?xml version="1.0" encoding="UTF-8"?>
			<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
			<properties>
				<entry key="test">xml</entry>
			</properties>
			""")
	void loadXml() throws Exception {
		List<PropertySource<?>> loaded = this.loader.load("test.xml", new ClassPathResource("test.xml"));
		PropertySource<?> source = loaded.get(0);
		assertThat(source.getProperty("test")).isEqualTo("xml");
	}

}

Analyze Your Own Codebase

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

Try Supermodel Free