|
23 | 23 |
|
24 | 24 | import org.junit.jupiter.api.Test;
|
25 | 25 | import org.junit.jupiter.api.extension.ExtendWith;
|
26 |
| -import org.mockito.BDDMockito; |
27 | 26 |
|
28 | 27 | import org.springframework.beans.BeansException;
|
29 | 28 | import org.springframework.beans.factory.BeanCreationException;
|
|
37 | 36 | import org.springframework.context.annotation.Configuration;
|
38 | 37 |
|
39 | 38 | import static org.assertj.core.api.Assertions.assertThat;
|
| 39 | +import static org.mockito.BDDMockito.given; |
40 | 40 | import static org.mockito.Mockito.mock;
|
41 | 41 |
|
42 | 42 | /**
|
|
45 | 45 | * @author Andy Wilkinson
|
46 | 46 | * @author Marten Deinum
|
47 | 47 | * @author Stephane Nicoll
|
| 48 | + * @author Shraddha Yeole |
48 | 49 | */
|
49 | 50 | class H2ConsoleAutoConfigurationTests {
|
50 | 51 |
|
@@ -123,24 +124,22 @@ void dataSourceUrlIsLoggedWhenAvailable(CapturedOutput output) throws BeansExcep
|
123 | 124 | }
|
124 | 125 |
|
125 | 126 | @Test
|
126 |
| - void testDataSource() { |
127 |
| - this.contextRunner.withUserConfiguration(DataSourceAvailable.class) |
128 |
| - .withPropertyValues("spring.h2.console.enabled=true").run((context) -> { |
129 |
| - assertThat(context.isRunning()).isTrue(); |
130 |
| - }); |
| 127 | + void h2ConsoleShouldNotFailIfDatabaseConnectionFails() { |
| 128 | + this.contextRunner.withUserConfiguration(CustomDataSourceConfiguration.class) |
| 129 | + .withPropertyValues("spring.h2.console.enabled=true") |
| 130 | + .run((context) -> assertThat(context.isRunning()).isTrue()); |
131 | 131 | }
|
132 | 132 |
|
133 | 133 | @Configuration(proxyBeanMethods = false)
|
134 |
| - static class DataSourceAvailable { |
| 134 | + static class CustomDataSourceConfiguration { |
135 | 135 |
|
136 | 136 | @Bean
|
137 |
| - public DataSource dataSource() throws SQLException { |
| 137 | + DataSource dataSource() throws SQLException { |
138 | 138 | DataSource dataSource = mock(DataSource.class);
|
139 |
| - BDDMockito.when(dataSource.getConnection()).thenThrow(IllegalStateException.class); |
| 139 | + given(dataSource.getConnection()).willThrow(IllegalStateException.class); |
140 | 140 | return dataSource;
|
141 | 141 | }
|
142 | 142 |
|
143 | 143 | }
|
144 | 144 |
|
145 |
| - |
146 | 145 | }
|
0 commit comments