title: Testing using Junit and Mock put request
body: <p>I'am trying to do a test on the put request and it gives me the null Pointer error just in this type of request I don't kow why please could someone help me , here is my controller :</p>
  
  <pre><code>@PutMapping ("/update/{id}")
      public Entreprise updateEntreprise(@PathVariable Long id,@RequestBody Entreprise entreprise ) {
         Entreprise e=entrepriseService.getEntreprise(id);
         e.setDescription(entreprise.getDescription());
         e.setNom(entreprise.getNom());
         e.setNumberCertificats(entreprise.getNumberCertificats());
         e.setNumberClients(entreprise.getNumberClients());
         e.setNumberYears(entreprise.getNumberYears());
         e.setNumberCollaborators(entreprise.getNumberCollaborators());
         entrepriseService.updateEntreprise(e);
          return e;
      }
  </code></pre>
  
  <p>and for the test method :</p>
  
  <pre><code>@RunWith(SpringRunner.class)
  @WebMvcTest(value = EntrepriseController.class, secure = false)
  public class TestsEntrepriseController {
      @Autowired
      private MockMvc mockMvc;
  
  
      @MockBean
      EntrepriseService entrepriseService;
   @Test
      public void givenEntrepriseURIWithPut_whenMockMVC_thenVerifyResponse() throws Exception {
          Entreprise entreprise = new Entreprise();
          entreprise.setId(1);
          entreprise.setNom("oumaima");
          entreprise.setDescription("description");
          entreprise.setNumberCertificats(12);
          entreprise.setNumberClients(15);
          entreprise.setNumberCollaborators(20);
          entreprise.setNumberYears(12);
          Services services = new Services();
          services.setNom("cloud");
          services.setId(1);
          Set&lt;Services&gt; allServices =  new HashSet&lt;&gt;(Arrays. asList(services));
          entreprise.setServices(allServices);
          mockMvc.perform(put("/entreprise/update/1")
                  .contentType(IntegrationTestUtil.APPLICATION_JSON_UTF8)
                  .content(IntegrationTestUtil.convertObjectToJsonBytes(entreprise))
          )
                  .andExpect(status().isBadRequest())
                  .andExpect(content().string("{\"fieldErrors\":[{\"path\":\"title\",\"message\":\"The title cannot be empty.\"}]}"));
  
      }
  }
  </code></pre>