Author: desruisseaux
Date: Wed Jun 19 13:24:11 2013
New Revision: 1494610
URL: http://svn.apache.org/r1494610
Log:
Ported two tests.
Added:
sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/util/logging/DummyLogger.java
(with props)
sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/util/logging/LoggerAdapterTest.java
(with props)
Modified:
sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/test/suite/UtilityTestSuite.java
sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/util/logging/EmptyWarningListeners.java
Modified: sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/test/suite/UtilityTestSuite.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/test/suite/UtilityTestSuite.java?rev=1494610&r1=1494609&r2=1494610&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/test/suite/UtilityTestSuite.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/test/suite/UtilityTestSuite.java
[UTF-8] Wed Jun 19 13:24:11 2013
@@ -51,6 +51,7 @@ import org.junit.BeforeClass;
org.apache.sis.util.logging.PerformanceLevelTest.class,
org.apache.sis.util.logging.WarningListenersTest.class,
org.apache.sis.util.logging.MonolineFormatterTest.class,
+ org.apache.sis.util.logging.LoggerAdapterTest.class,
org.apache.sis.math.MathFunctionsTest.class,
org.apache.sis.math.StatisticsTest.class,
org.apache.sis.math.StatisticsFormatTest.class,
Added: sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/util/logging/DummyLogger.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/util/logging/DummyLogger.java?rev=1494610&view=auto
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/util/logging/DummyLogger.java
(added)
+++ sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/util/logging/DummyLogger.java
[UTF-8] Wed Jun 19 13:24:11 2013
@@ -0,0 +1,114 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.sis.util.logging;
+
+import java.util.logging.Level;
+
+
+/**
+ * A dummy implementation of {@link LoggerAdapter} class for testing purpose.
+ * This class is used by {@link LoggerAdapterTest}.
+ *
+ * @author Martin Desruisseaux (IRD)
+ * @since 0.3 (derived from geotk-2.4)
+ * @version 0.3
+ * @module
+ */
+final strictfp class DummyLogger extends LoggerAdapter {
+ /**
+ * The level of the last logging event.
+ */
+ Level level;
+
+ /**
+ * The last logged message.
+ */
+ String last;
+
+ /**
+ * Creates a dummy logger.
+ */
+ DummyLogger() {
+ super("org.apache.sis.util.logging");
+ clear();
+ }
+
+ /**
+ * Clears the logger state, for testing purpose only.
+ */
+ public void clear() {
+ level = Level.OFF;
+ last = null;
+ }
+
+ @Override
+ public void setLevel(Level level) {
+ this.level = level;
+ }
+
+ @Override
+ public Level getLevel() {
+ return level;
+ }
+
+ @Override
+ public boolean isLoggable(Level level) {
+ return level.intValue() > this.level.intValue();
+ }
+
+ @Override
+ public void severe(String message) {
+ level = Level.SEVERE;
+ last = message;
+ }
+
+ @Override
+ public void warning(String message) {
+ level = Level.WARNING;
+ last = message;
+ }
+
+ @Override
+ public void info(String message) {
+ level = Level.INFO;
+ last = message;
+ }
+
+ @Override
+ public void config(String message) {
+ level = Level.CONFIG;
+ last = message;
+ }
+
+ @Override
+ public void fine(String message) {
+ level = Level.FINE;
+ last = message;
+ }
+
+ @Override
+ public void finer(String message) {
+ level = Level.FINER;
+ last = message;
+ }
+
+ @Override
+ public void finest(String message) {
+ level = Level.FINEST;
+ last = message;
+ }
+}
Propchange: sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/util/logging/DummyLogger.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/util/logging/DummyLogger.java
------------------------------------------------------------------------------
svn:mime-type = text/plain;charset=UTF-8
Modified: sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/util/logging/EmptyWarningListeners.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/util/logging/EmptyWarningListeners.java?rev=1494610&r1=1494609&r2=1494610&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/util/logging/EmptyWarningListeners.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/util/logging/EmptyWarningListeners.java
[UTF-8] Wed Jun 19 13:24:11 2013
@@ -30,6 +30,11 @@ import org.apache.sis.util.resources.Err
* component where the real {@link WarningListeners} instance is not yet available.</p>
*
* @param <S> If the listener list had a source, that would be type type of the source.
+ *
+ * @author Martin Desruisseaux (Geomatys)
+ * @since 0.3
+ * @version 0.3
+ * @module
*/
public final strictfp class EmptyWarningListeners<S> extends WarningListeners<S>
{
/**
Added: sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/util/logging/LoggerAdapterTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/util/logging/LoggerAdapterTest.java?rev=1494610&view=auto
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/util/logging/LoggerAdapterTest.java
(added)
+++ sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/util/logging/LoggerAdapterTest.java
[UTF-8] Wed Jun 19 13:24:11 2013
@@ -0,0 +1,71 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.sis.util.logging;
+
+import java.util.logging.Level;
+import org.apache.sis.test.TestCase;
+import org.junit.*;
+
+import static org.junit.Assert.*;
+
+
+/**
+ * Tests the {@link LoggerAdapter} class.
+ *
+ * @author Martin Desruisseaux (IRD)
+ * @since 0.3 (derived from geotk-2.4)
+ * @version 0.3
+ * @module
+ */
+public final strictfp class LoggerAdapterTest extends TestCase {
+ /**
+ * Tests the {@link LoggerAdapter#log(Level,String)} method.
+ * This is of special interest because of the switch cases used in implementation.
+ */
+ @Test
+ public void testLog() {
+ final DummyLogger logger = new DummyLogger();
+ final Object[] levels = new Object[] {
+ Level.FINE, "apple",
+ Level.INFO, "orange",
+ Level.FINEST, "yellow",
+ Level.CONFIG, "yeti",
+ Level.SEVERE, "ouch!",
+ Level.WARNING, "caution",
+ Level.FINEST, "don't mind",
+ };
+ for (int i=0; i<levels.length; i++) {
+ final Level level = (Level) levels[i];
+ final String message = (String) levels[++i];
+ logger.clear();
+ logger.log(level, message);
+ assertEquals(level, logger.level);
+ assertEquals(message, logger.last);
+ }
+ // Actually, Level.OFF has the highest intValue.
+ // LoggerAdapter can easily match this level to a no-op.
+ logger.clear();
+ logger.log(Level.OFF, "off");
+ assertEquals(Level.OFF, logger.level);
+
+ // Actually, Level.ALL has the smallest intValue.
+ // LoggerAdapter has no easy match for this level.
+ logger.clear();
+ logger.log(Level.ALL, "all");
+ assertEquals(Level.OFF, logger.level);
+ }
+}
Propchange: sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/util/logging/LoggerAdapterTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/util/logging/LoggerAdapterTest.java
------------------------------------------------------------------------------
svn:mime-type = text/plain;charset=UTF-8
|