From 0a3f072972476bad46efae46a31ab0f5cc6d9be9 Mon Sep 17 00:00:00 2001
From: tpylak <tpylak>
Date: Mon, 5 Sep 2011 08:18:11 +0000
Subject: [PATCH] expose logger for tests

SVN: 22778
---
 .../concurrent/ConcurrencyUtilitiesTest.java  | 39 +----------
 .../cisd/common/logging/AssertingLogger.java  | 64 +++++++++++++++++++
 2 files changed, 65 insertions(+), 38 deletions(-)
 create mode 100644 common/sourceTest/java/ch/systemsx/cisd/common/logging/AssertingLogger.java

diff --git a/common/sourceTest/java/ch/systemsx/cisd/common/concurrent/ConcurrencyUtilitiesTest.java b/common/sourceTest/java/ch/systemsx/cisd/common/concurrent/ConcurrencyUtilitiesTest.java
index 21191d59ce6..782afd2ff3b 100644
--- a/common/sourceTest/java/ch/systemsx/cisd/common/concurrent/ConcurrencyUtilitiesTest.java
+++ b/common/sourceTest/java/ch/systemsx/cisd/common/concurrent/ConcurrencyUtilitiesTest.java
@@ -22,8 +22,6 @@ import static org.testng.AssertJUnit.assertNull;
 import static org.testng.AssertJUnit.assertTrue;
 import static org.testng.AssertJUnit.fail;
 
-import java.util.ArrayList;
-import java.util.List;
 import java.util.Timer;
 import java.util.TimerTask;
 import java.util.concurrent.Callable;
@@ -39,7 +37,7 @@ import ch.systemsx.cisd.base.exceptions.CheckedExceptionTunnel;
 import ch.systemsx.cisd.base.exceptions.InterruptedExceptionUnchecked;
 import ch.systemsx.cisd.base.namedthread.NamingThreadPoolExecutor;
 import ch.systemsx.cisd.common.concurrent.ConcurrencyUtilities.ILogSettings;
-import ch.systemsx.cisd.common.logging.ISimpleLogger;
+import ch.systemsx.cisd.common.logging.AssertingLogger;
 import ch.systemsx.cisd.common.logging.LogInitializer;
 import ch.systemsx.cisd.common.logging.LogLevel;
 import ch.systemsx.cisd.common.test.Retry10;
@@ -54,41 +52,6 @@ public class ConcurrencyUtilitiesTest
 
     private final static String name = "This is the pool name";
 
-    private static class LogRecord
-    {
-        final LogLevel level;
-
-        final String message;
-
-        LogRecord(final LogLevel level, final String message)
-        {
-            this.level = level;
-            this.message = message;
-        }
-    }
-
-    private class AssertingLogger implements ISimpleLogger
-    {
-        private final List<LogRecord> records = new ArrayList<LogRecord>();
-
-        public void log(final LogLevel level, final String message)
-        {
-            records.add(new LogRecord(level, message));
-        }
-
-        public void assertNumberOfMessage(final int expectedNumberOfMessages)
-        {
-            assertEquals(expectedNumberOfMessages, records.size());
-        }
-
-        public void assertEq(final int i, final LogLevel expectedLevel, final String expectedMessage)
-        {
-            assertEquals(expectedLevel, records.get(i).level);
-            assertEquals(expectedMessage, records.get(i).message);
-        }
-
-    }
-
     private ILogSettings logSettings;
 
     private AssertingLogger logger;
diff --git a/common/sourceTest/java/ch/systemsx/cisd/common/logging/AssertingLogger.java b/common/sourceTest/java/ch/systemsx/cisd/common/logging/AssertingLogger.java
new file mode 100644
index 00000000000..bcd5a96ac59
--- /dev/null
+++ b/common/sourceTest/java/ch/systemsx/cisd/common/logging/AssertingLogger.java
@@ -0,0 +1,64 @@
+/*
+ * Copyright 2011 ETH Zuerich, CISD
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package ch.systemsx.cisd.common.logging;
+
+import static org.testng.AssertJUnit.assertEquals;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import ch.systemsx.cisd.common.logging.ISimpleLogger;
+import ch.systemsx.cisd.common.logging.LogLevel;
+
+/**
+ * A logger useful for testing.
+ * 
+ * @author Bernd Rinn
+ */
+public class AssertingLogger implements ISimpleLogger
+{
+    private final List<LogRecord> records = new ArrayList<LogRecord>();
+
+    public void log(final LogLevel level, final String message)
+    {
+        records.add(new LogRecord(level, message));
+    }
+
+    public void assertNumberOfMessage(final int expectedNumberOfMessages)
+    {
+        assertEquals(expectedNumberOfMessages, records.size());
+    }
+
+    public void assertEq(final int i, final LogLevel expectedLevel, final String expectedMessage)
+    {
+        assertEquals(expectedLevel, records.get(i).level);
+        assertEquals(expectedMessage, records.get(i).message);
+    }
+
+    private static class LogRecord
+    {
+        final LogLevel level;
+
+        final String message;
+
+        LogRecord(final LogLevel level, final String message)
+        {
+            this.level = level;
+            this.message = message;
+        }
+    }
+}
\ No newline at end of file
-- 
GitLab