title: JUnit testing / calling function few times
body: <p>I am extracting concept from a single page and that page is being used in different functions, so i have created a function that assigns the value if value hasn't been assigned yet.</p>
  
  <pre><code>public String text() {                               
      if (text.isPresent()) {                          
          return text.get();                           
      }                                                
      this.text = Optional.of(extractText(pdDocument));
      return text.get();                               
  }
  </code></pre>
  
  <p>I would like to create a test that checks that the function is being called once and the context is shared between the functions that doing some functionality in the same context</p>
  
  <p>Here is an example when text() is being called twice</p>
  
  <pre><code>private Optional&lt;String&gt; packingListNet() {           
      return locatePattern(text(), PACKING_LIST_NET);   
  }  
  
  private Optional&lt;String&gt; packingListNumber() {        
      return locatePattern(text(), PACKING_LIST_NUMBER);
  }                  
  </code></pre>
  
  <p>Would be grateful for any information, thank you</p>