title: java.lang.AssertionError: Status expected:<200> but was:<400> for Spring Boot Rest Controller Patch request
body: <p>Below is my controller (SalesOrderController.Java) and JUnit Test (SalesOrderControllerTest.Java)</p>
  
  <pre><code>@RestController
  </code></pre>
  
  <p>public class SalesOrderController extends BaseController {</p>
  
  <pre><code>/** The Constant LOGGER. */
  private static final Logger LOGGER = LoggerFactory.getLogger(SalesOrderController.class);
  
  /** The sales order service. */
  @Autowired
  private ISalesOrderService salesOrderService;
  
  @CrossOrigin
  @RequestMapping(value = "/issuers/{issuerId}/reassign-sales-orders", method = RequestMethod.PATCH, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
  public BaseResponse reassignSalesOrder(@PathVariable("issuerId") final Long pIssuerId,
          @RequestBody @Valid final ReassignSalesOrderRequest pReassignSalesOrderRequest) {
      LOGGER.info("Reassigning sales orders of issuer:" + pIssuerId);
      return salesOrderService.reassignSalesOrder(pIssuerId, pReassignSalesOrderRequest);
  }
  </code></pre>
  
  <p>}</p>
  
  <p>and below is my Junit for above controller</p>
  
  <pre><code>@RunWith(MockitoJUnitRunner.class)
  </code></pre>
  
  <p>public class SalesOrderControllerTest extends AbstractBaseControllerTest {</p>
  
  <pre><code>/** The sales order service. */
  @Mock
  private ISalesOrderService salesOrderService;
  
  /** The sales order controller. */
  @InjectMocks
  private SalesOrderController salesOrderController;
  
  @Before
  public void setUp() throws Exception {
      mockMvc = MockMvcBuilders.standaloneSetup(salesOrderController).build();
  }
  
  @Test
  public void testReassignSalesOrder() throws Exception {
      ReassignSalesOrderRequest lSalesOrderUpdateRequest = new ReassignSalesOrderRequest();
      lSalesOrderUpdateRequest.setRedirectOption("Satellite");
      lSalesOrderUpdateRequest.setSatelliteId(200L);
      lSalesOrderUpdateRequest.setSalesOrderIds(Collections.singletonList(1L));
      when(salesOrderService.reassignSalesOrder(100L, lSalesOrderUpdateRequest)).thenReturn(new BaseResponse());
      ObjectMapper mapper = new ObjectMapper();
      mockMvc.perform(patch("/api/issuers/100/reassign-sales-orders")
              .contentType(MediaType.APPLICATION_JSON_UTF8).accept(MediaType.APPLICATION_JSON_UTF8)
              .content(mapper.writeValueAsString(lSalesOrderUpdateRequest)))
              .andExpect(status().isOk());
      verify(salesOrderService).reassignSalesOrder(100L, lSalesOrderUpdateRequest);
  }
  </code></pre>
  
  <p>}</p>
  
  <pre><code>java.lang.AssertionError: Status expected:&lt;200&gt; but was:&lt;400&gt;
  at org.springframework.test.util.AssertionErrors.fail(AssertionErrors.java:55)
  at org.springframework.test.util.AssertionErrors.assertEquals(AssertionErrors.java:82)
  at org.springframework.test.web.servlet.result.StatusResultMatchers.lambda$matcher$9(StatusResultMatchers.java:617)
  at org.springframework.test.web.servlet.MockMvc$1.andExpect(MockMvc.java:178)
  at com.gide.csri.cui.controller.SalesOrderControllerTest.testReassignSalesOrder(SalesOrderControllerTest.java:88)
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
  at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
  at java.lang.reflect.Method.invoke(Unknown Source)
  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.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
  at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
  at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
  at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
  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.junit.runners.ParentRunner.run(ParentRunner.java:363)
  at org.mockito.internal.runners.DefaultInternalRunner$1.run(DefaultInternalRunner.java:79)
  at org.mockito.internal.runners.DefaultInternalRunner.run(DefaultInternalRunner.java:85)
  at org.mockito.internal.runners.StrictRunner.run(StrictRunner.java:39)
  at org.mockito.junit.MockitoJUnitRunner.run(MockitoJUnitRunner.java:163)
  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>so why i am getting this error what's wrong in my code ?</p>