Title: [waffle-scm] [330] trunk/core/src/test/java/org/codehaus/waffle/monitor: Refactored MonitorLevel to be an inner Level enum of Monitor interface.

Diff

Modified: trunk/core/src/main/java/org/codehaus/waffle/monitor/AbstractWritingMonitor.java (329 => 330)

--- trunk/core/src/main/java/org/codehaus/waffle/monitor/AbstractWritingMonitor.java	2007-11-02 17:24:39 UTC (rev 329)
+++ trunk/core/src/main/java/org/codehaus/waffle/monitor/AbstractWritingMonitor.java	2007-11-02 18:53:14 UTC (rev 330)
@@ -10,12 +10,13 @@
  *****************************************************************************/
 package org.codehaus.waffle.monitor;
 
-import org.codehaus.waffle.action.MethodDefinition;
-import static org.codehaus.waffle.monitor.MonitorLevel.DEBUG;
-import static org.codehaus.waffle.monitor.MonitorLevel.INFO;
+import static org.codehaus.waffle.monitor.Monitor.Level.DEBUG;
+import static org.codehaus.waffle.monitor.Monitor.Level.INFO;
 
 import java.util.Set;
 
+import org.codehaus.waffle.action.MethodDefinition;
+
 /**
  * Abstract implementation of Monitor that delegates writing to concrete subclasses.
  * 
@@ -26,15 +27,15 @@
     /**
      * Writes message for a given level. Concrete implementations should provide writing functionality.
      * 
-     * @param level
-     * @param message
+     * @param level the Level
+     * @param message the message to write 
      */
-    protected abstract void write(MonitorLevel level, String message);
+    protected abstract void write(Level level, String message);
 
     /**
      * Traces an exception. Concrete implementations should provide writing functionality.
      *
-     * @param exception
+     * @param exception the Exception to trace
      */
     protected abstract void trace(Exception exception);
 

Modified: trunk/core/src/main/java/org/codehaus/waffle/monitor/ActionMonitor.java (329 => 330)

--- trunk/core/src/main/java/org/codehaus/waffle/monitor/ActionMonitor.java	2007-11-02 17:24:39 UTC (rev 329)
+++ trunk/core/src/main/java/org/codehaus/waffle/monitor/ActionMonitor.java	2007-11-02 18:53:14 UTC (rev 330)
@@ -10,19 +10,16 @@
  *****************************************************************************/
 package org.codehaus.waffle.monitor;
 
-import org.codehaus.waffle.action.MethodDefinition;
-
 import java.util.Set;
 
+import org.codehaus.waffle.action.MethodDefinition;
+
 /**
- * Defines events that need to be monitored, eg for debugging purposes.
+ * A monitor for action-related events
  * 
- * Each implementing class can opt to disregard some of these events or handle them with 
- * different priorities.
- * 
  * @author Mauro Talevi
  */
-public interface ActionMonitor {
+public interface ActionMonitor extends Monitor {
 
     void defaultActionMethodFound(MethodDefinition methodDefinition);
 

Modified: trunk/core/src/main/java/org/codehaus/waffle/monitor/CommonsLoggingMonitor.java (329 => 330)

--- trunk/core/src/main/java/org/codehaus/waffle/monitor/CommonsLoggingMonitor.java	2007-11-02 17:24:39 UTC (rev 329)
+++ trunk/core/src/main/java/org/codehaus/waffle/monitor/CommonsLoggingMonitor.java	2007-11-02 18:53:14 UTC (rev 330)
@@ -49,7 +49,7 @@
     }
 
     @Override
-    protected void write(MonitorLevel level, String message) {
+    protected void write(Level level, String message) {
         switch (level) {
             case ERROR:
                 if (log.isErrorEnabled())

Added: trunk/core/src/main/java/org/codehaus/waffle/monitor/Monitor.java (0 => 330)

--- trunk/core/src/main/java/org/codehaus/waffle/monitor/Monitor.java	                        (rev 0)
+++ trunk/core/src/main/java/org/codehaus/waffle/monitor/Monitor.java	2007-11-02 18:53:14 UTC (rev 330)
@@ -0,0 +1,27 @@
+/*****************************************************************************
+ * Copyright (C) 2005,2006 Michael Ward                                      *
+ * All rights reserved.                                                      *
+ * ------------------------------------------------------------------------- *
+ * The software in this package is published under the terms of the BSD      *
+ * style license a copy of which has been included with this distribution in *
+ * the LICENSE.txt file.                                                     *
+ *                                                                           *
+ * Original code by: Mauro Talevi                                            *
+ *****************************************************************************/
+package org.codehaus.waffle.monitor;
+
+/**
+ * Marker Monitor defining the levels and any methods common to all monitors.
+ * 
+ * A monitor defines events that need to be monitored, eg for debugging purposes.
+ * 
+ * Each implementing class can opt to disregard some of these events or handle them with 
+ * different priorities.
+ * 
+ * @author Mauro Talevi
+ */
+public interface Monitor {
+    enum Level {
+        ERROR, INFO, WARN, DEBUG;
+    }
+}

Deleted: trunk/core/src/main/java/org/codehaus/waffle/monitor/MonitorLevel.java (329 => 330)

--- trunk/core/src/main/java/org/codehaus/waffle/monitor/MonitorLevel.java	2007-11-02 17:24:39 UTC (rev 329)
+++ trunk/core/src/main/java/org/codehaus/waffle/monitor/MonitorLevel.java	2007-11-02 18:53:14 UTC (rev 330)
@@ -1,35 +0,0 @@
-/*****************************************************************************
- * Copyright (C) 2005,2006 Michael Ward                                      *
- * All rights reserved.                                                      *
- * ------------------------------------------------------------------------- *
- * The software in this package is published under the terms of the BSD      *
- * style license a copy of which has been included with this distribution in *
- * the LICENSE.txt file.                                                     *
- *                                                                           *
- * Original code by: Mauro Talevi                                            *
- *****************************************************************************/
-package org.codehaus.waffle.monitor;
-
-/**
- * Enum that represent monitoring levels
- * 
- * @author Mauro Talevi
- */
-public enum MonitorLevel {
-
-    ERROR("Error"),
-    INFO("Info"), 
-    WARN("Warn"),
-    DEBUG("Debug");
-
-    private final String level;
-
-    MonitorLevel(String level) {
-        this.level = level;
-    }
-
-    public String toString(){
-        return level;
-    }
-    
-}

Modified: trunk/core/src/main/java/org/codehaus/waffle/monitor/SilentMonitor.java (329 => 330)

--- trunk/core/src/main/java/org/codehaus/waffle/monitor/SilentMonitor.java	2007-11-02 17:24:39 UTC (rev 329)
+++ trunk/core/src/main/java/org/codehaus/waffle/monitor/SilentMonitor.java	2007-11-02 18:53:14 UTC (rev 330)
@@ -11,6 +11,7 @@
 package org.codehaus.waffle.monitor;
 
 
+
 /**
  * SilentMonitor is a writing monitor that writes nothing.
  * 
@@ -18,7 +19,7 @@
  */
 public class SilentMonitor extends AbstractWritingMonitor {
 
-    protected void write(MonitorLevel level, String message) {
+    protected void write(Level level, String message) {
         // write nothing
     }
 

Modified: trunk/core/src/test/java/org/codehaus/waffle/monitor/AbstractWritingMonitorTest.java (329 => 330)

--- trunk/core/src/test/java/org/codehaus/waffle/monitor/AbstractWritingMonitorTest.java	2007-11-02 17:24:39 UTC (rev 329)
+++ trunk/core/src/test/java/org/codehaus/waffle/monitor/AbstractWritingMonitorTest.java	2007-11-02 18:53:14 UTC (rev 330)
@@ -10,19 +10,20 @@
  *****************************************************************************/
 package org.codehaus.waffle.monitor;
 
+import static org.junit.Assert.assertEquals;
+
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.lang.reflect.Method;
+import java.util.Set;
+
 import org.codehaus.waffle.action.MethodDefinition;
 import org.jmock.Mockery;
 import org.jmock.integration.junit4.JMock;
 import org.jmock.integration.junit4.JUnit4Mockery;
-import static org.junit.Assert.assertEquals;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 
-import java.io.PrintWriter;
-import java.io.StringWriter;
-import java.lang.reflect.Method;
-import java.util.Set;
-
 /**
  * @author Mauro Talevi
  */
@@ -37,7 +38,7 @@
         final AbstractWritingMonitor monitor = new AbstractWritingMonitor() {
 
             @Override
-            protected void write(MonitorLevel level, String message) {
+            protected void write(Level level, String message) {
                 sb.append(message).append("\n");
             }
 
@@ -60,7 +61,7 @@
         final StringWriter monitorWriter = new StringWriter();
         final AbstractWritingMonitor monitor = new AbstractWritingMonitor() {
             @Override
-            protected void write(MonitorLevel level, String message) {
+            protected void write(Level level, String message) {
                 // will not be tested here
             }
 

Modified: trunk/core/src/test/java/org/codehaus/waffle/monitor/CommonsLoggingMonitorTest.java (329 => 330)

--- trunk/core/src/test/java/org/codehaus/waffle/monitor/CommonsLoggingMonitorTest.java	2007-11-02 17:24:39 UTC (rev 329)
+++ trunk/core/src/test/java/org/codehaus/waffle/monitor/CommonsLoggingMonitorTest.java	2007-11-02 18:53:14 UTC (rev 330)
@@ -13,6 +13,7 @@
 import static org.junit.Assert.assertNotNull;
 
 import org.apache.commons.logging.Log;
+import org.codehaus.waffle.monitor.Monitor.Level;
 import org.jmock.Expectations;
 import org.jmock.Mockery;
 import org.jmock.integration.junit4.JMock;
@@ -53,10 +54,10 @@
         });
 
         final CommonsLoggingMonitor monitor = new CommonsLoggingMonitor(log);
-        monitor.write(MonitorLevel.DEBUG, message);
-        monitor.write(MonitorLevel.ERROR, message);
-        monitor.write(MonitorLevel.INFO, message);
-        monitor.write(MonitorLevel.WARN, message);
+        monitor.write(Level.DEBUG, message);
+        monitor.write(Level.ERROR, message);
+        monitor.write(Level.INFO, message);
+        monitor.write(Level.WARN, message);
     }
 
     @Test
@@ -73,9 +74,9 @@
         });
 
         final CommonsLoggingMonitor monitor = new CommonsLoggingMonitor(log);
-        monitor.write(MonitorLevel.DEBUG, message);
-        monitor.write(MonitorLevel.ERROR, message);
-        monitor.write(MonitorLevel.INFO, message);
-        monitor.write(MonitorLevel.WARN, message);
+        monitor.write(Level.DEBUG, message);
+        monitor.write(Level.ERROR, message);
+        monitor.write(Level.INFO, message);
+        monitor.write(Level.WARN, message);
     }
 }

Deleted: trunk/core/src/test/java/org/codehaus/waffle/monitor/MonitorLevelTest.java (329 => 330)

--- trunk/core/src/test/java/org/codehaus/waffle/monitor/MonitorLevelTest.java	2007-11-02 17:24:39 UTC (rev 329)
+++ trunk/core/src/test/java/org/codehaus/waffle/monitor/MonitorLevelTest.java	2007-11-02 18:53:14 UTC (rev 330)
@@ -1,31 +0,0 @@
-/*****************************************************************************
- * Copyright (C) 2005,2006 Michael Ward                                      *
- * All rights reserved.                                                      *
- * ------------------------------------------------------------------------- *
- * The software in this package is published under the terms of the BSD      *
- * style license a copy of which has been included with this distribution in *
- * the LICENSE.txt file.                                                     *
- *                                                                           *
- * Original code by: Mauro Talevi                                            *
- *****************************************************************************/
-package org.codehaus.waffle.monitor;
-
-import static org.junit.Assert.assertEquals;
-
-import org.junit.Test;
-
-/**
- * 
- * @author Mauro Talevi
- */
-public class MonitorLevelTest {
-
-    @Test
-    public void enumsHHaveValidStringRepresentations() {
-        assertEquals(MonitorLevel.DEBUG.toString(), "Debug");
-        assertEquals(MonitorLevel.ERROR.toString(), "Error");
-        assertEquals(MonitorLevel.INFO.toString(), "Info");
-        assertEquals(MonitorLevel.WARN.toString(), "Warn");
-    }
-
-}


To unsubscribe from this list please visit:

http://xircles.codehaus.org/manage_email

Reply via email to