Review Comments

This commit is contained in:
Niket Agrawal 2023-10-14 21:55:00 +05:30
parent 8999b501c9
commit 4e0b27b017
2 changed files with 5 additions and 25 deletions

View File

@ -36,18 +36,15 @@ class ValidationControllerUnitTest {
@Test
void whenNullInputForBooleanField_thenHttpBadRequestAsHttpResponse() throws Exception {
String postBody = "{\"boolField\":null,\"trueField\":true,\"falseField\":false,\"boolStringVar\":\"+\"}";
mockMvc.perform(post("/validateBoolean").contentType("application/json")
.content(postBody))
.andExpect(status().isBadRequest());
}
@Test
void whenInvalidInputForTrueBooleanField_thenErrorResponse() throws Exception {
String postBody = "{\"boolField\":true,\"trueField\":false,\"falseField\":false,\"boolStringVar\":\"+\"}";
String output = mockMvc.perform(post("/validateBoolean").contentType("application/json")
@ -61,7 +58,6 @@ class ValidationControllerUnitTest {
@Test
void whenInvalidInputForFalseBooleanField_thenErrorResponse() throws Exception {
String postBody = "{\"boolField\":true,\"trueField\":true,\"falseField\":true,\"boolStringVar\":\"+\"}";
String output = mockMvc.perform(post("/validateBoolean").contentType("application/json")
@ -75,7 +71,6 @@ class ValidationControllerUnitTest {
@Test
void whenInvalidBooleanFromJson_thenErrorResponse() throws Exception {
String postBody = "{\"boolField\":true,\"trueField\":true,\"falseField\":false,\"boolStringVar\":\"plus\"}";
String output = mockMvc.perform(post("/validateBoolean").contentType("application/json")
@ -85,12 +80,10 @@ class ValidationControllerUnitTest {
.getContentAsString();
assertEquals("Only values accepted as Boolean are + and -", output);
}
@Test
void whenAllBooleanFieldsValid_thenCorrectResponse() throws Exception {
String postBody = "{\"boolField\":true,\"trueField\":true,\"falseField\":false,\"boolStringVar\":\"+\"}";
String output = mockMvc.perform(post("/validateBoolean").contentType("application/json")
@ -100,30 +93,25 @@ class ValidationControllerUnitTest {
.getContentAsString();
assertEquals("BooleanObject is valid", output);
}
@Test
void givenAllBooleanFieldsValid_whenServiceValidationFails_thenErrorResponse() throws Exception {
mockMvc.perform(post("/validateBooleanAtService").contentType("application/json"))
.andExpect(status().isInternalServerError());
}
@Test
void whenNullInputForTrueBooleanField_thenCorrectResponse() throws Exception {
String postBody = "{\"boolField\":true,\"trueField\":null,\"falseField\":false,\"boolStringVar\":\"+\"}";
mockMvc.perform(post("/validateBoolean").contentType("application/json")
.content(postBody))
.andExpect(status().isOk());
}
@Test
void whenNullInputForFalseBooleanField_thenHttpBadRequestAsHttpResponse() throws Exception {
String postBody = "{\"boolField\":true,\"trueField\":true,\"falseField\":null,\"boolStringVar\":\"+\"}";
String output = mockMvc.perform(post("/validateBoolean").contentType("application/json")
@ -133,6 +121,5 @@ class ValidationControllerUnitTest {
.getContentAsString();
assertEquals("falseField cannot be null", output);
}
}

View File

@ -8,21 +8,14 @@ class BooleanUnitTest {
@Test
void givenInputAsString_whenStringToBoolean_thenValidBooleanConversion() {
Boolean trueVar = Boolean.valueOf("TRUE");
Boolean falseVar = Boolean.valueOf("false");
Boolean parsedVar = Boolean.parseBoolean("True");
assertEquals(Boolean.TRUE, trueVar);
assertEquals(Boolean.FALSE, falseVar);
assertEquals(Boolean.TRUE, parsedVar);
assertEquals(Boolean.TRUE, Boolean.valueOf("TRUE"));
assertEquals(Boolean.FALSE, Boolean.valueOf("false"));
assertEquals(Boolean.TRUE, Boolean.parseBoolean("True"));
}
@Test
void givenInputAsboolean_whenbooleanToBoolean_thenValidBooleanConversion() {
Boolean trueVar = Boolean.valueOf(true);
Boolean falseVar = Boolean.valueOf(false);
assertEquals(Boolean.TRUE, trueVar);
assertEquals(Boolean.FALSE, falseVar);
assertEquals(Boolean.TRUE, Boolean.valueOf(true));
assertEquals(Boolean.FALSE, Boolean.valueOf(false));
}
}