Browse Source

Polishing

pull/31445/head
Sam Brannen 1 year ago
parent
commit
87127ab684
  1. 2
      spring-test/src/test/java/org/springframework/test/context/aot/samples/basic/DisabledInAotProcessingTests.java
  2. 2
      spring-test/src/test/java/org/springframework/test/context/aot/samples/basic/DisabledInAotRuntimeClassLevelTests.java
  3. 2
      spring-test/src/test/java/org/springframework/test/context/aot/samples/basic/DisabledInAotRuntimeMethodLevelTests.java
  4. 9
      spring-test/src/test/java/org/springframework/test/context/hierarchies/web/EarTests.java
  5. 33
      spring-test/src/test/java/org/springframework/test/web/servlet/samples/spr/EncodedUriTests.java
  6. 30
      spring-test/src/test/java/org/springframework/test/web/servlet/samples/spr/HttpOptionsTests.java

2
spring-test/src/test/java/org/springframework/test/context/aot/samples/basic/DisabledInAotProcessingTests.java

@ -47,7 +47,7 @@ public class DisabledInAotProcessingTests {
assertThat(enigma).isEqualTo("puzzle"); assertThat(enigma).isEqualTo("puzzle");
} }
@Configuration @Configuration(proxyBeanMethods = false)
static class Config { static class Config {
@Bean @Bean

2
spring-test/src/test/java/org/springframework/test/context/aot/samples/basic/DisabledInAotRuntimeClassLevelTests.java

@ -61,7 +61,7 @@ public class DisabledInAotRuntimeClassLevelTests {
} }
@Configuration(proxyBeanMethods = false) @Configuration(proxyBeanMethods = false)
static class BasicTestConfiguration { static class Config {
@Bean @Bean
MessageService defaultMessageService() { MessageService defaultMessageService() {

2
spring-test/src/test/java/org/springframework/test/context/aot/samples/basic/DisabledInAotRuntimeMethodLevelTests.java

@ -63,7 +63,7 @@ public class DisabledInAotRuntimeMethodLevelTests {
} }
@Configuration(proxyBeanMethods = false) @Configuration(proxyBeanMethods = false)
static class BasicTestConfiguration { static class Config {
@Bean @Bean
MessageService defaultMessageService() { MessageService defaultMessageService() {

9
spring-test/src/test/java/org/springframework/test/context/hierarchies/web/EarTests.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2022 the original author or authors. * Copyright 2002-2023 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -17,14 +17,12 @@
package org.springframework.test.context.hierarchies.web; package org.springframework.test.context.hierarchies.web;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.web.context.WebApplicationContext; import org.springframework.web.context.WebApplicationContext;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
@ -33,8 +31,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Sam Brannen * @author Sam Brannen
* @since 3.2.2 * @since 3.2.2
*/ */
@ExtendWith(SpringExtension.class) @SpringJUnitConfig
@ContextConfiguration
class EarTests { class EarTests {
@Configuration @Configuration

33
spring-test/src/test/java/org/springframework/test/web/servlet/samples/spr/EncodedUriTests.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2022 the original author or authors. * Copyright 2002-2023 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -16,24 +16,18 @@
package org.springframework.test.web.servlet.samples.spr; package org.springframework.test.web.servlet.samples.spr;
import java.net.URI; import java.net.URI;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.BeansException; import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.BeanPostProcessor; import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.core.PriorityOrdered; import org.springframework.core.PriorityOrdered;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit.jupiter.web.SpringJUnitWebConfig;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.ResultActions; import org.springframework.test.web.servlet.ResultActions;
import org.springframework.ui.Model; import org.springframework.ui.Model;
@ -59,23 +53,18 @@ import static org.springframework.test.web.servlet.setup.MockMvcBuilders.webAppC
* *
* @author Sebastien Deleuze * @author Sebastien Deleuze
*/ */
@ExtendWith(SpringExtension.class) @SpringJUnitWebConfig
@WebAppConfiguration
@ContextConfiguration
public class EncodedUriTests { public class EncodedUriTests {
@Autowired private final MockMvc mockMvc;
private WebApplicationContext wac;
private MockMvc mockMvc;
@BeforeEach EncodedUriTests(WebApplicationContext wac) {
public void setup() { this.mockMvc = webAppContextSetup(wac).build();
this.mockMvc = webAppContextSetup(this.wac).build();
} }
@Test @Test
public void test() throws Exception { void test() throws Exception {
String id = "a/b"; String id = "a/b";
URI url = UriComponentsBuilder.fromUriString("/circuit").pathSegment(id).build().encode().toUri(); URI url = UriComponentsBuilder.fromUriString("/circuit").pathSegment(id).build().encode().toUri();
ResultActions result = mockMvc.perform(get(url)); ResultActions result = mockMvc.perform(get(url));
@ -88,12 +77,12 @@ public class EncodedUriTests {
static class WebConfig implements WebMvcConfigurer { static class WebConfig implements WebMvcConfigurer {
@Bean @Bean
public MyController myController() { MyController myController() {
return new MyController(); return new MyController();
} }
@Bean @Bean
public HandlerMappingConfigurer myHandlerMappingConfigurer() { HandlerMappingConfigurer myHandlerMappingConfigurer() {
return new HandlerMappingConfigurer(); return new HandlerMappingConfigurer();
} }
@ -107,7 +96,7 @@ public class EncodedUriTests {
private static class MyController { private static class MyController {
@RequestMapping(value = "/circuit/{id}", method = RequestMethod.GET) @RequestMapping(value = "/circuit/{id}", method = RequestMethod.GET)
public String getCircuit(@PathVariable String id, Model model) { String getCircuit(@PathVariable String id, Model model) {
model.addAttribute("receivedId", id); model.addAttribute("receivedId", id);
return "result"; return "result";
} }

30
spring-test/src/test/java/org/springframework/test/web/servlet/samples/spr/HttpOptionsTests.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2020 the original author or authors. * Copyright 2002-2023 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -18,17 +18,12 @@ package org.springframework.test.web.servlet.samples.spr;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit.jupiter.web.SpringJUnitWebConfig;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.MockMvc;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestMethod;
@ -47,24 +42,21 @@ import static org.springframework.test.web.servlet.setup.MockMvcBuilders.webAppC
* *
* @author Arnaud Cogoluègnes * @author Arnaud Cogoluègnes
*/ */
@ExtendWith(SpringExtension.class) @SpringJUnitWebConfig
@WebAppConfiguration
@ContextConfiguration
public class HttpOptionsTests { public class HttpOptionsTests {
@Autowired private final WebApplicationContext wac;
private WebApplicationContext wac;
private MockMvc mockMvc; private final MockMvc mockMvc;
HttpOptionsTests(WebApplicationContext wac) {
@BeforeEach this.wac = wac;
public void setup() {
this.mockMvc = webAppContextSetup(this.wac).dispatchOptions(true).build(); this.mockMvc = webAppContextSetup(this.wac).dispatchOptions(true).build();
} }
@Test @Test
public void test() throws Exception { void test() throws Exception {
MyController controller = this.wac.getBean(MyController.class); MyController controller = this.wac.getBean(MyController.class);
int initialCount = controller.counter.get(); int initialCount = controller.counter.get();
this.mockMvc.perform(options("/myUrl")).andExpect(status().isOk()); this.mockMvc.perform(options("/myUrl")).andExpect(status().isOk());
@ -78,7 +70,7 @@ public class HttpOptionsTests {
static class WebConfig implements WebMvcConfigurer { static class WebConfig implements WebMvcConfigurer {
@Bean @Bean
public MyController myController() { MyController myController() {
return new MyController(); return new MyController();
} }
} }
@ -91,7 +83,7 @@ public class HttpOptionsTests {
@RequestMapping(value = "/myUrl", method = RequestMethod.OPTIONS) @RequestMapping(value = "/myUrl", method = RequestMethod.OPTIONS)
@ResponseBody @ResponseBody
public void handle() { void handle() {
counter.incrementAndGet(); counter.incrementAndGet();
} }
} }

Loading…
Cancel
Save