package org.automon.implentations;

import com.jamonapi.Monitor;
import com.jamonapi.MonitorFactory;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import static org.assertj.core.api.Assertions.assertThat;


public class MetricsTest {
    private Jamon openMon = new Jamon();
    private static final String LABEL =  "helloWorld.timer";
    private static final String EXCEPTION = "org.automon.MyException";

    @Before
    public void setUp() throws Exception {
        MonitorFactory.reset();
    }

    @After
    public void tearDown() throws Exception {
        MonitorFactory.reset();
    }

    @Test
    public void testStart() throws Exception {
        Monitor mon = openMon.start(LABEL);
        assertThat(mon.getLabel()).describedAs("The label should match passed in label").isEqualTo(LABEL);
        assertThat(mon.getUnits()).describedAs("The units should be for time").isEqualTo("ms.");
        assertThat(mon.getActive()).describedAs("The monitor should have been started").isEqualTo(1);
    }

    @Test
    public void testStop() throws Exception {
        Monitor mon = openMon.start(LABEL);
        openMon.stop(mon);
        assertThat(mon.getLabel()).describedAs("The label should match passed in label").isEqualTo(LABEL);
        assertThat(mon.getActive()).describedAs("The monitor should not be running").isEqualTo(0);
        assertThat(mon.getHits()).describedAs("The monitor should have finished and recorded hits").isEqualTo(1);
    }

    @Test
    public void testException() throws Exception {
        openMon.exception(EXCEPTION);
        Monitor mon = MonitorFactory.getMonitor(EXCEPTION, "Exception");
        assertThat(mon).describedAs("The exception monitor should have been created").isNotNull();
        assertThat(mon.getLabel()).describedAs("The label should match passed in label").isEqualTo(EXCEPTION);
    }

    @Test
    public void testShouldBeEnabledByDefault() throws Exception {
        assertThat(openMon.isEnabled()).describedAs("Should be enabled by default").isTrue();
    }

    @Test
    public void testEnableDisable() throws Exception {
        openMon.enable(false);
        assertThat(openMon.isEnabled()).describedAs("Enabled status should equal jamons status").isEqualTo(MonitorFactory.isEnabled());
        assertThat(openMon.isEnabled()).describedAs("Status should be disabled").isFalse();

        openMon.enable(true);
        assertThat(openMon.isEnabled()).describedAs("Enabled status should equal jamons status").isEqualTo(MonitorFactory.isEnabled());
        assertThat(openMon.isEnabled()).describedAs("Status should be enabled").isTrue();
    }

}
@@ -29,16 +29,133 @@
 tions;%0A%0A
+import com.codahale.metrics.MetricRegistry;%0Aimport com.codahale.metrics.Snapshot;%0Aimport com.codahale.metrics.Timer;%0A
 import c
@@ -383,21 +383,23 @@
 private 
-Jamon
+Metrics
  openMon
@@ -409,13 +409,15 @@
 new 
-Jamon
+Metrics
 ();%0A
@@ -608,40 +608,8 @@
 n %7B%0A
-        MonitorFactory.reset();%0A
     
@@ -672,40 +672,8 @@
 n %7B%0A
-        MonitorFactory.reset();%0A
     
@@ -732,38 +732,36 @@
 ption %7B%0A        
-Monito
+Time
 r mon = openMon.
@@ -804,253 +804,46 @@
 .get
-Label()).describedAs(%22The label should match passed in label%22).isEqualTo(LABEL);%0A        assertThat(mon.getUnits()).describedAs(%22The units should be for time%22).isEqualTo(%22ms.%22);%0A        assertThat(mon.getActive()).describedAs(%22The monito
+Count()).describedAs(%22The time
 r should
  hav
@@ -842,23 +842,23 @@
 ould
+n't
  have 
-been star
+comple
 ted%22
@@ -861,33 +861,33 @@
 ted%22).isEqualTo(
-1
+0
 );%0A    %7D%0A%0A    @T
@@ -936,38 +936,36 @@
 ption %7B%0A        
-Monito
+Time
 r mon = openMon.
@@ -1035,121 +1035,13 @@
 .get
-Label()).describedAs(%22The label should match passed in label%22).isEqualTo(LABEL);%0A        assertThat(mon.getActive
+Count
 ()).
@@ -1049,38 +1049,36 @@
 escribedAs(%22The 
-monito
+time
 r should not be 
@@ -1074,354 +1074,252 @@
 uld 
-not be running%22).isEqualTo(0);%0A        assertThat(mon.getHits()).describedAs(%22The monitor should have finished and recorded hits%22).isEqualTo(1);%0A    %7D%0A%0A    @Test%0A    public void testException() throws Exception %7B%0A        openMon.exception(EXCEPTION);%0A        Monitor mon = MonitorFactory.getMonitor(EXCEPTION, %22Exception%22);%0A        assertThat(mon
+have completed/been stopped%22).isEqualTo(1);%0A    %7D%0A%0A    @Test%0A    public void testException() throws Exception %7B%0A        MetricRegistry metricRegistry = openMon.getMetricRegistry();%0A        assertThat(metricRegistry.counter(EXCEPTION).getCount()
 ).de
@@ -1329,19 +1329,18 @@
 ibedAs(%22
-The
+No
  excepti
@@ -1346,142 +1346,186 @@
 ion 
-monitor should have been created%22).isNotNull();%0A        assertThat(mon.getLabel()).describedAs(%22The label should match passed in label
+should exist yet%22).isEqualTo(0);%0A        openMon.exception(EXCEPTION);%0A        assertThat(metricRegistry.counter(EXCEPTION).getCount()).describedAs(%22An exception should now exist
 %22).i
@@ -1533,25 +1533,17 @@
 EqualTo(
-EXCEPTION
+1
 );%0A    %7D
@@ -1874,437 +1874,338 @@
 As(%22
-Enabled status should equal jamons status%22).isEqualTo(MonitorFactory.isEnabled());%0A        assertThat(openMon.isEnabled()).describedAs(%22Status should be disabled%22).isFalse();%0A%0A        openMon.enable(true);%0A        assertThat(openMon.isEnabled()).describedAs(%22Enabled status should equal jamons status%22).isEqualTo(MonitorFactory.isEnabled());%0A        assertThat(openMon.isEnabled()).describedAs(%22Status should be enabled%22).isTrue(
+Metrics can't be enabled/disabled so it is a noop%22).isTrue();%0A      %7D%0A%0A    @Test%0A    public void setMetricRegistry() throws Exception %7B%0A        MetricRegistry newMetricRegistry = new MetricRegistry();%0A        openMon.setMetricRegistry(newMetricRegistry);%0A        assertThat(openMon.getMetricRegistry()).isEqualTo(newMetricRegistry
 );%0A 

test - modified Metrics test