title: Mockito - Test if a method of a class is called
body: <p>I am new to writing tests in java, and seem to be unable to test if a method of a class is called.</p>
  
  <p>I am sending metrics to datadog, and want to test in the code if a function of another class was called. </p>
  
  <p>It says I need to mock first, but I couldn't get it to work.</p>
  
  <p>MetricRecorder.java</p>
  
  <pre><code>import com.timgroup.statsd.StatsDClient;
  import com.timgroup.statsd.NonBlockingStatsDClient;
  import com.google.common.base.Preconditions;
  
  public class MetricRecorder {
      private final String namespace;
      private final static StatsDClient metrics = new NonBlockingStatsDClient(
        "my.prefix",                          
        "localhost",                          
        8125,                                 
        new String[] {"tag:value"} 
      );
  
      public MetricRecorder(String namespace) {
          Preconditions.checkNotNull(namespace);
          this.namespace = namespace;
      }
  
      public void inc(String metricName) {
          this.inc(metricName, 1);
      }
  
      public void inc(final String metricName, final long value) {
          Preconditions.checkNotNull(metricName);
          try {
              metrics.recordHistogramValue(MetricRecorder.name(namespace, metricName), value);
          } catch (Exception e) {
              logger.warn("Unable to record metric {} due to :", metricName, e);
          }
      }
      ...
  }
  </code></pre>
  
  <p>MetricRecorderTest.java</p>
  
  <pre><code>public class MetricsRecorderTest {
  
      @Test
      public void metricsRecorderTest() {
          MetricRecorder recorder = new MetricRecorder("dev");
          recorder.inc("foo", 1);
          verify(recorder.metrics, times(1)).recordHistogramValue(eq("dev.foo"), 1);
      }
  }
  </code></pre>
  
  <p>When I run the test I get this => org.mockito.exceptions.misusing.NotAMockException: 
  Argument passed to verify() is of type NonBlockingStatsDClient and is not a mock!</p>
  
  <p>Any idea of how I should be testing if recordHistogramValue was called, and if so with what arguments?</p>