Skip to content

Commit 8499888

Browse files
committed
Merge branch '3.4.x' into 3.5.x
Closes gh-46223
2 parents 167ec8c + c0d66d1 commit 8499888

File tree

7 files changed

+105
-0
lines changed

7 files changed

+105
-0
lines changed

spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/elasticsearch/ElasticsearchReactiveHealthIndicatorTests.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import org.springframework.boot.actuate.data.elasticsearch.ElasticsearchReactiveHealthIndicator;
3434
import org.springframework.boot.actuate.health.Health;
3535
import org.springframework.boot.actuate.health.Status;
36+
import org.springframework.boot.testsupport.junit.EnabledOnLocale;
3637
import org.springframework.data.elasticsearch.client.elc.ReactiveElasticsearchClient;
3738
import org.springframework.http.HttpHeaders;
3839
import org.springframework.http.HttpStatus;
@@ -87,6 +88,7 @@ void elasticsearchWithYellowStatusIsUp() {
8788
}
8889

8990
@Test
91+
@EnabledOnLocale(language = "en")
9092
void elasticsearchIsDown() throws Exception {
9193
this.server.shutdown();
9294
Health health = this.healthIndicator.health().block(TIMEOUT);

spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/java/org/springframework/boot/maven/AotTests.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
import org.junit.jupiter.api.TestTemplate;
2727
import org.junit.jupiter.api.extension.ExtendWith;
2828

29+
import org.springframework.boot.testsupport.junit.EnabledOnLocale;
30+
2931
import static org.assertj.core.api.Assertions.assertThat;
3032
import static org.assertj.core.api.Assertions.contentOf;
3133

@@ -125,6 +127,7 @@ void whenAotRunsWithReleaseSourcesAreGenerated(MavenBuild mavenBuild) {
125127
}
126128

127129
@TestTemplate
130+
@EnabledOnLocale(language = "en")
128131
void whenAotRunsWithInvalidCompilerArgumentsCompileFails(MavenBuild mavenBuild) {
129132
mavenBuild.project("aot-compiler-arguments")
130133
.goals("package")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Copyright 2012-present 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+
* https://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.testsupport.junit;
18+
19+
import java.lang.annotation.ElementType;
20+
import java.lang.annotation.Retention;
21+
import java.lang.annotation.RetentionPolicy;
22+
import java.lang.annotation.Target;
23+
24+
import org.junit.jupiter.api.extension.ExtendWith;
25+
26+
/**
27+
* {@code @EnabledOnLocale} annotation is used to conditionally enable a test method based
28+
* on the specified locale attributes.
29+
*
30+
* @author Dmytro Nosan
31+
*/
32+
@Target({ ElementType.TYPE, ElementType.METHOD })
33+
@Retention(RetentionPolicy.RUNTIME)
34+
@ExtendWith(EnabledOnLocaleCondition.class)
35+
public @interface EnabledOnLocale {
36+
37+
/**
38+
* Specifies the language code for which the test method should be enabled.
39+
* @return the language code
40+
*/
41+
String language();
42+
43+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Copyright 2012-present 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+
* https://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.testsupport.junit;
18+
19+
import java.util.Locale;
20+
21+
import org.junit.jupiter.api.extension.ConditionEvaluationResult;
22+
import org.junit.jupiter.api.extension.ExecutionCondition;
23+
import org.junit.jupiter.api.extension.ExtensionContext;
24+
import org.junit.platform.commons.support.AnnotationSupport;
25+
26+
/**
27+
* An implementation of {@link ExecutionCondition} that conditionally enables or disables
28+
* the execution of a test method or class based on the specified locale attributes.
29+
*
30+
* @author Dmytro Nosan
31+
*/
32+
class EnabledOnLocaleCondition implements ExecutionCondition {
33+
34+
@Override
35+
public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) {
36+
return AnnotationSupport.findAnnotation(context.getElement(), EnabledOnLocale.class)
37+
.map(this::evaluate)
38+
.orElseGet(() -> ConditionEvaluationResult.enabled("No @EnabledOnLocale annotation found"));
39+
}
40+
41+
private ConditionEvaluationResult evaluate(EnabledOnLocale annotation) {
42+
Locale locale = Locale.getDefault();
43+
String language = locale.getLanguage();
44+
if (!annotation.language().equals(language)) {
45+
return ConditionEvaluationResult.disabled("Disabled on language: " + language);
46+
}
47+
return ConditionEvaluationResult.enabled("Enabled on language: " + language);
48+
}
49+
50+
}

spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/embedded/tomcat/TomcatReactiveWebServerFactoryTests.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import org.junit.jupiter.api.Test;
3939
import org.mockito.InOrder;
4040

41+
import org.springframework.boot.testsupport.junit.EnabledOnLocale;
4142
import org.springframework.boot.web.reactive.server.AbstractReactiveWebServerFactory;
4243
import org.springframework.boot.web.reactive.server.AbstractReactiveWebServerFactoryTests;
4344
import org.springframework.boot.web.server.PortInUseException;
@@ -226,6 +227,7 @@ void referenceClearingIsDisabled() {
226227
}
227228

228229
@Test
230+
@EnabledOnLocale(language = "en")
229231
void portClashOfPrimaryConnectorResultsInPortInUseException() throws Exception {
230232
doWithBlockedPort((port) -> assertThatExceptionOfType(RuntimeException.class).isThrownBy(() -> {
231233
AbstractReactiveWebServerFactory factory = getFactory();

spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/embedded/tomcat/TomcatServletWebServerFactoryTests.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@
8383

8484
import org.springframework.boot.ssl.DefaultSslBundleRegistry;
8585
import org.springframework.boot.testsupport.classpath.resources.WithPackageResources;
86+
import org.springframework.boot.testsupport.junit.EnabledOnLocale;
8687
import org.springframework.boot.testsupport.system.CapturedOutput;
8788
import org.springframework.boot.web.server.PortInUseException;
8889
import org.springframework.boot.web.server.Shutdown;
@@ -367,6 +368,7 @@ void defaultUriEncoding() {
367368
}
368369

369370
@Test
371+
@EnabledOnLocale(language = "en")
370372
void startupFailureDoesNotResultInUnstoppedThreadsBeingReported(CapturedOutput output) throws Exception {
371373
super.portClashOfPrimaryConnectorResultsInPortInUseException();
372374
assertThat(output).doesNotContain("appears to have started a thread named [main]");

spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/server/AbstractServletWebServerFactoryTests.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@
126126
import org.springframework.boot.system.ApplicationTemp;
127127
import org.springframework.boot.testsupport.classpath.resources.ResourcePath;
128128
import org.springframework.boot.testsupport.classpath.resources.WithPackageResources;
129+
import org.springframework.boot.testsupport.junit.EnabledOnLocale;
129130
import org.springframework.boot.testsupport.system.CapturedOutput;
130131
import org.springframework.boot.testsupport.system.OutputCaptureExtension;
131132
import org.springframework.boot.testsupport.web.servlet.DirtiesUrlFactories;
@@ -1088,6 +1089,7 @@ void serverHeaderIsDisabledByDefault() throws Exception {
10881089
}
10891090

10901091
@Test
1092+
@EnabledOnLocale(language = "en")
10911093
protected void portClashOfPrimaryConnectorResultsInPortInUseException() throws Exception {
10921094
doWithBlockedPort((port) -> {
10931095
assertThatExceptionOfType(RuntimeException.class).isThrownBy(() -> {
@@ -1100,6 +1102,7 @@ protected void portClashOfPrimaryConnectorResultsInPortInUseException() throws E
11001102
}
11011103

11021104
@Test
1105+
@EnabledOnLocale(language = "en")
11031106
protected void portClashOfSecondaryConnectorResultsInPortInUseException() throws Exception {
11041107
doWithBlockedPort((port) -> {
11051108
assertThatExceptionOfType(RuntimeException.class).isThrownBy(() -> {

0 commit comments

Comments
 (0)