Skip to content

Commit 45cc649

Browse files
committed
Merge branch '2.1.x'
2 parents a84a6c3 + 82bc875 commit 45cc649

File tree

26 files changed

+266
-430
lines changed

26 files changed

+266
-430
lines changed

spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/invoke/convert/ConversionServiceParameterValueMapperTests.java

+9-11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2018 the original author or authors.
2+
* Copyright 2012-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -28,7 +28,6 @@
2828

2929
import static org.assertj.core.api.Assertions.assertThat;
3030
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
31-
import static org.junit.Assert.fail;
3231
import static org.mockito.ArgumentMatchers.any;
3332
import static org.mockito.BDDMockito.given;
3433
import static org.mockito.Mockito.mock;
@@ -61,15 +60,14 @@ public void mapParameterWhenConversionServiceFailsShouldThrowParameterMappingExc
6160
given(conversionService.convert(any(), any())).willThrow(error);
6261
ConversionServiceParameterValueMapper mapper = new ConversionServiceParameterValueMapper(
6362
conversionService);
64-
try {
65-
mapper.mapParameterValue(new TestOperationParameter(Integer.class), "123");
66-
fail("Did not throw");
67-
}
68-
catch (ParameterMappingException ex) {
69-
assertThat(ex.getValue()).isEqualTo("123");
70-
assertThat(ex.getParameter().getType()).isEqualTo(Integer.class);
71-
assertThat(ex.getCause()).isEqualTo(error);
72-
}
63+
assertThatExceptionOfType(ParameterMappingException.class)
64+
.isThrownBy(() -> mapper.mapParameterValue(
65+
new TestOperationParameter(Integer.class), "123"))
66+
.satisfies((ex) -> {
67+
assertThat(ex.getValue()).isEqualTo("123");
68+
assertThat(ex.getParameter().getType()).isEqualTo(Integer.class);
69+
assertThat(ex.getCause()).isEqualTo(error);
70+
});
7371
}
7472

7573
@Test

spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/trace/http/reactive/HttpTraceWebFilterTests.java

+10-15
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2018 the original author or authors.
2+
* Copyright 2012-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -36,7 +36,7 @@
3636
import org.springframework.web.server.ServerWebExchangeDecorator;
3737

3838
import static org.assertj.core.api.Assertions.assertThat;
39-
import static org.junit.Assert.fail;
39+
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
4040
import static org.mockito.BDDMockito.given;
4141
import static org.mockito.Mockito.mock;
4242

@@ -123,19 +123,14 @@ public Mono<Principal> getPrincipal() {
123123
@Test
124124
public void statusIsAssumedToBe500WhenChainFails()
125125
throws ServletException, IOException {
126-
try {
127-
this.filter
128-
.filter(MockServerWebExchange
129-
.from(MockServerHttpRequest.get("https://api.example.com")),
130-
(exchange) -> Mono.error(new RuntimeException()))
131-
.block(Duration.ofSeconds(30));
132-
fail();
133-
}
134-
catch (Exception ex) {
135-
assertThat(this.repository.findAll()).hasSize(1);
136-
assertThat(this.repository.findAll().get(0).getResponse().getStatus())
137-
.isEqualTo(500);
138-
}
126+
assertThatExceptionOfType(Exception.class).isThrownBy(() -> this.filter
127+
.filter(MockServerWebExchange
128+
.from(MockServerHttpRequest.get("https://api.example.com")),
129+
(exchange) -> Mono.error(new RuntimeException()))
130+
.block(Duration.ofSeconds(30)));
131+
assertThat(this.repository.findAll()).hasSize(1);
132+
assertThat(this.repository.findAll().get(0).getResponse().getStatus())
133+
.isEqualTo(500);
139134
}
140135

141136
}

spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/trace/http/servlet/HttpTraceFilterTests.java

+20-21
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2018 the original author or authors.
2+
* Copyright 2012-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -37,7 +37,7 @@
3737
import org.springframework.mock.web.MockHttpServletResponse;
3838

3939
import static org.assertj.core.api.Assertions.assertThat;
40-
import static org.junit.Assert.fail;
40+
import static org.assertj.core.api.Assertions.assertThatIOException;
4141
import static org.mockito.BDDMockito.given;
4242
import static org.mockito.Mockito.mock;
4343

@@ -106,25 +106,24 @@ public void filterCapturesPrincipal() throws ServletException, IOException {
106106
@Test
107107
public void statusIsAssumedToBe500WhenChainFails()
108108
throws ServletException, IOException {
109-
try {
110-
this.filter.doFilter(new MockHttpServletRequest(),
111-
new MockHttpServletResponse(), new MockFilterChain(new HttpServlet() {
112-
113-
@Override
114-
protected void service(HttpServletRequest req,
115-
HttpServletResponse resp)
116-
throws ServletException, IOException {
117-
throw new IOException();
118-
}
119-
120-
}));
121-
fail("Filter swallowed IOException");
122-
}
123-
catch (IOException ex) {
124-
assertThat(this.repository.findAll()).hasSize(1);
125-
assertThat(this.repository.findAll().get(0).getResponse().getStatus())
126-
.isEqualTo(500);
127-
}
109+
assertThatIOException()
110+
.isThrownBy(() -> this.filter.doFilter(new MockHttpServletRequest(),
111+
new MockHttpServletResponse(),
112+
new MockFilterChain(new HttpServlet() {
113+
114+
@Override
115+
protected void service(HttpServletRequest req,
116+
HttpServletResponse resp)
117+
throws ServletException, IOException {
118+
throw new IOException();
119+
}
120+
121+
})))
122+
.satisfies((ex) -> {
123+
assertThat(this.repository.findAll()).hasSize(1);
124+
assertThat(this.repository.findAll().get(0).getResponse().getStatus())
125+
.isEqualTo(500);
126+
});
128127
}
129128

130129
@Test

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/OnBeanConditionTypeDeductionFailureTests.java

+16-17
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2017 the original author or authors.
2+
* Copyright 2012-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -31,7 +31,7 @@
3131
import org.springframework.core.type.AnnotationMetadata;
3232

3333
import static org.assertj.core.api.Assertions.assertThat;
34-
import static org.junit.Assert.fail;
34+
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
3535

3636
/**
3737
* Tests for {@link OnBeanCondition} when deduction of the bean's type fails
@@ -44,21 +44,20 @@ public class OnBeanConditionTypeDeductionFailureTests {
4444

4545
@Test
4646
public void conditionalOnMissingBeanWithDeducedTypeThatIsPartiallyMissingFromClassPath() {
47-
try {
48-
new AnnotationConfigApplicationContext(ImportingConfiguration.class).close();
49-
fail("Context refresh was successful");
50-
}
51-
catch (Exception ex) {
52-
Throwable beanTypeDeductionException = findNestedCause(ex,
53-
BeanTypeDeductionException.class);
54-
assertThat(beanTypeDeductionException)
55-
.hasMessage("Failed to deduce bean type for "
56-
+ OnMissingBeanConfiguration.class.getName()
57-
+ ".objectMapper");
58-
assertThat(findNestedCause(beanTypeDeductionException,
59-
NoClassDefFoundError.class)).isNotNull();
60-
61-
}
47+
assertThatExceptionOfType(Exception.class).isThrownBy(
48+
() -> new AnnotationConfigApplicationContext(ImportingConfiguration.class)
49+
.close())
50+
.satisfies((ex) -> {
51+
Throwable beanTypeDeductionException = findNestedCause(ex,
52+
BeanTypeDeductionException.class);
53+
assertThat(beanTypeDeductionException)
54+
.hasMessage("Failed to deduce bean type for "
55+
+ OnMissingBeanConfiguration.class.getName()
56+
+ ".objectMapper");
57+
assertThat(findNestedCause(beanTypeDeductionException,
58+
NoClassDefFoundError.class)).isNotNull();
59+
60+
});
6261
}
6362

6463
private Throwable findNestedCause(Throwable ex, Class<? extends Throwable> target) {

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/DataSourceInitializerInvokerTests.java

+9-12
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2018 the original author or authors.
2+
* Copyright 2012-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -47,7 +47,7 @@
4747
import org.springframework.util.ClassUtils;
4848

4949
import static org.assertj.core.api.Assertions.assertThat;
50-
import static org.junit.Assert.fail;
50+
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
5151

5252
/**
5353
* Tests for {@link DataSourceInitializerInvoker}.
@@ -178,16 +178,13 @@ private ContextConsumer<AssertableApplicationContext> assertInitializationIsDisa
178178

179179
private void assertDataSourceNotInitialized(DataSource dataSource) {
180180
JdbcOperations template = new JdbcTemplate(dataSource);
181-
try {
182-
template.queryForObject("SELECT COUNT(*) from BAR", Integer.class);
183-
fail("Query should have failed as BAR table does not exist");
184-
}
185-
catch (BadSqlGrammarException ex) {
186-
SQLException sqlException = ex.getSQLException();
187-
int expectedCode = -5501; // user lacks privilege or object not
188-
// found
189-
assertThat(sqlException.getErrorCode()).isEqualTo(expectedCode);
190-
}
181+
assertThatExceptionOfType(BadSqlGrammarException.class).isThrownBy(
182+
() -> template.queryForObject("SELECT COUNT(*) from BAR", Integer.class))
183+
.satisfies((ex) -> {
184+
SQLException sqlException = ex.getSQLException();
185+
int expectedCode = -5501; // user lacks privilege or object not found
186+
assertThat(sqlException.getErrorCode()).isEqualTo(expectedCode);
187+
});
191188
}
192189

193190
@Test

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jooq/JooqAutoConfigurationTests.java

+11-21
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2018 the original author or authors.
2+
* Copyright 2012-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -52,7 +52,7 @@
5252
import org.springframework.transaction.PlatformTransactionManager;
5353

5454
import static org.assertj.core.api.Assertions.assertThat;
55-
import static org.junit.Assert.fail;
55+
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
5656

5757
/**
5858
* Tests for {@link JooqAutoConfiguration}.
@@ -90,15 +90,10 @@ public void jooqWithoutTx() {
9090
"insert into jooqtest (name) values ('foo');"));
9191
dsl.transaction(new AssertFetch(dsl,
9292
"select count(*) as total from jooqtest;", "1"));
93-
try {
94-
dsl.transaction(new ExecuteSql(dsl,
95-
"insert into jooqtest (name) values ('bar');",
96-
"insert into jooqtest (name) values ('foo');"));
97-
fail("An DataIntegrityViolationException should have been thrown.");
98-
}
99-
catch (DataIntegrityViolationException ex) {
100-
// Ignore
101-
}
93+
assertThatExceptionOfType(DataIntegrityViolationException.class)
94+
.isThrownBy(() -> dsl.transaction(new ExecuteSql(dsl,
95+
"insert into jooqtest (name) values ('bar');",
96+
"insert into jooqtest (name) values ('foo');")));
10297
dsl.transaction(new AssertFetch(dsl,
10398
"select count(*) as total from jooqtest;", "2"));
10499
});
@@ -120,19 +115,14 @@ public void jooqWithTx() {
120115
"insert into jooqtest_tx (name) values ('foo');"));
121116
dsl.transaction(new AssertFetch(dsl,
122117
"select count(*) as total from jooqtest_tx;", "1"));
123-
try {
124-
dsl.transaction(new ExecuteSql(dsl,
125-
"insert into jooqtest (name) values ('bar');",
126-
"insert into jooqtest (name) values ('foo');"));
127-
fail("A DataIntegrityViolationException should have been thrown.");
128-
}
129-
catch (DataIntegrityViolationException ex) {
130-
// Ignore
131-
}
118+
assertThatExceptionOfType(DataIntegrityViolationException.class)
119+
.isThrownBy(() -> dsl.transaction(new ExecuteSql(dsl,
120+
"insert into jooqtest (name) values ('bar');",
121+
"insert into jooqtest (name) values ('foo');")));
132122
dsl.transaction(new AssertFetch(dsl,
133123
"select count(*) as total from jooqtest_tx;", "1"));
134-
135124
});
125+
136126
}
137127

138128
@Test

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/logging/ConditionEvaluationReportLoggingListenerTests.java

+10-19
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2018 the original author or authors.
2+
* Copyright 2012-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -42,8 +42,8 @@
4242
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
4343

4444
import static org.assertj.core.api.Assertions.assertThat;
45+
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
4546
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
46-
import static org.junit.Assert.fail;
4747

4848
/**
4949
* Tests for {@link ConditionEvaluationReportLoggingListener}.
@@ -75,15 +75,10 @@ public void logsDebugOnError() {
7575
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
7676
this.initializer.initialize(context);
7777
context.register(ErrorConfig.class);
78-
try {
79-
context.refresh();
80-
fail("Did not error");
81-
}
82-
catch (Exception ex) {
83-
withDebugLogging(
84-
() -> this.initializer.onApplicationEvent(new ApplicationFailedEvent(
85-
new SpringApplication(), new String[0], context, ex)));
86-
}
78+
assertThatExceptionOfType(Exception.class).isThrownBy(context::refresh).satisfies(
79+
(ex) -> withDebugLogging(() -> this.initializer.onApplicationEvent(
80+
new ApplicationFailedEvent(new SpringApplication(), new String[0],
81+
context, ex))));
8782
assertThat(this.output.toString()).contains("CONDITIONS EVALUATION REPORT");
8883
}
8984

@@ -92,14 +87,10 @@ public void logsInfoOnErrorIfDebugDisabled() {
9287
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
9388
this.initializer.initialize(context);
9489
context.register(ErrorConfig.class);
95-
try {
96-
context.refresh();
97-
fail("Did not error");
98-
}
99-
catch (Exception ex) {
100-
this.initializer.onApplicationEvent(new ApplicationFailedEvent(
101-
new SpringApplication(), new String[0], context, ex));
102-
}
90+
assertThatExceptionOfType(Exception.class).isThrownBy(context::refresh)
91+
.satisfies((ex) -> this.initializer.onApplicationEvent(
92+
new ApplicationFailedEvent(new SpringApplication(), new String[0],
93+
context, ex)));
10394
assertThat(this.output.toString()).contains("Error starting"
10495
+ " ApplicationContext. To display the conditions report re-run"
10596
+ " your application with 'debug' enabled.");

spring-boot-project/spring-boot-cli/src/test/java/org/springframework/boot/cli/GrabCommandIntegrationTests.java

+6-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2018 the original author or authors.
2+
* Copyright 2012-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -28,7 +28,7 @@
2828
import org.springframework.util.FileSystemUtils;
2929

3030
import static org.assertj.core.api.Assertions.assertThat;
31-
import static org.junit.Assert.fail;
31+
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
3232

3333
/**
3434
* Integration tests for {@link GrabCommand}
@@ -67,14 +67,10 @@ public void grab() throws Exception {
6767

6868
@Test
6969
public void duplicateDependencyManagementBomAnnotationsProducesAnError() {
70-
try {
71-
this.cli.grab("duplicateDependencyManagementBom.groovy");
72-
fail();
73-
}
74-
catch (Exception ex) {
75-
assertThat(ex.getMessage())
76-
.contains("Duplicate @DependencyManagementBom annotation");
77-
}
70+
assertThatExceptionOfType(Exception.class)
71+
.isThrownBy(
72+
() -> this.cli.grab("duplicateDependencyManagementBom.groovy"))
73+
.withMessageContaining("Duplicate @DependencyManagementBom annotation");
7874
}
7975

8076
@Test

0 commit comments

Comments
 (0)