Review Comments

This commit is contained in:
Niket Agrawal 2023-09-26 18:53:59 +05:30
parent 96ff2a982a
commit 00671fd084
2 changed files with 6 additions and 6 deletions

View File

@ -10,12 +10,12 @@ public class BooleanDeserializer extends JsonDeserializer<Boolean> {
@Override @Override
public Boolean deserialize(JsonParser parser, DeserializationContext context) throws IOException { public Boolean deserialize(JsonParser parser, DeserializationContext context) throws IOException {
String value = parser.getText(); String value = parser.getText();
if (value != null && (value.equals("TRUE") || value.equals("1") || value.equals("+"))) { if (value != null && value.equals("+")) {
return Boolean.TRUE; return Boolean.TRUE;
} else if (value != null && (value.equals("FALSE") || value.equals("0") || value.equals("-"))) { } else if (value != null && value.equals("-")) {
return Boolean.FALSE; return Boolean.FALSE;
} else { } else {
throw new IllegalArgumentException("Only values accepted as Boolean are TRUE, FALSE, +, -, 1 , 0"); throw new IllegalArgumentException("Only values accepted as Boolean are + and -");
} }
} }
} }

View File

@ -84,13 +84,13 @@ class ValidationControllerUnitTest {
.getResponse() .getResponse()
.getContentAsString(); .getContentAsString();
assertEquals("Only values accepted as Boolean are TRUE, FALSE, +, -, 1 , 0", output); assertEquals("Only values accepted as Boolean are + and -", output);
} }
@Test @Test
void testInvalidBooleanFromJson() throws Exception { void testInvalidBooleanFromJson() throws Exception {
String postBody = "{\"boolField\":true,\"trueField\":true,\"falseField\":false,\"boolStringVar\":\"6\"}"; String postBody = "{\"boolField\":true,\"trueField\":true,\"falseField\":false,\"boolStringVar\":\"plus\"}";
String output = mockMvc.perform(post("/validateBoolean").contentType("application/json") String output = mockMvc.perform(post("/validateBoolean").contentType("application/json")
.content(postBody)) .content(postBody))
@ -98,7 +98,7 @@ class ValidationControllerUnitTest {
.getResponse() .getResponse()
.getContentAsString(); .getContentAsString();
assertEquals("Only values accepted as Boolean are TRUE, FALSE, +, -, 1 , 0", output); assertEquals("Only values accepted as Boolean are + and -", output);
} }