title: How I have to adjust the json path so that my test is successful?
body: <pre class="lang-java prettyprint-override"><code>@DisplayName(&quot;test getCarportById(), Status OK&quot;)
  @Test
  void testGetCarportLocationById() throws Exception {
  
      // given
      final String externalId = &quot;123L&quot;;
  
      final CarportLocation carportLocation = CarportLocationMockHelper.createCarportLocationByIdDTO(externalId);
  
      given(carportService.getCarportLocationToId(externalId.toString())).willReturn(carportLocation);
  
      // when
  
      final MvcResult mvcResult = this.mockMvc.perform(getRequestBuilderMockCarportLocationsById(externalId.toString()))
                                              .andExpect(status().isOk())
                                              .andDo(print())
                                              .andExpect(content().contentType(&quot;application/json&quot;))
                                              .andExpect(resultMatcherOK)
                                              .andExpect(MockMvcResultMatchers.jsonPath(&quot;$.externalId&quot;)
                                                                              .value(CarportLocation.getExternalId()))
                                              .andReturn();
  
      // then
  
      assertEquals(&quot;application/json&quot;, mvcResult.getResponse()
                                                .getContentType());
  }
  </code></pre>
  <pre class="lang-java prettyprint-override"><code>public static CarportLocation createCarportLocationByIdDTO(String externalId) {
  
      finalCarportLocation carportLocation = new CarportLocation();
      carportLocation.setId(123456L);
      carportLocation.setExternalId(externalId);
      carportLocation.setCarportName(&quot;Carport1&quot;);
      carportLocation.setLocX(12.4534);
      carportLocation.setLocY(19.5678);
      carportLocation.setLocZ(25.0);
  
      return carportLocation;
  }
  </code></pre>
  <p>This is the expression I print out by .andDo(print()):</p>
  <pre class="lang-none prettyprint-override"><code>MockHttpServletRequest:
        HTTP Method = GET
        Request URI = /carport/carports/filter
         Parameters = {carportNameAndExternalId=[123L]}
            Headers = []
               Body = &lt;no character encoding set&gt;
      Session Attrs = {}
  
  Handler:
               Type = controller.CarportController
             Method = controller.CarportController#_getCarportLocationsByIdAndName(String)
  
  Async:
      Async started = false
       Async result = null
  
  Resolved Exception:
               Type = null
  
  ModelAndView:
          View name = null
               View = null
              Model = null
  
  FlashMap:
         Attributes = null
  
  MockHttpServletResponse:
             Status = 200
      Error message = null
            Headers = [Content-Type:&quot;application/json&quot;]
       Content type = application/json
               Body = []
      Forwarded URL = null
     Redirected URL = null
            Cookies = []
  </code></pre>
  <p>Only unfortunately my JUnit test fails and I am not sure why.</p>
  <blockquote>
  <p>java.lang.AssertionError: No value at JSON path &quot;$.externalId&quot;</p>
  </blockquote>
  <p>Of course, I have also already searched for the problem and came across the following SO question: <a href="https://stackoverflow.com/questions/33659684/assertion-error-no-value-for-json-path-in-junit-test">Assertion error: No value for JSON Path in JUnit test</a></p>
  <p>only unfortunately a &quot;$[1].externalId&quot; did not help me. The <code>andDo(print())</code> method has also therefore but can't really work with the output.
  Does anyone know how I have to adjust the json path so that my test is successful?</p>