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)
.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

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");
* 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;

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");
* 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 {

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");
* 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 {

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");
* 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";

View File

@ -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;

View File

@ -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

View File

@ -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;