title: How to set up different responses for the same request to MockServer?
body: <p>i'm having an issue when setting up the MockServerClient for multiple responses with the exact same request.</p>
  <p>I read that with expectations with &quot;Times&quot; this might be done, but i coulnd't make it work with my scenario.</p>
  <p>If you call the service with this JSON (twice):</p>
  <pre><code>{
      &quot;id&quot;: 1
  }
  </code></pre>
  <p>The first response should be &quot;passed true&quot;, the second &quot;passed false&quot;</p>
  <p>Response 1:</p>
  <pre><code>{
      &quot;passed&quot;:true
  }
  </code></pre>
  <p>Response 2:</p>
  <pre><code>{
      &quot;passed&quot;:false
  }
  </code></pre>
  <p>I set up the first request, but how do i set the second one?</p>
  <pre><code>import com.nice.project.MyService;
  import com.nice.project.MyPojo;
  import org.mockito.Mock;
  import org.mockserver.integration.ClientAndServer;
  import org.mockserver.matchers.TimeToLive;
  import org.mockserver.matchers.Times;
  import org.mockserver.model.Header;
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.beans.factory.annotation.Value;
  import org.springframework.boot.test.context.SpringBootTest;
  import org.springframework.http.HttpHeaders;
  import org.springframework.http.HttpMethod;
  import org.springframework.http.HttpStatus;
  import org.springframework.http.MediaType;
  import org.springframework.test.context.TestPropertySource;
  
  import java.io.File;
  import java.nio.charset.StandardCharsets;
  import java.time.Instant;
  import java.util.Optional;
  import java.util.concurrent.TimeUnit;
  
  import static org.assertj.core.api.Assertions.assertThat;
  import static org.mockito.ArgumentMatchers.contains;
  import static org.mockito.Mockito.when;
  import static org.mockserver.integration.ClientAndServer.startClientAndServer;
  import static org.mockserver.model.HttpRequest.request;
  import static org.mockserver.model.HttpResponse.response;
  
  @SpringBootTest    
  public class Tests{
      
      private static final int PORT = 9998;
  
      private static ClientAndServer mockServer;
  
      @Autowired
      private MyService myService;
  
      @BeforeAll
      public void init(){
          mockServer = startClientAndServer(PORT);
          mockServer
              .when(
                  request()
                      .withPath(testUrlValidateTransactionOk).withMethod(HttpMethod.POST.name())
                      .withHeaders(
                          new Header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON.toString())
                      )
                      .withBody(contains(&quot;\&quot;id\&quot;:\&quot;1\&quot;&quot;))
                  ).respond(
              response().withStatusCode(HttpStatus.OK.value())
                  .withHeaders(
                      new Header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON.toString())
                  )
                  .withBody(&quot;{\&quot;passed\&quot;:true}&quot;));
  
          // What do i set here? Or in the snippet before by chaining?
          // mockServer.when()...
  
      }
  
      @Test
      void t1{
          //myService will internally call the MockServer
  
          //FIRST CALL -&gt; Pass
          MyPojo p = myService.call(1);
  
          assertThat(p.isPassed()).isEqualTo(Boolean.TRUE);
  
          //SECOND CALL -&gt; No Pass
          MyPojo p2 = myService.call(1);
          assertThat(p2.isPassed()).isEqualTo(Boolean.FALSE);
  
      }
  }
  </code></pre>
  <p>Dependencies (relevant):</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
  &lt;project xmlns=&quot;http://maven.apache.org/POM/4.0.0&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
      xsi:schemaLocation=&quot;http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd&quot;&gt;
      &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
      &lt;parent&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-parent&lt;/artifactId&gt;
          &lt;version&gt;2.4.4&lt;/version&gt;
      &lt;/parent&gt;
  
      &lt;groupId&gt;com.nice.project&lt;/groupId&gt;
      &lt;artifactId&gt;testing&lt;/artifactId&gt;
      &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
      &lt;name&gt;test&lt;/name&gt;
      &lt;description&gt;Testing&lt;/description&gt;
  
      &lt;properties&gt;
          &lt;java.version&gt;1.8&lt;/java.version&gt;
          &lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt;
          &lt;httpclient.version&gt;4.5.13&lt;/httpclient.version&gt;
          &lt;mock-server.version&gt;5.11.2&lt;/mock-server.version&gt;
      &lt;/properties&gt;
      &lt;dependencies&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;
          &lt;/dependency&gt;   
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-actuator&lt;/artifactId&gt;
          &lt;/dependency&gt;               
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-json&lt;/artifactId&gt;
          &lt;/dependency&gt;   
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-validation&lt;/artifactId&gt;
          &lt;/dependency&gt;   
          
          &lt;!--HTTP CLIENT--&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.apache.httpcomponents&lt;/groupId&gt;
              &lt;artifactId&gt;httpclient&lt;/artifactId&gt;
          &lt;/dependency&gt;
          
          &lt;!--TEST--&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-test&lt;/artifactId&gt;
              &lt;scope&gt;test&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.junit.jupiter&lt;/groupId&gt;
              &lt;artifactId&gt;junit-jupiter-engine&lt;/artifactId&gt;
              &lt;scope&gt;test&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.mock-server&lt;/groupId&gt;
              &lt;artifactId&gt;mockserver-netty&lt;/artifactId&gt;
              &lt;version&gt;${mock-server.version}&lt;/version&gt;
              &lt;scope&gt;test&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.mock-server&lt;/groupId&gt;
              &lt;artifactId&gt;mockserver-client-java&lt;/artifactId&gt;
              &lt;version&gt;${mock-server.version}&lt;/version&gt;
              &lt;scope&gt;test&lt;/scope&gt;
          &lt;/dependency&gt;       
  
      &lt;/dependencies&gt;
  
  &lt;/project&gt;
  </code></pre>
  <p>Thank you in advance.</p>