Home / Class/ ConfigDataResourceNotFoundExceptionTests Class — spring-boot Architecture

ConfigDataResourceNotFoundExceptionTests Class — spring-boot Architecture

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

Entity Profile

Source Code

core/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigDataResourceNotFoundExceptionTests.java lines 39–169

class ConfigDataResourceNotFoundExceptionTests {

	private final ConfigDataResource resource = new TestConfigDataResource();

	private final ConfigDataLocation location = ConfigDataLocation.of("optional:test");

	private final Throwable cause = new RuntimeException();

	private File exists;

	private File missing;

	@TempDir
	@SuppressWarnings("NullAway.Init")
	File temp;

	@BeforeEach
	void setup() throws IOException {
		this.exists = new File(this.temp, "exists");
		this.missing = new File(this.temp, "missing");
		try (OutputStream out = new FileOutputStream(this.exists)) {
			out.write("test".getBytes());
		}
	}

	@Test
	@SuppressWarnings("NullAway") // Test null check
	void createWhenResourceIsNullThrowsException() {
		assertThatIllegalArgumentException().isThrownBy(() -> new ConfigDataResourceNotFoundException(null))
			.withMessage("'resource' must not be null");
	}

	@Test
	void createWithResourceCreatesInstance() {
		ConfigDataResourceNotFoundException exception = new ConfigDataResourceNotFoundException(this.resource);
		assertThat(exception.getResource()).isSameAs(this.resource);
	}

	@Test
	void createWithResourceAndCauseCreatesInstance() {
		ConfigDataResourceNotFoundException exception = new ConfigDataResourceNotFoundException(this.resource,
				this.cause);
		assertThat(exception.getResource()).isSameAs(this.resource);
		assertThat(exception.getCause()).isSameAs(this.cause);
	}

	@Test
	void getResourceReturnsResource() {
		ConfigDataResourceNotFoundException exception = new ConfigDataResourceNotFoundException(this.resource);
		assertThat(exception.getResource()).isSameAs(this.resource);
	}

	@Test
	void getLocationWhenHasNoLocationReturnsNull() {
		ConfigDataResourceNotFoundException exception = new ConfigDataResourceNotFoundException(this.resource);
		assertThat(exception.getLocation()).isNull();
	}

	@Test
	void getLocationWhenHasLocationReturnsLocation() {
		ConfigDataResourceNotFoundException exception = new ConfigDataResourceNotFoundException(this.resource)
			.withLocation(this.location);
		assertThat(exception.getLocation()).isSameAs(this.location);
	}

	@Test
	void getReferenceDescriptionWhenHasNoLocationReturnsDescription() {
		ConfigDataResourceNotFoundException exception = new ConfigDataResourceNotFoundException(this.resource);
		assertThat(exception.getReferenceDescription()).isEqualTo("resource 'mytestresource'");
	}

	@Test
	void getReferenceDescriptionWhenHasLocationReturnsDescription() {
		ConfigDataResourceNotFoundException exception = new ConfigDataResourceNotFoundException(this.resource)
			.withLocation(this.location);
		assertThat(exception.getReferenceDescription())
			.isEqualTo("resource 'mytestresource' via location 'optional:test'");
	}

	@Test
	void withLocationReturnsNewInstanceWithLocation() {
		ConfigDataResourceNotFoundException exception = new ConfigDataResourceNotFoundException(this.resource)
			.withLocation(this.location);
		assertThat(exception.getLocation()).isSameAs(this.location);
	}

	@Test
	void throwIfDoesNotExistWhenPathExistsDoesNothing() {
		ConfigDataResourceNotFoundException.throwIfDoesNotExist(this.resource, this.exists.toPath());
	}

	@Test
	void throwIfDoesNotExistWhenPathDoesNotExistThrowsException() {
		assertThatExceptionOfType(ConfigDataResourceNotFoundException.class).isThrownBy(
				() -> ConfigDataResourceNotFoundException.throwIfDoesNotExist(this.resource, this.missing.toPath()));
	}

	@Test
	void throwIfDoesNotExistWhenFileExistsDoesNothing() {
		ConfigDataResourceNotFoundException.throwIfDoesNotExist(this.resource, this.exists);

	}

	@Test
	void throwIfDoesNotExistWhenFileDoesNotExistThrowsException() {
		assertThatExceptionOfType(ConfigDataResourceNotFoundException.class)
			.isThrownBy(() -> ConfigDataResourceNotFoundException.throwIfDoesNotExist(this.resource, this.missing));
	}

	@Test
	void throwIfDoesNotExistWhenResourceExistsDoesNothing() {
		ConfigDataResourceNotFoundException.throwIfDoesNotExist(this.resource, new FileSystemResource(this.exists));
	}

	@Test
	void throwIfDoesNotExistWhenResourceDoesNotExistThrowsException() {
		assertThatExceptionOfType(ConfigDataResourceNotFoundException.class)
			.isThrownBy(() -> ConfigDataResourceNotFoundException.throwIfDoesNotExist(this.resource,
					new FileSystemResource(this.missing)));
	}

	static class TestConfigDataResource extends ConfigDataResource {

		@Override
		public String toString() {
			return "mytestresource";
		}

	}

}

Analyze Your Own Codebase

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

Try Supermodel Free