This is an automated email from the ASF dual-hosted git repository.

btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit ffc1eec79e7f7650ead21a1ee8a6bef1bfa2341d
Author: datph <[email protected]>
AuthorDate: Tue Apr 2 15:22:31 2019 +0700

    JAMES-2706 Refactor MetricsMailetTest with non-mock metric
---
 server/mailet/mailets/pom.xml                      |  5 +++++
 .../james/transport/mailets/MetricsMailetTest.java | 24 ++++++++--------------
 2 files changed, 13 insertions(+), 16 deletions(-)

diff --git a/server/mailet/mailets/pom.xml b/server/mailet/mailets/pom.xml
index 967e4e5..cb82e3b 100644
--- a/server/mailet/mailets/pom.xml
+++ b/server/mailet/mailets/pom.xml
@@ -106,6 +106,11 @@
         </dependency>
         <dependency>
             <groupId>${james.groupId}</groupId>
+            <artifactId>metrics-tests</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>${james.groupId}</groupId>
             <artifactId>james-mdn</artifactId>
         </dependency>
         <dependency>
diff --git 
a/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/MetricsMailetTest.java
 
b/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/MetricsMailetTest.java
index 30a3d8e..797a495 100644
--- 
a/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/MetricsMailetTest.java
+++ 
b/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/MetricsMailetTest.java
@@ -19,14 +19,9 @@
 
 package org.apache.james.transport.mailets;
 
-import static org.mockito.ArgumentMatchers.anyString;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.verifyNoMoreInteractions;
-import static org.mockito.Mockito.when;
+import static org.assertj.core.api.Assertions.assertThat;
 
-import org.apache.james.metrics.api.Metric;
-import org.apache.james.metrics.api.MetricFactory;
+import org.apache.james.metrics.tests.RecordingMetricFactory;
 import org.apache.mailet.base.test.FakeMail;
 import org.apache.mailet.base.test.FakeMailetConfig;
 import org.junit.Before;
@@ -37,19 +32,16 @@ import org.junit.rules.ExpectedException;
 public class MetricsMailetTest {
 
     public static final String MAILET_NAME = "Metric test";
+    public static final String METRIC_NAME = "metricName";
     @Rule
     public ExpectedException expectedException = ExpectedException.none();
 
-    private MetricFactory metricFactory;
-    private Metric metric;
+    private RecordingMetricFactory metricFactory;
     private MetricsMailet mailet;
 
     @Before
     public void setUp() throws Exception {
-        metricFactory = mock(MetricFactory.class);
-        metric = mock(Metric.class);
-        when(metricFactory.generate(anyString())).thenReturn(metric);
-
+        metricFactory = new RecordingMetricFactory();
         mailet = new MetricsMailet(metricFactory);
     }
 
@@ -64,13 +56,13 @@ public class MetricsMailetTest {
     public void serviceShouldIncrementMetricCounter() throws Exception {
         mailet.init(FakeMailetConfig.builder()
             .mailetName(MAILET_NAME)
-            .setProperty(MetricsMailet.METRIC_NAME, "metricName")
+            .setProperty(MetricsMailet.METRIC_NAME, METRIC_NAME)
             .build());
 
         mailet.service(FakeMail.builder().name("name").build());
 
-        verify(metric).increment();
-        verifyNoMoreInteractions(metric);
+        assertThat(metricFactory.countFor(METRIC_NAME))
+            .isEqualTo(1);
     }
 
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to