Polishing

This commit is contained in:
Sam Brannen
2020-09-11 16:36:55 +02:00
parent b2a0978c12
commit 31316a11fd
8 changed files with 23 additions and 25 deletions

View File

@@ -297,8 +297,7 @@ class MockHttpServletRequestTests {
assertThat(cookieHeaders) assertThat(cookieHeaders)
.describedAs("Cookies -> Header conversion works as expected per RFC6265") .describedAs("Cookies -> Header conversion works as expected per RFC6265")
.hasSize(1) .singleElement().isEqualTo("foo=bar; baz=qux");
.hasOnlyOneElementSatisfying(header -> assertThat(header).isEqualTo("foo=bar; baz=qux"));
} }
@Test @Test

View File

@@ -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"); * 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.
@@ -44,7 +44,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Tadaya Tsuyukubo * @author Tadaya Tsuyukubo
* @since 3.2.2 * @since 3.2.2
*/ */
@TestMethodOrder(MethodOrderer.Alphanumeric.class) @TestMethodOrder(MethodOrderer.MethodName.class)
class ContextHierarchyDirtiesContextTests { class ContextHierarchyDirtiesContextTests {
private static ApplicationContext context; private static ApplicationContext context;

View File

@@ -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"); * 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.
@@ -39,7 +39,7 @@ import static org.springframework.test.context.jdbc.Sql.ExecutionPhase.AFTER_TES
* @since 4.1 * @since 4.1
*/ */
@SpringJUnitConfig(EmptyDatabaseConfig.class) @SpringJUnitConfig(EmptyDatabaseConfig.class)
@TestMethodOrder(MethodOrderer.Alphanumeric.class) @TestMethodOrder(MethodOrderer.MethodName.class)
@DirtiesContext @DirtiesContext
class TransactionalAfterTestMethodSqlScriptsTests extends AbstractTransactionalTests { class TransactionalAfterTestMethodSqlScriptsTests extends AbstractTransactionalTests {

View File

@@ -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"); * 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.
@@ -30,7 +30,7 @@ import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
* @since 4.1 * @since 4.1
*/ */
@SpringJUnitConfig(EmptyDatabaseConfig.class) @SpringJUnitConfig(EmptyDatabaseConfig.class)
@TestMethodOrder(MethodOrderer.Alphanumeric.class) @TestMethodOrder(MethodOrderer.MethodName.class)
@Sql({ "schema.sql", "data.sql" }) @Sql({ "schema.sql", "data.sql" })
@DirtiesContext @DirtiesContext
class TransactionalSqlScriptsTests extends AbstractTransactionalTests { class TransactionalSqlScriptsTests extends AbstractTransactionalTests {

View File

@@ -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"); * 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.
@@ -44,7 +44,7 @@ import static org.assertj.core.api.Assertions.assertThat;
@SpringJUnitConfig @SpringJUnitConfig
@Transactional @Transactional
@DirtiesContext(classMode = ClassMode.AFTER_CLASS) @DirtiesContext(classMode = ClassMode.AFTER_CLASS)
@TestMethodOrder(MethodOrderer.Alphanumeric.class) @TestMethodOrder(MethodOrderer.MethodName.class)
abstract class AbstractEjbTxDaoTests { abstract class AbstractEjbTxDaoTests {
protected static final String TEST_NAME = "test-name"; protected static final String TEST_NAME = "test-name";

View File

@@ -57,7 +57,7 @@ import static org.mockito.BDDMockito.given;
@ContextConfiguration(classes = JavaConfigTests.RootConfig.class), @ContextConfiguration(classes = JavaConfigTests.RootConfig.class),
@ContextConfiguration(classes = JavaConfigTests.WebConfig.class) @ContextConfiguration(classes = JavaConfigTests.WebConfig.class)
}) })
public class JavaConfigTests { class JavaConfigTests {
@Autowired @Autowired
private WebApplicationContext wac; private WebApplicationContext wac;
@@ -65,21 +65,18 @@ public class JavaConfigTests {
@Autowired @Autowired
private PersonDao personDao; private PersonDao personDao;
@Autowired
private PersonController personController;
private WebTestClient testClient; private WebTestClient testClient;
@BeforeEach @BeforeEach
public void setup() { void setup() {
this.testClient = MockMvcWebTestClient.bindToApplicationContext(this.wac).build(); this.testClient = MockMvcWebTestClient.bindToApplicationContext(this.wac).build();
given(this.personDao.getPerson(5L)).willReturn(new Person("Joe")); given(this.personDao.getPerson(5L)).willReturn(new Person("Joe"));
} }
@Test @Test
public void person() { void person() {
testClient.get().uri("/person/5") testClient.get().uri("/person/5")
.accept(MediaType.APPLICATION_JSON) .accept(MediaType.APPLICATION_JSON)
.exchange() .exchange()
@@ -88,7 +85,7 @@ public class JavaConfigTests {
} }
@Test @Test
public void tilesDefinitions() { void tilesDefinitions() {
testClient.get().uri("/") testClient.get().uri("/")
.exchange() .exchange()
.expectStatus().isOk() .expectStatus().isOk()
@@ -100,7 +97,7 @@ public class JavaConfigTests {
static class RootConfig { static class RootConfig {
@Bean @Bean
public PersonDao personDao() { PersonDao personDao() {
return Mockito.mock(PersonDao.class); return Mockito.mock(PersonDao.class);
} }
} }
@@ -113,7 +110,7 @@ public class JavaConfigTests {
private RootConfig rootConfig; private RootConfig rootConfig;
@Bean @Bean
public PersonController personController() { PersonController personController() {
return new PersonController(this.rootConfig.personDao()); return new PersonController(this.rootConfig.personDao());
} }
@@ -138,7 +135,7 @@ public class JavaConfigTests {
} }
@Bean @Bean
public TilesConfigurer tilesConfigurer() { TilesConfigurer tilesConfigurer() {
TilesConfigurer configurer = new TilesConfigurer(); TilesConfigurer configurer = new TilesConfigurer();
configurer.setDefinitions("/WEB-INF/**/tiles.xml"); configurer.setDefinitions("/WEB-INF/**/tiles.xml");
return configurer; return configurer;

View File

@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.test.web.servlet.samples.client.standalone; package org.springframework.test.web.servlet.samples.client.standalone;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
@@ -33,7 +34,7 @@ import static org.hamcrest.Matchers.equalTo;
* *
* @author Rossen Stoyanchev * @author Rossen Stoyanchev
*/ */
public class ResponseBodyTests { class ResponseBodyTests {
@Test @Test
void json() { void json() {
@@ -56,13 +57,14 @@ public class ResponseBodyTests {
private static class PersonController { private static class PersonController {
@GetMapping("/person/{name}") @GetMapping("/person/{name}")
public Person get(@PathVariable String name) { Person get(@PathVariable String name) {
Person person = new Person(name); Person person = new Person(name);
person.setAge(42); person.setAge(42);
return person; return person;
} }
} }
@SuppressWarnings("unused")
private static class Person { private static class Person {
@NotNull @NotNull

View File

@@ -38,10 +38,10 @@ import static org.springframework.test.web.servlet.setup.MockMvcBuilders.standal
* @author Rossen Stoyanchev * @author Rossen Stoyanchev
* @author Sam Brannen * @author Sam Brannen
*/ */
public class ResponseBodyTests { class ResponseBodyTests {
@Test @Test
public void json() throws Exception { void json() throws Exception {
standaloneSetup(new PersonController()).build() standaloneSetup(new PersonController()).build()
.perform(get("/person/Lee").accept(MediaType.APPLICATION_JSON)) .perform(get("/person/Lee").accept(MediaType.APPLICATION_JSON))
.andExpect(status().isOk()) .andExpect(status().isOk())
@@ -60,7 +60,7 @@ public class ResponseBodyTests {
private static class PersonController { private static class PersonController {
@GetMapping("/person/{name}") @GetMapping("/person/{name}")
public Person get(@PathVariable String name) { Person get(@PathVariable String name) {
Person person = new Person(name); Person person = new Person(name);
person.setAge(42); person.setAge(42);
return person; return person;