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
Post a Comment