Polish contribution
See gh-23141
This commit is contained in:
@@ -24,19 +24,8 @@ package org.springframework.test.context.junit.jupiter.comics;
|
||||
*/
|
||||
public class Person extends Character {
|
||||
|
||||
private final long id;
|
||||
|
||||
public Person(String name) {
|
||||
this(0, name);
|
||||
}
|
||||
|
||||
public Person(long id, String name) {
|
||||
super(name);
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -67,20 +67,6 @@ class MultipleWebRequestsSpringExtensionTests {
|
||||
.andExpect(jsonPath("$.name", is("Dilbert")));
|
||||
}
|
||||
|
||||
@Test
|
||||
void getPerson1() throws Exception {
|
||||
// Tests for #23121 (Target type in jsonPath method of MockMvcResultMatchers) coercing into Long
|
||||
this.mockMvc.perform(get("/person/1").accept(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath("$.id", Long.class, is(1L)));
|
||||
}
|
||||
|
||||
@Test
|
||||
void getPerson2() throws Exception {
|
||||
// Tests for #23121 (Target type in jsonPath method of MockMvcResultMatchers) coercing into String
|
||||
this.mockMvc.perform(get("/person/2").accept(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath("$.id", String.class, is("2")));
|
||||
}
|
||||
|
||||
@Test
|
||||
void getPerson99() throws Exception {
|
||||
this.mockMvc.perform(get("/person/99").accept(MediaType.APPLICATION_JSON))
|
||||
|
||||
@@ -31,9 +31,9 @@ class PersonController {
|
||||
@GetMapping("/person/{id}")
|
||||
Person getPerson(@PathVariable long id) {
|
||||
if (id == 42) {
|
||||
return new Person(id, "Dilbert");
|
||||
return new Person("Dilbert");
|
||||
}
|
||||
return new Person(id, "Wally");
|
||||
return new Person("Wally");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -16,15 +16,16 @@
|
||||
|
||||
package org.springframework.test.web.servlet.samples.standalone;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.test.web.Person;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
|
||||
@@ -35,6 +36,7 @@ import static org.springframework.test.web.servlet.setup.MockMvcBuilders.standal
|
||||
* Response written from {@code @ResponseBody} method.
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
* @author Sam Brannen
|
||||
*/
|
||||
public class ResponseBodyTests {
|
||||
|
||||
@@ -44,17 +46,49 @@ public class ResponseBodyTests {
|
||||
.perform(get("/person/Lee").accept(MediaType.APPLICATION_JSON))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentType("application/json"))
|
||||
.andExpect(jsonPath("$.name").value("Lee"));
|
||||
.andExpect(jsonPath("$.name").value("Lee"))
|
||||
.andExpect(jsonPath("$.age").value(42))
|
||||
.andExpect(jsonPath("$.age").value(42.0f))
|
||||
.andExpect(jsonPath("$.age").value(equalTo(42)))
|
||||
.andExpect(jsonPath("$.age").value(equalTo(42.0f), Float.class))
|
||||
.andExpect(jsonPath("$.age", equalTo(42)))
|
||||
.andExpect(jsonPath("$.age", equalTo(42.0f), Float.class));
|
||||
}
|
||||
|
||||
|
||||
@Controller
|
||||
private class PersonController {
|
||||
@RestController
|
||||
private static class PersonController {
|
||||
|
||||
@RequestMapping(value="/person/{name}")
|
||||
@ResponseBody
|
||||
@GetMapping("/person/{name}")
|
||||
public Person get(@PathVariable String name) {
|
||||
return new Person(name);
|
||||
Person person = new Person(name);
|
||||
person.setAge(42);
|
||||
return person;
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private static class Person {
|
||||
|
||||
@NotNull
|
||||
private final String name;
|
||||
|
||||
private int age;
|
||||
|
||||
public Person(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public int getAge() {
|
||||
return this.age;
|
||||
}
|
||||
|
||||
public void setAge(int age) {
|
||||
this.age = age;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user