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 JamonTest {
    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();
    }

}
@@ -1537,32 +1537,167 @@
 ows Exception %7B%0A
+        assertThat(MonitorFactory.exists(EXCEPTION, %22Exception%22)).describedAs(%22The exception monitor should not exist yet%22).isFalse();%0A
         openMon.
@@ -1726,30 +1726,27 @@
         
-Monitor mon = 
+assertThat(
 MonitorF
@@ -1756,18 +1756,14 @@
 ory.
-getMonitor
+exists
 (EXC
@@ -1786,32 +1786,8 @@
 on%22)
-;%0A        assertThat(mon
 ).de
@@ -1830,76 +1830,124 @@
 uld 
-have been created%22).isNotNull();%0A        assertThat(mon.getLabel()).
+exist%22).isTrue();%0A        assertThat(MonitorFactory.getMonitor(EXCEPTION, %22Exception%22).getLabel()).%0A                
 desc

test - refactored jamon test