title: Reactive Spring Mono and doOnNext
body: <p>I use spring-boot-starter-webflux, reactor-test and spring-boot-starter-test 2.0.0.M7 in my project. In my <code>RepositoryInMemory.class</code> has a <code>List&lt;String&gt;</code> where you can add String values by <code>saveName(Mono&lt;String&gt; name)</code> method. You can also ask all the values that are added to the list by <code>getAllNames()</code> method. Problem is that how to test <code>RepositoryInMemory.class</code>? I have <code>RepositoryInMemoryTest.class</code> but seems like that it does not work because <code>List&lt;String&gt;</code> returns always 0. I know that the problem is <code>doOnNext</code> method in <code>RepositoryInMemory.class</code> but I don't know why and how to solve it. Does anyone know that how I should create a valid Junit test case? </p>
  
  <p><strong>RepositoryInMemory</strong> class</p>
  
  <pre><code>package com.example
  
  import java.util.ArrayList;
  import java.util.List;
  
  import org.springframework.stereotype.Repository;
  
  import reactor.core.publisher.Flux;
  import reactor.core.publisher.Mono;
  
  @Repository
  public class RepositoryInMemory {
  
      private final List&lt;String&gt; names = new ArrayList&lt;&gt;();
  
      public Flux&lt;String&gt; getAllNames() {
          return Flux.fromIterable(names);
      }
  
      public Mono&lt;Void&gt; saveName(Mono&lt;String&gt; name) {
          return name.doOnNext(report -&gt; names.add(report)).then();
      }
  }
  </code></pre>
  
  <p><strong>RepositoryInMemoryTest</strong> class</p>
  
  <pre><code>package com.example
  
  import static org.junit.Assert.assertEquals;
  
  import org.junit.Test;
  import org.junit.runner.RunWith;
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.boot.test.context.SpringBootTest;
  import org.springframework.test.context.junit4.SpringRunner;
  
  import reactor.core.publisher.Mono;
  
  @RunWith(SpringRunner.class)
  @SpringBootTest
  public class RepositoryInMemoryTest {
  
      @Autowired
      private RepositoryInMemory repository;
  
      @Test
      public void addDataToList_ShouldReturnOne() {
          Mono&lt;String&gt; name = Mono.just("Example Name");
          repository.saveName(name);
          int count = Math.toIntExact(repository.getAllNames().count().block());
          assertEquals(1, count);
      }
  }
  </code></pre>