title: Junit Test case : java.lang.exception: json can not be null or empty
body: <p>I am trying to write Test case for controller using <code>JUnit</code> and <code>mockito</code>.  But I am getting error as JSON can not be null or empty. can any one please tell me what I m doing wrong?</p>
  
  <p><strong>DepartmentController</strong></p>
  
  <pre><code>@RestController
  @RequestMapping("/api.spacestudy.com/SpaceStudy")
  public class DepartmentController {
  
      @Autowired
      DepartmentService depService;
  
      @GetMapping("/Control/SearchFilter/loadDepartments")
      public ResponseEntity&lt;Set&lt;Department&gt;&gt; findDepName() {
  
          Set&lt;Department&gt; depname = depService.findDepName();
          return ResponseEntity.ok(depname);
      }
  </code></pre>
  
  <p><strong>DepartmentControllerTest</strong></p>
  
  <pre><code>@RunWith(SpringJUnit4ClassRunner.class)
  public class DepartmentControllerTest {
  
      private MockMvc mockMvc;
  
     @Mock
     public DepartmentService depService;  
  
     @InjectMocks
     DepartmentController departmentController;
  
     @Before
      public void setup() throws Exception    {
          mockMvc = MockMvcBuilders.standaloneSetup(departmentController).build(); 
      }
      @Test(timeout = 10000)
         public void findDepNameTest() throws Exception
         {
             Department dep = new Department();
             dep.setsDeptName("ABC");
  
             Set&lt;Department&gt; department = new  HashSet&lt;Department&gt;();
             department.add(dep);
  
             Mockito.when(depService.findDepName()).thenReturn(department);
  
          mockMvc.perform(get("/api.spacestudy.com/SpaceStudy/LoadDept").accept(MediaType.APPLICATION_JSON))
                  .andExpect(status().isOk())
                  .andExpect(jsonPath("$[0].sDeptName" , is("abc")));
  
  
         }
  
      }
  </code></pre>
  
  <p><strong>Failure Trace</strong></p>
  
  <pre><code>java.lang.AssertionError: No value at JSON path "$[0].sDeptName", exception: json can not be null or empty
      at org.springframework.test.util.JsonPathExpectationsHelper.evaluateJsonPath(JsonPathExpectationsHelper.java:245)
      at org.springframework.test.util.JsonPathExpectationsHelper.assertValue(JsonPathExpectationsHelper.java:73)
      at org.springframework.test.web.servlet.result.JsonPathResultMatchers$1.match(JsonPathResultMatchers.java:87)
      at org.springframework.test.web.servlet.MockMvc$1.andExpect(MockMvc.java:171)
      at com.spacestudy.DepartmentControllerTest.findDepNameTest(DepartmentControllerTest.java:76)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at 
  </code></pre>