Skip to content

Commit 36d6a78

Browse files
committed
Polishing.
Simplify test arrangement, remove tests testing framework functionality. See #3028
1 parent b62bb53 commit 36d6a78

File tree

1 file changed

+18
-45
lines changed

1 file changed

+18
-45
lines changed

src/test/java/org/springframework/data/web/config/EnableSpringDataWebSupportIntegrationTests.java

+18-45
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,12 @@
2222
import java.util.Arrays;
2323
import java.util.List;
2424

25-
import com.fasterxml.jackson.databind.Module;
2625
import org.junit.jupiter.api.Test;
26+
2727
import org.springframework.beans.factory.annotation.Autowired;
2828
import org.springframework.context.ApplicationContext;
2929
import org.springframework.context.annotation.Bean;
3030
import org.springframework.context.annotation.Configuration;
31-
import org.springframework.context.annotation.Primary;
3231
import org.springframework.core.convert.ConversionService;
3332
import org.springframework.data.classloadersupport.HidingClassLoader;
3433
import org.springframework.data.geo.Distance;
@@ -54,6 +53,7 @@
5453
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter;
5554
import org.springframework.web.util.UriComponentsBuilder;
5655

56+
import com.fasterxml.jackson.databind.Module;
5757
import com.fasterxml.jackson.databind.ObjectMapper;
5858

5959
/**
@@ -125,8 +125,7 @@ SimpleEntityPathResolver entityPathResolver() {
125125
@Configuration
126126
static class PageSampleConfig extends WebMvcConfigurationSupport {
127127

128-
@Autowired
129-
private List<Module> modules;
128+
@Autowired private List<Module> modules;
130129

131130
@Bean
132131
PageSampleController controller() {
@@ -140,27 +139,14 @@ protected void configureMessageConverters(List<HttpMessageConverter<?>> converte
140139
}
141140
}
142141

143-
144142
@EnableSpringDataWebSupport
145-
static class PageSampleConfigWithDirect extends PageSampleConfig {
146-
}
143+
static class PageSampleConfigWithDirect extends PageSampleConfig {}
147144

148145
@EnableSpringDataWebSupport(pageSerializationMode = EnableSpringDataWebSupport.PageSerializationMode.VIA_DTO)
149-
static class PageSampleConfigWithViaDto extends PageSampleConfig {
150-
}
151-
152-
@EnableSpringDataWebSupport
153-
static class PageSampleConfigWithSpringDataWebSettings extends PageSampleConfig {
154-
155-
@Primary
156-
@Bean
157-
SpringDataWebSettings SpringDataWebSettings() {
158-
return new SpringDataWebSettings(EnableSpringDataWebSupport.PageSerializationMode.VIA_DTO);
159-
}
160-
}
146+
static class PageSampleConfigWithViaDto extends PageSampleConfig {}
161147

162148
@Test // DATACMNS-330
163-
void registersBasicBeanDefinitions() throws Exception {
149+
void registersBasicBeanDefinitions() {
164150

165151
ApplicationContext context = WebTestUtils.createApplicationContext(SampleConfig.class);
166152
var names = Arrays.asList(context.getBeanDefinitionNames());
@@ -172,7 +158,7 @@ void registersBasicBeanDefinitions() throws Exception {
172158
}
173159

174160
@Test // DATACMNS-330
175-
void registersHateoasSpecificBeanDefinitions() throws Exception {
161+
void registersHateoasSpecificBeanDefinitions() {
176162

177163
ApplicationContext context = WebTestUtils.createApplicationContext(SampleConfig.class);
178164
var names = Arrays.asList(context.getBeanDefinitionNames());
@@ -182,7 +168,7 @@ void registersHateoasSpecificBeanDefinitions() throws Exception {
182168
}
183169

184170
@Test // DATACMNS-330
185-
void doesNotRegisterHateoasSpecificComponentsIfHateoasNotPresent() throws Exception {
171+
void doesNotRegisterHateoasSpecificComponentsIfHateoasNotPresent() {
186172

187173
var classLoader = HidingClassLoader.hide(Link.class);
188174

@@ -195,7 +181,7 @@ void doesNotRegisterHateoasSpecificComponentsIfHateoasNotPresent() throws Except
195181
}
196182

197183
@Test // DATACMNS-475
198-
void registersJacksonSpecificBeanDefinitions() throws Exception {
184+
void registersJacksonSpecificBeanDefinitions() {
199185

200186
ApplicationContext context = WebTestUtils.createApplicationContext(SampleConfig.class);
201187
var names = Arrays.asList(context.getBeanDefinitionNames());
@@ -204,7 +190,7 @@ void registersJacksonSpecificBeanDefinitions() throws Exception {
204190
}
205191

206192
@Test // DATACMNS-475
207-
void doesNotRegisterJacksonSpecificComponentsIfJacksonNotPresent() throws Exception {
193+
void doesNotRegisterJacksonSpecificComponentsIfJacksonNotPresent() {
208194

209195
ApplicationContext context = WebTestUtils.createApplicationContext(HidingClassLoader.hide(ObjectMapper.class),
210196
SampleConfig.class);
@@ -312,10 +298,8 @@ void registersSpringDataWebSettingsBean() {
312298

313299
ApplicationContext context = WebTestUtils.createApplicationContext(SampleConfig.class);
314300

315-
assertThatNoException().isThrownBy(() -> {
316-
assertThat(context.getBean(SpringDataWebSettings.class));
317-
assertThat(context.getBean(PageModule.class));
318-
});
301+
assertThatNoException().isThrownBy(() -> context.getBean(SpringDataWebSettings.class));
302+
assertThatNoException().isThrownBy(() -> context.getBean(PageModule.class));
319303
}
320304

321305
@Test // GH-3024
@@ -324,9 +308,9 @@ void usesDirectPageSerializationMode() throws Exception {
324308
var applicationContext = WebTestUtils.createApplicationContext(PageSampleConfigWithDirect.class);
325309
var mvc = MockMvcBuilders.webAppContextSetup(applicationContext).build();
326310

327-
mvc.perform(post("/page")).//
328-
andExpect(status().isOk()).//
329-
andExpect(jsonPath("$.pageable").exists());
311+
mvc.perform(post("/page"))//
312+
.andExpect(status().isOk()) //
313+
.andExpect(jsonPath("$.pageable").exists());
330314
}
331315

332316
@Test // GH-3024
@@ -335,20 +319,9 @@ void usesViaDtoPageSerializationMode() throws Exception {
335319
var applicationContext = WebTestUtils.createApplicationContext(PageSampleConfigWithViaDto.class);
336320
var mvc = MockMvcBuilders.webAppContextSetup(applicationContext).build();
337321

338-
mvc.perform(post("/page")).//
339-
andExpect(status().isOk()).//
340-
andExpect(jsonPath("$.page").exists());
341-
}
342-
343-
@Test // GH-3024
344-
void overridesPageSerializationModeByCustomizingSpringDataWebSettings() throws Exception {
345-
346-
var applicationContext = WebTestUtils.createApplicationContext(PageSampleConfigWithSpringDataWebSettings.class);
347-
var mvc = MockMvcBuilders.webAppContextSetup(applicationContext).build();
348-
349-
mvc.perform(post("/page")).//
350-
andExpect(status().isOk()).//
351-
andExpect(jsonPath("$.page").exists());
322+
mvc.perform(post("/page")) //
323+
.andExpect(status().isOk()) //
324+
.andExpect(jsonPath("$.page").exists());
352325
}
353326

354327
private static void assertResolversRegistered(ApplicationContext context, Class<?>... resolverTypes) {

0 commit comments

Comments
 (0)