This repository was archived by the owner on Dec 15, 2021. It is now read-only.
  
  
  
  
    
    
    
      
    
  
  
    
File tree Expand file tree Collapse file tree 2 files changed +22
-5
lines changed 
main/java/org/springframework/issues 
test/java/org/springframework/issues Expand file tree Collapse file tree 2 files changed +22
-5
lines changed Original file line number Diff line number Diff line change @@ -15,8 +15,13 @@ public void initBinder(WebDataBinder binder) {
1515        binder .addValidators (new  PayloadValidator ());
1616    }
1717
18-     @ RequestMapping ("/" )
19-     public  String  emptyBody (@ RequestBody  @ Validated  Payload  payload ) {
18+     @ RequestMapping ("/mandatory-body" )
19+     public  String  mandatoryBody (@ RequestBody  @ Validated  Payload  payload ) {
20+         return  "hello" ;
21+     }
22+ 
23+     @ RequestMapping ("/optional-body" )
24+     public  String  optionalBody (@ RequestBody (required  = false ) @ Validated  Payload  payload ) {
2025        return  "hello" ;
2126    }
2227}
Original file line number Diff line number Diff line change @@ -24,19 +24,31 @@ public void prepare() {
2424
2525    @ Test 
2626    public  void  shouldSend200WithValidPayload () throws  Exception  {
27-         mockMvc .perform (post ("/" ).content ("{\" message\" :\" spring\" }" ).contentType (MediaType .APPLICATION_JSON ))
27+         mockMvc .perform (post ("/mandatory-body " ).content ("{\" message\" :\" spring\" }" ).contentType (MediaType .APPLICATION_JSON ))
2828                .andExpect (status ().isOk ())
2929                .andExpect (content ().string ("\" hello\" " ));
3030    }
3131
3232    @ Test 
3333    public  void  shouldSend400WithEmptyBody () throws  Exception  {
34-         mockMvc .perform (post ("/" )).andExpect (status ().isBadRequest ());
34+         mockMvc .perform (post ("/mandatory-body " )).andExpect (status ().isBadRequest ());
3535    }
3636
3737    @ Test 
3838    public  void  shouldSend400WithEmptyJsonObject () throws  Exception  {
39-         mockMvc .perform (post ("/" ).content ("{}" ).contentType (MediaType .APPLICATION_JSON ))
39+         mockMvc .perform (post ("/mandatory-body " ).content ("{}" ).contentType (MediaType .APPLICATION_JSON ))
4040                .andExpect (status ().isBadRequest ());
4141    }
42+ 
43+     @ Test 
44+     public  void  shouldSend400WithNullJsonObject () throws  Exception  {
45+         mockMvc .perform (post ("/mandatory-body" ).content ("null" ).contentType (MediaType .APPLICATION_JSON ))
46+                 .andExpect (status ().isBadRequest ());
47+     }
48+ 
49+     @ Test 
50+     public  void  shouldSend200WithNullJsonObject () throws  Exception  {
51+         mockMvc .perform (post ("/optional-body" ).content ("null" ).contentType (MediaType .APPLICATION_JSON ))
52+                 .andExpect (status ().isOk ());
53+     }
4254}
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments