mercredi 22 juillet 2020

JMockit With Chain Methods

I am having difficulty understanding how to properly mock chain methods with Jmockit

so here is an example of a chain method i would want to test

  protected void configure(HttpSecurity http) throws Exception {
    http
        .authorizeRequests().anyRequest().permitAll()
        .and()
        .httpBasic().disable()
        .csrf().disable();
  }

My undestanding currently is to manually specify each method in the Expectation and return a mock. Then do this for each step. Like below

new Expecations(){
http.authorizeRequest()
result = mockedRequests;

mockedRequest.anyRequest()
results = mockedAnyRequest;

//etc


}

My question is there a better way of doing this? I feel like this is alot of extra code for a simple test. P.S This is for JMockit 1.8

Aucun commentaire:

Enregistrer un commentaire