From 31316a11fdb7fa407063e9024259750bfd5c612e Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Fri, 11 Sep 2020 16:36:55 +0200 Subject: [PATCH] Polishing --- .../mock/web/MockHttpServletRequestTests.java | 3 +-- .../ContextHierarchyDirtiesContextTests.java | 4 ++-- ...sactionalAfterTestMethodSqlScriptsTests.java | 4 ++-- .../jdbc/TransactionalSqlScriptsTests.java | 4 ++-- .../transaction/ejb/AbstractEjbTxDaoTests.java | 4 ++-- .../samples/client/context/JavaConfigTests.java | 17 +++++++---------- .../client/standalone/ResponseBodyTests.java | 6 ++++-- .../samples/standalone/ResponseBodyTests.java | 6 +++--- 8 files changed, 23 insertions(+), 25 deletions(-) diff --git a/spring-test/src/test/java/org/springframework/mock/web/MockHttpServletRequestTests.java b/spring-test/src/test/java/org/springframework/mock/web/MockHttpServletRequestTests.java index 76104fbb6fb..ed837c9267c 100644 --- a/spring-test/src/test/java/org/springframework/mock/web/MockHttpServletRequestTests.java +++ b/spring-test/src/test/java/org/springframework/mock/web/MockHttpServletRequestTests.java @@ -297,8 +297,7 @@ class MockHttpServletRequestTests { assertThat(cookieHeaders) .describedAs("Cookies -> Header conversion works as expected per RFC6265") - .hasSize(1) - .hasOnlyOneElementSatisfying(header -> assertThat(header).isEqualTo("foo=bar; baz=qux")); + .singleElement().isEqualTo("foo=bar; baz=qux"); } @Test diff --git a/spring-test/src/test/java/org/springframework/test/context/ContextHierarchyDirtiesContextTests.java b/spring-test/src/test/java/org/springframework/test/context/ContextHierarchyDirtiesContextTests.java index 7ca80b0a462..2cbccdb0aa3 100644 --- a/spring-test/src/test/java/org/springframework/test/context/ContextHierarchyDirtiesContextTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/ContextHierarchyDirtiesContextTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 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. @@ -44,7 +44,7 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Tadaya Tsuyukubo * @since 3.2.2 */ -@TestMethodOrder(MethodOrderer.Alphanumeric.class) +@TestMethodOrder(MethodOrderer.MethodName.class) class ContextHierarchyDirtiesContextTests { private static ApplicationContext context; diff --git a/spring-test/src/test/java/org/springframework/test/context/jdbc/TransactionalAfterTestMethodSqlScriptsTests.java b/spring-test/src/test/java/org/springframework/test/context/jdbc/TransactionalAfterTestMethodSqlScriptsTests.java index b3f4091a678..546d1a5f30b 100644 --- a/spring-test/src/test/java/org/springframework/test/context/jdbc/TransactionalAfterTestMethodSqlScriptsTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/jdbc/TransactionalAfterTestMethodSqlScriptsTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 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. @@ -39,7 +39,7 @@ import static org.springframework.test.context.jdbc.Sql.ExecutionPhase.AFTER_TES * @since 4.1 */ @SpringJUnitConfig(EmptyDatabaseConfig.class) -@TestMethodOrder(MethodOrderer.Alphanumeric.class) +@TestMethodOrder(MethodOrderer.MethodName.class) @DirtiesContext class TransactionalAfterTestMethodSqlScriptsTests extends AbstractTransactionalTests { diff --git a/spring-test/src/test/java/org/springframework/test/context/jdbc/TransactionalSqlScriptsTests.java b/spring-test/src/test/java/org/springframework/test/context/jdbc/TransactionalSqlScriptsTests.java index f77ed9bc28b..bba80aec144 100644 --- a/spring-test/src/test/java/org/springframework/test/context/jdbc/TransactionalSqlScriptsTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/jdbc/TransactionalSqlScriptsTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 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. @@ -30,7 +30,7 @@ import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; * @since 4.1 */ @SpringJUnitConfig(EmptyDatabaseConfig.class) -@TestMethodOrder(MethodOrderer.Alphanumeric.class) +@TestMethodOrder(MethodOrderer.MethodName.class) @Sql({ "schema.sql", "data.sql" }) @DirtiesContext class TransactionalSqlScriptsTests extends AbstractTransactionalTests { diff --git a/spring-test/src/test/java/org/springframework/test/context/transaction/ejb/AbstractEjbTxDaoTests.java b/spring-test/src/test/java/org/springframework/test/context/transaction/ejb/AbstractEjbTxDaoTests.java index a3afc5e129f..a98ce7135cc 100644 --- a/spring-test/src/test/java/org/springframework/test/context/transaction/ejb/AbstractEjbTxDaoTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/transaction/ejb/AbstractEjbTxDaoTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 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. @@ -44,7 +44,7 @@ import static org.assertj.core.api.Assertions.assertThat; @SpringJUnitConfig @Transactional @DirtiesContext(classMode = ClassMode.AFTER_CLASS) -@TestMethodOrder(MethodOrderer.Alphanumeric.class) +@TestMethodOrder(MethodOrderer.MethodName.class) abstract class AbstractEjbTxDaoTests { protected static final String TEST_NAME = "test-name"; diff --git a/spring-test/src/test/java/org/springframework/test/web/servlet/samples/client/context/JavaConfigTests.java b/spring-test/src/test/java/org/springframework/test/web/servlet/samples/client/context/JavaConfigTests.java index f8b02550ece..7f27c859c6d 100644 --- a/spring-test/src/test/java/org/springframework/test/web/servlet/samples/client/context/JavaConfigTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/servlet/samples/client/context/JavaConfigTests.java @@ -57,7 +57,7 @@ import static org.mockito.BDDMockito.given; @ContextConfiguration(classes = JavaConfigTests.RootConfig.class), @ContextConfiguration(classes = JavaConfigTests.WebConfig.class) }) -public class JavaConfigTests { +class JavaConfigTests { @Autowired private WebApplicationContext wac; @@ -65,21 +65,18 @@ public class JavaConfigTests { @Autowired private PersonDao personDao; - @Autowired - private PersonController personController; - private WebTestClient testClient; @BeforeEach - public void setup() { + void setup() { this.testClient = MockMvcWebTestClient.bindToApplicationContext(this.wac).build(); given(this.personDao.getPerson(5L)).willReturn(new Person("Joe")); } @Test - public void person() { + void person() { testClient.get().uri("/person/5") .accept(MediaType.APPLICATION_JSON) .exchange() @@ -88,7 +85,7 @@ public class JavaConfigTests { } @Test - public void tilesDefinitions() { + void tilesDefinitions() { testClient.get().uri("/") .exchange() .expectStatus().isOk() @@ -100,7 +97,7 @@ public class JavaConfigTests { static class RootConfig { @Bean - public PersonDao personDao() { + PersonDao personDao() { return Mockito.mock(PersonDao.class); } } @@ -113,7 +110,7 @@ public class JavaConfigTests { private RootConfig rootConfig; @Bean - public PersonController personController() { + PersonController personController() { return new PersonController(this.rootConfig.personDao()); } @@ -138,7 +135,7 @@ public class JavaConfigTests { } @Bean - public TilesConfigurer tilesConfigurer() { + TilesConfigurer tilesConfigurer() { TilesConfigurer configurer = new TilesConfigurer(); configurer.setDefinitions("/WEB-INF/**/tiles.xml"); return configurer; diff --git a/spring-test/src/test/java/org/springframework/test/web/servlet/samples/client/standalone/ResponseBodyTests.java b/spring-test/src/test/java/org/springframework/test/web/servlet/samples/client/standalone/ResponseBodyTests.java index d441e8d0aa7..1f8cd1f787c 100644 --- a/spring-test/src/test/java/org/springframework/test/web/servlet/samples/client/standalone/ResponseBodyTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/servlet/samples/client/standalone/ResponseBodyTests.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.test.web.servlet.samples.client.standalone; import javax.validation.constraints.NotNull; @@ -33,7 +34,7 @@ import static org.hamcrest.Matchers.equalTo; * * @author Rossen Stoyanchev */ -public class ResponseBodyTests { +class ResponseBodyTests { @Test void json() { @@ -56,13 +57,14 @@ public class ResponseBodyTests { private static class PersonController { @GetMapping("/person/{name}") - public Person get(@PathVariable String name) { + Person get(@PathVariable String name) { Person person = new Person(name); person.setAge(42); return person; } } + @SuppressWarnings("unused") private static class Person { @NotNull diff --git a/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/ResponseBodyTests.java b/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/ResponseBodyTests.java index 5dabd07ab55..2799b24d191 100644 --- a/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/ResponseBodyTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/ResponseBodyTests.java @@ -38,10 +38,10 @@ import static org.springframework.test.web.servlet.setup.MockMvcBuilders.standal * @author Rossen Stoyanchev * @author Sam Brannen */ -public class ResponseBodyTests { +class ResponseBodyTests { @Test - public void json() throws Exception { + void json() throws Exception { standaloneSetup(new PersonController()).build() .perform(get("/person/Lee").accept(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()) @@ -60,7 +60,7 @@ public class ResponseBodyTests { private static class PersonController { @GetMapping("/person/{name}") - public Person get(@PathVariable String name) { + Person get(@PathVariable String name) { Person person = new Person(name); person.setAge(42); return person;