From 733c7e76b96ba59962dc5032ae6dd4f0de5fca1c Mon Sep 17 00:00:00 2001 From: Muhammad Abdullah Azam Khan Date: Sun, 17 Oct 2021 00:52:40 +0400 Subject: [PATCH] Resolving build failure cases --- .../com/baeldung/unsupportedmediatype/User.java | 4 ++++ .../ApplicationUnitTest.java} | 15 +++++++-------- 2 files changed, 11 insertions(+), 8 deletions(-) rename spring-boot-rest-2/src/test/java/com/baeldung/{unsupportedmedia/ApplicationTest.java => unsupportedmediatype/ApplicationUnitTest.java} (84%) diff --git a/spring-boot-rest-2/src/main/java/com/baeldung/unsupportedmediatype/User.java b/spring-boot-rest-2/src/main/java/com/baeldung/unsupportedmediatype/User.java index 74a6f4383b..5f5f2a972c 100644 --- a/spring-boot-rest-2/src/main/java/com/baeldung/unsupportedmediatype/User.java +++ b/spring-boot-rest-2/src/main/java/com/baeldung/unsupportedmediatype/User.java @@ -10,6 +10,10 @@ public class User implements Serializable { private Integer age; private String address; + public User(){ + + } + public User(Integer id, String name, Integer age, String address){ this.id = id; this.name = name; diff --git a/spring-boot-rest-2/src/test/java/com/baeldung/unsupportedmedia/ApplicationTest.java b/spring-boot-rest-2/src/test/java/com/baeldung/unsupportedmediatype/ApplicationUnitTest.java similarity index 84% rename from spring-boot-rest-2/src/test/java/com/baeldung/unsupportedmedia/ApplicationTest.java rename to spring-boot-rest-2/src/test/java/com/baeldung/unsupportedmediatype/ApplicationUnitTest.java index e5c56d0adc..a84388f750 100644 --- a/spring-boot-rest-2/src/test/java/com/baeldung/unsupportedmedia/ApplicationTest.java +++ b/spring-boot-rest-2/src/test/java/com/baeldung/unsupportedmediatype/ApplicationUnitTest.java @@ -1,7 +1,6 @@ -package com.baeldung.unsupportedmedia; +package com.baeldung.unsupportedmediatype; -import com.baeldung.unsupportedmediatype.UserController; -import org.junit.jupiter.api.Test; +import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; @@ -14,12 +13,12 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers. @RunWith(SpringRunner.class) @WebMvcTest(UserController.class) -public class ApplicationTest { +public class ApplicationUnitTest { @Autowired private MockMvc mockMvc; @Test - void JsonTestCase() throws Exception { + public void JsonTestCase() throws Exception { mockMvc.perform(MockMvcRequestBuilders.post("/user/") .contentType(MediaType.APPLICATION_JSON_VALUE) .content("{\n" + @@ -31,7 +30,7 @@ public class ApplicationTest { } @Test - void JsonFailTestCase() throws Exception {// Because no content-type added + public void JsonFailTestCase() throws Exception {// Because no content-type added mockMvc.perform(MockMvcRequestBuilders.post("/user/") .content("{\n" + " \"name\": \"Andy\",\n" + @@ -42,7 +41,7 @@ public class ApplicationTest { } @Test - void XmlTestCase() throws Exception { + public void XmlTestCase() throws Exception { mockMvc.perform(MockMvcRequestBuilders.post("/user/") .contentType(MediaType.APPLICATION_XML_VALUE) .content("Andy1
Hello world
")) @@ -50,7 +49,7 @@ public class ApplicationTest { } @Test - void StringTestCase() throws Exception { + public void StringFailTestCase() throws Exception { // Because content-type is not supported mockMvc.perform(MockMvcRequestBuilders.post("/user/") .contentType(MediaType.TEXT_PLAIN_VALUE) .content("Andy1
Hello world
"))