Refactoring for better Indentation and Formatting

This commit is contained in:
Muhammad Abdullah Azam Khan 2021-11-05 18:32:19 +04:00
parent 733c7e76b9
commit 9d464b4f45
3 changed files with 26 additions and 25 deletions

View File

@ -6,8 +6,8 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class UnsupportedMediaTypeApplication {
public static void main(String[] args) {
SpringApplication.run(UnsupportedMediaTypeApplication.class, args);
}
public static void main(String[] args) {
SpringApplication.run(UnsupportedMediaTypeApplication.class, args);
}
}

View File

@ -11,10 +11,9 @@ public class User implements Serializable {
private String address;
public User(){
}
public User(Integer id, String name, Integer age, String address){
public User(Integer id, String name, Integer age, String address) {
this.id = id;
this.name = name;
this.age = age;
@ -55,11 +54,13 @@ public class User implements Serializable {
@Override
public String toString() {
return "User{" +
"id=" + id +
", name='" + name + '\'' +
", age=" + age +
", address='" + address + '\'' +
'}';
return "User{"
+ "id=" + id
+ ", name='" + name + '\''
+ ", age=" + age
+ ", address='" + address + '\''
+ '}';
}
}

View File

@ -21,38 +21,38 @@ public class ApplicationUnitTest {
public void JsonTestCase() throws Exception {
mockMvc.perform(MockMvcRequestBuilders.post("/user/")
.contentType(MediaType.APPLICATION_JSON_VALUE)
.content("{\n" +
" \"name\": \"Andy\",\n" +
" \"age\": 1,\n" +
" \"address\": \"Hello world\"\n" +
"}"))
.content( "{\n"
+ " \"name\": \"Andy\",\n"
+ " \"age\": 1,\n"
+ " \"address\": \"Hello world\"\n"
+ "}"))
.andExpect(status().isOk());
}
@Test
public void JsonFailTestCase() throws Exception {// Because no content-type added
mockMvc.perform(MockMvcRequestBuilders.post("/user/")
.content("{\n" +
" \"name\": \"Andy\",\n" +
" \"age\": 1,\n" +
" \"address\": \"Hello world\"\n" +
"}"))
.content( "{\n"
+ " \"name\": \"Andy\",\n"
+ " \"age\": 1,\n"
+ " \"address\": \"Hello world\"\n"
+ "}"))
.andExpect(status().isUnsupportedMediaType());
}
@Test
public void XmlTestCase() throws Exception {
mockMvc.perform(MockMvcRequestBuilders.post("/user/")
.contentType(MediaType.APPLICATION_XML_VALUE)
.content("<user><name>Andy</name><age>1</age><address>Hello world</address></user>"))
.contentType(MediaType.APPLICATION_XML_VALUE)
.content("<user><name>Andy</name><age>1</age><address>Hello world</address></user>"))
.andExpect(status().isOk());
}
@Test
public void StringFailTestCase() throws Exception { // Because content-type is not supported
mockMvc.perform(MockMvcRequestBuilders.post("/user/")
.contentType(MediaType.TEXT_PLAIN_VALUE)
.content("<user><name>Andy</name><age>1</age><address>Hello world</address></user>"))
.contentType(MediaType.TEXT_PLAIN_VALUE)
.content("<user><name>Andy</name><age>1</age><address>Hello world</address></user>"))
.andExpect(status().isUnsupportedMediaType());
}
}