Skip to content

Commit 4ec77d4

Browse files
committed
Merge pull request #7193 from izeye:patch-22
* pr/7193: Polish contribution Add a missing return
2 parents 74d3a66 + a03ce0a commit 4ec77d4

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed

spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/orm/jpa/TestDatabaseAutoConfiguration.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ private BeanDefinitionHolder getDataSourceBeanDefinition(
118118
if (ObjectUtils.isEmpty(beanNames)) {
119119
logger.warn("No DataSource beans found, "
120120
+ "embedded version will not be used");
121+
return null;
121122
}
122123
if (beanNames.length == 1) {
123124
String beanName = beanNames[0];
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
* Copyright 2012-2016 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.boot.test.autoconfigure.orm.jpa;
18+
19+
import javax.sql.DataSource;
20+
21+
import org.junit.After;
22+
import org.junit.Test;
23+
24+
import org.springframework.boot.test.util.EnvironmentTestUtils;
25+
import org.springframework.context.ConfigurableApplicationContext;
26+
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
27+
28+
import static org.assertj.core.api.Assertions.assertThat;
29+
30+
/**
31+
* Tests for {@link TestDatabaseAutoConfiguration}.
32+
*
33+
* @author Stephane Nicoll
34+
*/
35+
public class TestDatabaseAutoConfigurationTests {
36+
37+
private ConfigurableApplicationContext context;
38+
39+
@After
40+
public void closeContext() {
41+
if (this.context != null) {
42+
this.context.close();
43+
}
44+
}
45+
46+
@Test
47+
public void replaceWithNoDataSourceAvailable() {
48+
load(null);
49+
assertThat(this.context.getBeansOfType(DataSource.class)).isEmpty();
50+
}
51+
52+
public void load(Class<?> config, String... environment) {
53+
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
54+
if (config != null) {
55+
ctx.register(config);
56+
}
57+
ctx.register(TestDatabaseAutoConfiguration.class);
58+
EnvironmentTestUtils.addEnvironment(ctx, environment);
59+
ctx.refresh();
60+
this.context = ctx;
61+
}
62+
63+
}

0 commit comments

Comments
 (0)