Refine assertions on exception messages
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
* Copyright 2012-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -21,6 +21,7 @@ import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.BeanCreationException;
|
||||
import org.springframework.boot.autoconfigure.web.ServerProperties;
|
||||
import org.springframework.boot.context.properties.bind.validation.BindValidationException;
|
||||
import org.springframework.boot.test.util.TestPropertyValues;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
|
||||
@@ -56,15 +57,15 @@ class SamplePropertyValidationApplicationTests {
|
||||
void bindInvalidHost() {
|
||||
this.context.register(SamplePropertyValidationApplication.class);
|
||||
TestPropertyValues.of("sample.host:xxxxxx", "sample.port:9090").applyTo(this.context);
|
||||
assertThatExceptionOfType(BeanCreationException.class).isThrownBy(() -> this.context.refresh())
|
||||
.withMessageContaining("Failed to bind properties under 'sample'");
|
||||
assertThatExceptionOfType(BeanCreationException.class).isThrownBy(this.context::refresh).havingRootCause()
|
||||
.isInstanceOf(BindValidationException.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
void bindNullHost() {
|
||||
this.context.register(SamplePropertyValidationApplication.class);
|
||||
assertThatExceptionOfType(BeanCreationException.class).isThrownBy(() -> this.context.refresh())
|
||||
.withMessageContaining("Failed to bind properties under 'sample'");
|
||||
assertThatExceptionOfType(BeanCreationException.class).isThrownBy(this.context::refresh).havingRootCause()
|
||||
.isInstanceOf(BindValidationException.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user