title: How to verify a method call through a functional interface with Mockito?
body: <p>I'm using a Supplier to instantiate a field thread safe while avoiding consecutive calls to the synchronized method.</p>
  
  <pre><code>class MyClass extends AbstractClassWithContext {
  
      Supplier&lt;Foo&gt; fooGetter;
      Foo foo;    
  
      public MyClass() {
          this.fooGetter = this::initFoo;
      }
  
      Foo getFoo(){
          return fooGetter.get();
      }
  
      synchonized Foo initFoo(){
          if(Objects.isNull(this.foo)) {
              this.foo = getContext().getFoo();
          }
          this.fooGetter = () -&gt; this.foo;
          return this.foo;
      }
  }
  </code></pre>
  
  <p>When I'm running my Unit Tests I want to make sure that initFoo() is called exactly once. Sadly <code>verify(classUnderTest, times(1)).initFoo()</code> does not register that initFoo is entered. I debugged this and calling <code>getFoo()</code> does in turn enter initFoo.</p>
  
  <p>Any ideas?</p>