java - Bad status returned from Mockito test -


i test example method controller

@getmapping("/checkusernameatregistering") public httpentity<boolean> checkusernameatregistering(@requestparam string username) {             return responseentity.ok().body(!userservice.existsbyusername(username)); } 

which returns status ok.

i created test in mockito

public class checkuserdatarestcontrollertest {  @mock private userservice userservice;  @injectmocks private checkuserdatarestcontroller checkuserdatarestcontroller;  private mockmvc mockmvc;  @before public void setup() {     mockitoannotations.initmocks(this);      mockmvc = mockmvcbuilders.standalonesetup(checkuserdatarestcontroller).build(); }  @test public void testcheckusernameatregistering() throws exception {     mockmvc             .perform(get("/checkusernameatregistering")             .param("username", "jonki97"))             .andexpect(status().isok()); } } 

i expect status ok. know makes no sense, want test done correctly. however, after successfulfully completed request discarded

java.lang.assertionerror: status  expected :200 actual   :404  <click see difference>      @ org.springframework.test.util.assertionerrors.fail(assertionerrors.java:54)         ... 


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

reflection - How to access the object-members of an object declaration in kotlin -

php - Doctrine Query Builder Error on Join: [Syntax Error] line 0, col 87: Error: Expected Literal, got 'JOIN' -