Merge branch '2.4.x'
Closes gh-26646
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
* Copyright 2012-2021 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,10 @@ import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.platform.engine.discovery.DiscoverySelectors;
|
||||
import org.junit.platform.launcher.Launcher;
|
||||
import org.junit.platform.launcher.LauncherDiscoveryRequest;
|
||||
import org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder;
|
||||
import org.junit.platform.launcher.core.LauncherFactory;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigurationPackage;
|
||||
@@ -28,9 +32,6 @@ import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.domain.EntityScan;
|
||||
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
|
||||
import org.springframework.boot.test.autoconfigure.orm.jpa.ExampleEntity;
|
||||
import org.springframework.boot.testsupport.junit.platform.Launcher;
|
||||
import org.springframework.boot.testsupport.junit.platform.LauncherDiscoveryRequest;
|
||||
import org.springframework.boot.testsupport.junit.platform.LauncherDiscoveryRequestBuilder;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
@@ -49,7 +50,7 @@ class ImportsContextCustomizerFactoryWithAutoConfigurationTests {
|
||||
static ApplicationContext contextFromTest;
|
||||
|
||||
@Test
|
||||
void testClassesThatHaveSameAnnotationsShareAContext() throws Throwable {
|
||||
void testClassesThatHaveSameAnnotationsShareAContext() {
|
||||
executeTests(DataJpaTest1.class);
|
||||
ApplicationContext test1Context = contextFromTest;
|
||||
executeTests(DataJpaTest3.class);
|
||||
@@ -58,7 +59,7 @@ class ImportsContextCustomizerFactoryWithAutoConfigurationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testClassesThatOnlyHaveDifferingUnrelatedAnnotationsShareAContext() throws Throwable {
|
||||
void testClassesThatOnlyHaveDifferingUnrelatedAnnotationsShareAContext() {
|
||||
executeTests(DataJpaTest1.class);
|
||||
ApplicationContext test1Context = contextFromTest;
|
||||
executeTests(DataJpaTest2.class);
|
||||
@@ -67,7 +68,7 @@ class ImportsContextCustomizerFactoryWithAutoConfigurationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testClassesThatOnlyHaveDifferingPropertyMappedAnnotationAttributesDoNotShareAContext() throws Throwable {
|
||||
void testClassesThatOnlyHaveDifferingPropertyMappedAnnotationAttributesDoNotShareAContext() {
|
||||
executeTests(DataJpaTest1.class);
|
||||
ApplicationContext test1Context = contextFromTest;
|
||||
executeTests(DataJpaTest4.class);
|
||||
@@ -75,11 +76,10 @@ class ImportsContextCustomizerFactoryWithAutoConfigurationTests {
|
||||
assertThat(test1Context).isNotSameAs(test2Context);
|
||||
}
|
||||
|
||||
private void executeTests(Class<?> testClass) throws Throwable {
|
||||
ClassLoader classLoader = testClass.getClassLoader();
|
||||
LauncherDiscoveryRequest request = new LauncherDiscoveryRequestBuilder(classLoader)
|
||||
private void executeTests(Class<?> testClass) {
|
||||
LauncherDiscoveryRequest request = LauncherDiscoveryRequestBuilder.request()
|
||||
.selectors(DiscoverySelectors.selectClass(testClass)).build();
|
||||
Launcher launcher = new Launcher(testClass.getClassLoader());
|
||||
Launcher launcher = LauncherFactory.create();
|
||||
launcher.execute(request);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2020 the original author or authors.
|
||||
* Copyright 2012-2021 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,15 +21,16 @@ import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestMethodOrder;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.junit.platform.engine.discovery.DiscoverySelectors;
|
||||
import org.junit.platform.launcher.Launcher;
|
||||
import org.junit.platform.launcher.LauncherDiscoveryRequest;
|
||||
import org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder;
|
||||
import org.junit.platform.launcher.core.LauncherFactory;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||
import org.springframework.boot.test.system.CapturedOutput;
|
||||
import org.springframework.boot.test.system.OutputCaptureExtension;
|
||||
import org.springframework.boot.testsupport.junit.platform.Launcher;
|
||||
import org.springframework.boot.testsupport.junit.platform.LauncherDiscoveryRequest;
|
||||
import org.springframework.boot.testsupport.junit.platform.LauncherDiscoveryRequestBuilder;
|
||||
import org.springframework.security.test.context.support.WithMockUser;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
@@ -49,22 +50,21 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
||||
class WebMvcTestPrintDefaultIntegrationTests {
|
||||
|
||||
@Test
|
||||
void shouldNotPrint(CapturedOutput output) throws Throwable {
|
||||
void shouldNotPrint(CapturedOutput output) {
|
||||
executeTests(ShouldNotPrint.class);
|
||||
assertThat(output).doesNotContain("HTTP Method");
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldPrint(CapturedOutput output) throws Throwable {
|
||||
void shouldPrint(CapturedOutput output) {
|
||||
executeTests(ShouldPrint.class);
|
||||
assertThat(output).containsOnlyOnce("HTTP Method");
|
||||
}
|
||||
|
||||
private void executeTests(Class<?> testClass) throws Throwable {
|
||||
ClassLoader classLoader = testClass.getClassLoader();
|
||||
LauncherDiscoveryRequest request = new LauncherDiscoveryRequestBuilder(classLoader)
|
||||
private void executeTests(Class<?> testClass) {
|
||||
LauncherDiscoveryRequest request = LauncherDiscoveryRequestBuilder.request()
|
||||
.selectors(DiscoverySelectors.selectClass(testClass)).build();
|
||||
Launcher launcher = new Launcher(testClass.getClassLoader());
|
||||
Launcher launcher = LauncherFactory.create();
|
||||
launcher.execute(request);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user