title: My Unit Test case fails with Assertion Error
body: <p>Setup:  spring-boot 1.4.3.RELEASE
  Java 1.8</p>
  
  <p>I've written three test cases against my BluecostRestController.java (code below).  The tests for the following URLs worked fine:
  GET /bluecost/sscdata
  GET /bluecost/sscdata/sergio</p>
  
  <p>Now I'm trying to write a test case for the POST /bluecost/sscdata/ and I am getting the following Assertion Exception:</p>
  
  <pre><code>java.lang.AssertionError: Status expected:&lt;201&gt; but was:&lt;400&gt;
      at org.springframework.test.util.AssertionErrors.fail(AssertionErrors.java:54)
      at org.springframework.test.util.AssertionErrors.assertEquals(AssertionErrors.java:81)
      at org.springframework.test.web.servlet.result.StatusResultMatchers$10.match(StatusResultMatchers.java:665)
      at org.springframework.test.web.servlet.MockMvc$1.andExpect(MockMvc.java:171)
      at com.ibm.cio.cloud.cost.spreadsheet.controller.UTBlueCostRestControllerTests.testAddingSpreadsheetUpload(UTBlueCostRestControllerTests.java:198)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:498)
      at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
      at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
      at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
      at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
      at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75)
      at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86)
      at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84)
      at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
      at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:252)
      at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:94)
      at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
      at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
      at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
      at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
      at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
      at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
      at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
      at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
      at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:191)
      at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
      at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:538)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:760)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:460)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:206)
  </code></pre>
  
  <p>For some reason it's not finding this path: /bluecost/sscdata with that object.   Here is my test class:</p>
  
  <pre><code>@RunWith(SpringRunner.class)    @WebMvcTest(com.ibm.cio.cloud.cost.spreadsheet.rest.controller.BlueCostRestController.class)   
      public class UTBlueCostRestControllerTests extends UTBlueCostRestControllerParent {
  
          private static final long CREATED_SSCDATA_ID = 400l;
  
          @Test    
          public void testAddingSpreadsheetUpload() throws Exception {
  
              BluecostSSCData mockSSCData = new BluecostSSCData(
                      CREATED_SSCDATA_ID,
                      200l,
                      "chargeType-D7",
                      "controlGroup-293D",
                      "TEXACO",
                      "TestUser"
                      );
  
              String sscData = "{\r\n" + 
                      "   \"sscdataid\": \"400\",\r\n" + 
                      "   \"processGroupId\": \"200\",\r\n" + 
                      "   \"chargeTypeCd\": \"chargeType-D7\",\r\n" + 
                      "   \"controlGroupCd\": \"controlGroup-293D\",\r\n" + 
                      "   \"accountId\": \"TEXACO\",\r\n" + 
                      "   \"userId\": \"TestUser\",\r\n" + 
                      "}";
  
              when(blueCostSSCDataService.saveBluecostSSCData(mockSSCData))
                              .thenReturn(mockSSCData);
  
              mvc.perform(MockMvcRequestBuilders
                      .post("/bluecost/sscdata/").content(sscData)
                      .contentType(MediaType.APPLICATION_JSON))
                      .andExpect(status().isCreated())
                      .andExpect(header().string("location",
                              containsString("/bluecost/sscdata/"
                                      + CREATED_SSCDATA_ID)));
  
          }   
  
  This is the Controller Class:
      @RequestMapping("bluecost")
      @RestController
      public class BlueCostRestController {
  
          @Autowired
          BluecostSSCDataService blueCostSSCDataService;
  
          @Autowired
          CostSpreadsheetService costSpreadsheetService;
  
          @Autowired
          BlueCostService blueCostService;
  
          @RequestMapping(value = "/sscdata/", method = RequestMethod.GET)
          public ResponseEntity&lt;List&lt;BluecostSSCData&gt;&gt; getAllBluecostSSCData() {
              List&lt;BluecostSSCData&gt; bluecostSSCDataList = blueCostSSCDataService.getAllBlueCostSSCData();
              if (bluecostSSCDataList.isEmpty()) {
                  return new ResponseEntity(HttpStatus.NO_CONTENT); 
              }
              return new ResponseEntity&lt;List&lt;BluecostSSCData&gt;&gt;(bluecostSSCDataList, HttpStatus.OK);
          }
  
          @RequestMapping(value = "/sscdata/{localField2}", method = RequestMethod.GET)
          public ResponseEntity&lt;?&gt; findSSCDataByUploader(@PathVariable("localField2") String localField2) {
  
              List&lt;BluecostSSCData&gt; bluecostSSCDataList = blueCostSSCDataService.findBluecostSSCDataByUploader(localField2);
              if (bluecostSSCDataList.size() == 0) {
                  return new ResponseEntity(HttpStatus.NOT_FOUND);
              }
              return new ResponseEntity&lt;List&lt;BluecostSSCData&gt;&gt;(bluecostSSCDataList, HttpStatus.OK);
          }
  
          @RequestMapping(value = "/sscdata/", method = RequestMethod.POST)
          public ResponseEntity&lt;?&gt; createBluecostSSCData(@RequestBody BluecostSSCData sscdata) {
  
              BluecostSSCData createdSSCData = blueCostSSCDataService.saveBluecostSSCData(sscdata);
  
              if (createdSSCData == null)
                  return ResponseEntity.noContent().build();
  
              URI location = ServletUriComponentsBuilder
                      .fromCurrentRequest().path("/{id}")
                      .buildAndExpand(createdSSCData.getSscdataid())
                      .toUri();
  
              return ResponseEntity.created(location).build();
  
          }
  </code></pre>