sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1730054 - in /sis/branches/JDK8/core: sis-metadata/src/test/java/org/apache/sis/metadata/iso/ sis-metadata/src/test/java/org/apache/sis/metadata/iso/identification/ sis-metadata/src/test/java/org/apache/sis/metadata/iso/maintenance/ sis-me...
Date Fri, 12 Feb 2016 16:21:46 GMT
Author: desruisseaux
Date: Fri Feb 12 16:21:45 2016
New Revision: 1730054

URL: http://svn.apache.org/viewvc?rev=1730054&view=rev
Log:
Change the way the tests verify the logging messages.
Instead than doing the assertions in LoggingWatcher, do them in the test methods.
The reason for this change is that assertion failures in LoggingWatcher had very confusing stack traces.

Modified:
    sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/AllMetadataTest.java
    sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/identification/DefaultResolutionTest.java
    sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/maintenance/DefaultScopeDescriptionTest.java
    sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/spatial/DefaultGeorectifiedTest.java
    sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/internal/jaxb/referencing/CC_GeneralOperationParameterTest.java
    sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/AuthorityFactoriesTest.java
    sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/crs/DefaultProjectedCRSTest.java
    sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/factory/MultiAuthoritiesFactoryTest.java
    sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/factory/sql/EPSGFactoryTest.java
    sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/factory/sql/EPSGInstallerTest.java
    sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/test/LoggingWatcher.java

Modified: sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/AllMetadataTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/AllMetadataTest.java?rev=1730054&r1=1730053&r2=1730054&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/AllMetadataTest.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/AllMetadataTest.java [UTF-8] Fri Feb 12 16:21:45 2016
@@ -44,12 +44,11 @@ import static org.junit.Assert.*;
 @DependsOn(org.apache.sis.metadata.PropertyAccessorTest.class)
 public final strictfp class AllMetadataTest extends MetadataTestCase {
     /**
-     * A JUnit {@linkplain Rule rule} for listening to log events. This field is public
-     * because JUnit requires us to do so, but should be considered as an implementation
-     * details (it should have been a private field).
+     * A JUnit {@link Rule} for listening to log events. This field is public because JUnit requires us to
+     * do so, but should be considered as an implementation details (it should have been a private field).
      */
     @Rule
-    public final LoggingWatcher listener = new LoggingWatcher(Context.LOGGER);
+    public final LoggingWatcher loggings = new LoggingWatcher(Context.LOGGER);
 
     /**
      * Creates a new test case with all GeoAPI interfaces and code lists to test.
@@ -219,8 +218,8 @@ public final strictfp class AllMetadataT
     @Test
     @Override
     public void testPropertyValues() {
-        listener.maximumLogCount = 4;
         super.testPropertyValues();
+        loggings.assertNoUnexpectedLogging(4);
     }
 
     /**

Modified: sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/identification/DefaultResolutionTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/identification/DefaultResolutionTest.java?rev=1730054&r1=1730053&r2=1730054&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/identification/DefaultResolutionTest.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/identification/DefaultResolutionTest.java [UTF-8] Fri Feb 12 16:21:45 2016
@@ -42,21 +42,11 @@ import static org.apache.sis.test.Assert
 @DependsOn(DefaultRepresentativeFractionTest.class)
 public final strictfp class DefaultResolutionTest extends TestCase {
     /**
-     * A JUnit {@linkplain Rule rule} for listening to log events. This field is public
-     * because JUnit requires us to do so, but should be considered as an implementation
-     * details (it should have been a private field).
+     * A JUnit {@link Rule} for listening to log events. This field is public because JUnit requires us to
+     * do so, but should be considered as an implementation details (it should have been a private field).
      */
     @Rule
-    public final LoggingWatcher listener = new LoggingWatcher(Context.LOGGER) {
-        /**
-         * Ensures that the logging message contains the name of the exclusive properties.
-         */
-        @Override
-        protected void verifyMessage(final String message) {
-            assertTrue(message.contains("distance"));
-            assertTrue(message.contains("equivalentScale"));
-        }
-    };
+    public final LoggingWatcher loggings = new LoggingWatcher(Context.LOGGER);
 
     /**
      * Tests the {@link DefaultResolution#DefaultResolution(RepresentativeFraction)} constructor.
@@ -71,6 +61,7 @@ public final strictfp class DefaultResol
         scale.setDenominator(100);
         final DefaultResolution metadata = new DefaultResolution(scale);
         assertSame(scale, metadata.getEquivalentScale());
+        loggings.assertNoUnexpectedLogging(0);
     }
 
     /**
@@ -86,11 +77,13 @@ public final strictfp class DefaultResol
         metadata.setDistance(2.0);
         assertEquals("distance", Double.valueOf(2.0), metadata.getDistance());
         assertNull("equivalentScale", metadata.getEquivalentScale());
+        loggings.assertNoUnexpectedLogging(0);
 
-        listener.maximumLogCount = 1;
         metadata.setEquivalentScale(scale);
         assertSame("equivalentScale", scale, metadata.getEquivalentScale());
         assertNull("distance", metadata.getDistance());
+        loggings.assertLoggingContains(0, "distance", "equivalentScale");
+        loggings.assertNoUnexpectedLogging(1);
 
         metadata.setDistance(null); // Expected to be a no-op.
         assertSame("equivalentScale", scale, metadata.getEquivalentScale());
@@ -99,6 +92,7 @@ public final strictfp class DefaultResol
         metadata.setEquivalentScale(null);
         assertNull("equivalentScale", metadata.getEquivalentScale());
         assertNull("distance", metadata.getDistance());
+        loggings.assertNoUnexpectedLogging(1);
     }
 
     /**
@@ -161,5 +155,6 @@ public final strictfp class DefaultResol
          * Should not be a problem neither.
          */
         assertEquals(resolution, XML.unmarshal(xml));
+        loggings.assertNoUnexpectedLogging(0);
     }
 }

Modified: sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/maintenance/DefaultScopeDescriptionTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/maintenance/DefaultScopeDescriptionTest.java?rev=1730054&r1=1730053&r2=1730054&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/maintenance/DefaultScopeDescriptionTest.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/maintenance/DefaultScopeDescriptionTest.java [UTF-8] Fri Feb 12 16:21:45 2016
@@ -36,21 +36,11 @@ import static org.apache.sis.test.Assert
  */
 public final strictfp class DefaultScopeDescriptionTest extends TestCase {
     /**
-     * A JUnit {@linkplain Rule rule} for listening to log events. This field is public
-     * because JUnit requires us to do so, but should be considered as an implementation
-     * details (it should have been a private field).
+     * A JUnit {@link Rule} for listening to log events. This field is public because JUnit requires us to
+     * do so, but should be considered as an implementation details (it should have been a private field).
      */
     @Rule
-    public final LoggingWatcher listener = new LoggingWatcher(Context.LOGGER) {
-        /**
-         * Ensures that the logging message contains the name of the exclusive properties.
-         */
-        @Override
-        protected void verifyMessage(final String message) {
-            assertTrue(message.contains("dataset"));
-            assertTrue(message.contains("other"));
-        }
-    };
+    public final LoggingWatcher loggings = new LoggingWatcher(Context.LOGGER);
 
     /**
      * Tests the various setter methods. Since they are exclusive properties,
@@ -61,11 +51,13 @@ public final strictfp class DefaultScope
         final DefaultScopeDescription metadata = new DefaultScopeDescription();
         metadata.setDataset("A dataset");
         assertEquals("dataset", "A dataset", metadata.getDataset());
+        loggings.assertNoUnexpectedLogging(0);
 
-        listener.maximumLogCount = 1;
         metadata.setOther(new SimpleInternationalString("Other value"));
         assertEquals("other", "Other value", String.valueOf(metadata.getOther()));
         assertNull("dataset", metadata.getDataset());
+        loggings.assertLoggingContains(0, "dataset", "other");
+        loggings.assertNoUnexpectedLogging(1);
 
         metadata.setDataset(null); // Expected to be a no-op.
         assertEquals("other", "Other value", String.valueOf(metadata.getOther()));
@@ -74,5 +66,6 @@ public final strictfp class DefaultScope
         metadata.setOther(null);
         assertNull("other",   metadata.getOther());
         assertNull("dataset", metadata.getDataset());
+        loggings.assertNoUnexpectedLogging(1);
     }
 }

Modified: sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/spatial/DefaultGeorectifiedTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/spatial/DefaultGeorectifiedTest.java?rev=1730054&r1=1730053&r2=1730054&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/spatial/DefaultGeorectifiedTest.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/spatial/DefaultGeorectifiedTest.java [UTF-8] Fri Feb 12 16:21:45 2016
@@ -37,21 +37,11 @@ import static org.apache.sis.test.Assert
  */
 public final strictfp class DefaultGeorectifiedTest extends TestCase {
     /**
-     * A JUnit {@linkplain Rule rule} for listening to log events. This field is public
-     * because JUnit requires us to do so, but should be considered as an implementation
-     * details (it should have been a private field).
+     * A JUnit {@link Rule} for listening to log events. This field is public because JUnit requires us to
+     * do so, but should be considered as an implementation details (it should have been a private field).
      */
     @Rule
-    public final LoggingWatcher listener = new LoggingWatcher(Context.LOGGER) {
-        /**
-         * Ensures that the logging message contains the name of the exclusive properties.
-         */
-        @Override
-        protected void verifyMessage(final String message) {
-            assertTrue(message.contains("checkPointAvailability"));
-            assertTrue(message.contains("checkPointDescription"));
-        }
-    };
+    public final LoggingWatcher loggings = new LoggingWatcher(Context.LOGGER);
 
     /**
      * Tests {@link DefaultGeorectified#isCheckPointAvailable()} and
@@ -66,14 +56,17 @@ public final strictfp class DefaultGeore
         // Setting the description shall set automatically the availability.
         metadata.setCheckPointDescription(description);
         assertTrue("checkPointAvailability", metadata.isCheckPointAvailable());
+        loggings.assertNoUnexpectedLogging(0);
 
         // Setting the availability flag shall hide the description and logs a message.
-        listener.maximumLogCount = 1;
         metadata.setCheckPointAvailable(false);
         assertNull("checkPointDescription", metadata.getCheckPointDescription());
+        loggings.assertLoggingContains(0, "checkPointDescription", "checkPointAvailability");
+        loggings.assertNoUnexpectedLogging(1);
 
         // Setting the availability flag shall bring back the description.
         metadata.setCheckPointAvailable(true);
         assertSame("checkPointDescription", description, metadata.getCheckPointDescription());
+        loggings.assertNoUnexpectedLogging(1);
     }
 }

Modified: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/internal/jaxb/referencing/CC_GeneralOperationParameterTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/internal/jaxb/referencing/CC_GeneralOperationParameterTest.java?rev=1730054&r1=1730053&r2=1730054&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/internal/jaxb/referencing/CC_GeneralOperationParameterTest.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/internal/jaxb/referencing/CC_GeneralOperationParameterTest.java [UTF-8] Fri Feb 12 16:21:45 2016
@@ -31,7 +31,6 @@ import org.apache.sis.test.XMLTestCase;
 import org.apache.sis.test.DependsOn;
 import org.apache.sis.test.DependsOnMethod;
 import org.apache.sis.test.LoggingWatcher;
-import org.apache.sis.util.logging.Logging;
 import org.junit.Rule;
 import org.junit.Test;
 
@@ -52,19 +51,14 @@ import static org.junit.Assert.*;
 public final strictfp class CC_GeneralOperationParameterTest extends XMLTestCase {
     /**
      * A JUnit rule for listening to log events emitted during execution of {@link #testGroupMergeBecauseExtraParameter()}.
-     * This rule verifies that the log message contains the expected information. The expected message is something like
-     * "No parameter named "Parameter B" was found".
+     * This rule is used by test methods for verifying that the log message contains the expected information.
+     * The expected message is something like "No parameter named "Parameter B" was found".
      *
      * <p>This field is public because JUnit requires us to do so, but should be considered as an implementation details
      * (it should have been a private field).</p>
      */
     @Rule
-    public final LoggingWatcher listener = new LoggingWatcher(Logging.getLogger(Loggers.XML)) {
-        @Override protected void verifyMessage(final String message) {
-            assertTrue(message, message.contains("Parameter B"));
-            assertTrue(message, message.contains("Group"));
-        }
-    };
+    public final LoggingWatcher loggings = new LoggingWatcher(Loggers.XML);
 
     /**
      * Creates a parameter descriptor as unmarshalled by JAXB, without {@code valueClass}.
@@ -139,6 +133,8 @@ public final strictfp class CC_GeneralOp
 
         provided = unmarshal("Optional parameter", "More details here.");
         assertSame("With same remark.", complete, CC_GeneralOperationParameter.merge(provided, complete));
+
+        loggings.assertNoUnexpectedLogging(0);
     }
 
     /**
@@ -172,6 +168,7 @@ public final strictfp class CC_GeneralOp
         assertEquals ("maximumOccurs",     1,                     merged.getMaximumOccurs());
         assertEquals ("valueClass",        Integer.class,         merged.getValueClass());
         assertSame   ("remarks",           provided.getRemarks(), merged.getRemarks());
+        loggings.assertNoUnexpectedLogging(0);
     }
 
     /**
@@ -198,6 +195,7 @@ public final strictfp class CC_GeneralOp
                 create("Parameter D", "Remarks D.", false, 6));
 
         assertSame(complete, CC_GeneralOperationParameter.merge(provided, complete));
+        loggings.assertNoUnexpectedLogging(0);
     }
 
     /**
@@ -239,6 +237,7 @@ public final strictfp class CC_GeneralOp
         verifyParameter(itc.next(), itm.next(), false, "Remarks C.");   // Not same because different remarks.
         assertTrue ("Missing descriptor.",    itc.hasNext());
         assertFalse("Unexpected descriptor.", itm.hasNext());
+        loggings.assertNoUnexpectedLogging(0);
     }
 
     /**
@@ -281,6 +280,7 @@ public final strictfp class CC_GeneralOp
         verifyParameter(itc.next(), itm.next(), true, null);
         assertFalse("Unexpected descriptor.", itc.hasNext());
         assertFalse("Unexpected descriptor.", itm.hasNext());
+        loggings.assertNoUnexpectedLogging(0);
     }
 
     /**
@@ -305,7 +305,7 @@ public final strictfp class CC_GeneralOp
                 create("Parameter A", "Remarks A.", false, 3),
                 create("Parameter C", "Remarks C.", false, 4));
 
-        listener.maximumLogCount = 1;
+        loggings.assertNoUnexpectedLogging(0);
         final ParameterDescriptorGroup merged =
                 (ParameterDescriptorGroup) CC_GeneralOperationParameter.merge(provided, complete);
         assertNotSame(complete, provided);
@@ -313,6 +313,8 @@ public final strictfp class CC_GeneralOp
         assertSame   ("remarks",       complete.getRemarks(), merged.getRemarks());
         assertEquals ("minimumOccurs", 1,                     merged.getMinimumOccurs());
         assertEquals ("maximumOccurs", 2,                     merged.getMaximumOccurs());
+        loggings.assertLoggingContains(0, "Parameter B", "Group");
+        loggings.assertNoUnexpectedLogging(1);
 
         final Iterator<GeneralParameterDescriptor> itc = complete.descriptors().iterator();
         final Iterator<GeneralParameterDescriptor> itm = merged  .descriptors().iterator();
@@ -325,6 +327,7 @@ public final strictfp class CC_GeneralOp
         verifyParameter(itc.next(), itm.next(), true, "Remarks C.");
         assertFalse("Unexpected descriptor.", itc.hasNext());
         assertFalse("Unexpected descriptor.", itm.hasNext());
+        loggings.assertNoUnexpectedLogging(1);
     }
 
     /**

Modified: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/AuthorityFactoriesTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/AuthorityFactoriesTest.java?rev=1730054&r1=1730053&r2=1730054&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/AuthorityFactoriesTest.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/AuthorityFactoriesTest.java [UTF-8] Fri Feb 12 16:21:45 2016
@@ -24,7 +24,6 @@ import org.opengis.referencing.crs.CRSAu
 import org.opengis.referencing.crs.CoordinateReferenceSystem;
 import org.opengis.referencing.crs.GeographicCRS;
 import org.apache.sis.util.ComparisonMode;
-import org.apache.sis.util.logging.Logging;
 import org.apache.sis.internal.system.Loggers;
 import org.apache.sis.internal.util.Constants;
 import org.apache.sis.referencing.crs.HardCodedCRS;
@@ -51,27 +50,11 @@ import static org.apache.sis.test.Assert
  */
 public final strictfp class AuthorityFactoriesTest extends TestCase {
     /**
-     * A JUnit {@linkplain Rule rule} for listening to log events. This field is public because JUnit requires
-     * us to do so, but should be considered as an implementation details (it should have been a private field).
+     * A JUnit {@link Rule} for listening to log events. This field is public because JUnit requires us to
+     * do so, but should be considered as an implementation details (it should have been a private field).
      */
     @Rule
-    public final LoggingWatcher listener = new Listener();
-
-    /**
-     * Implementation of the {@link AuthorityFactoriesTest#listener} rule.
-     */
-    private static final class Listener extends LoggingWatcher {
-        /** The logged message. */
-        String message;
-
-        /** Creates a new log listener. */
-        Listener() {super(Logging.getLogger(Loggers.CRS_FACTORY));}
-
-        /** Stores the log message. */
-        @Override protected void verifyMessage(final String message) {
-            this.message = message;
-        }
-    }
+    public final LoggingWatcher loggings = new LoggingWatcher(Loggers.CRS_FACTORY);
 
     /**
      * Tests creation of {@code CRS:84} from various codes.
@@ -96,6 +79,7 @@ public final strictfp class AuthorityFac
         assertSame(crs, CRS.forCode("OGC:CRS84"));
 
         assertNotDeepEquals(crs, CRS.forCode("CRS:83"));
+        loggings.assertNoUnexpectedLogging(0);
     }
 
     /**
@@ -108,25 +92,25 @@ public final strictfp class AuthorityFac
     public void testVersionedEPSG() throws FactoryException {
         final CRSAuthorityFactory factory = AuthorityFactories.ALL;
         final GeographicCRS crs = factory.createGeographicCRS("EPSG:4326");
+        loggings.assertNoUnexpectedLogging(0);
 
-        listener.maximumLogCount = 1;
         assertSame(crs, factory.createGeographicCRS("urn:ogc:def:crs:EPSG:6.11.2:4326"));
         assertSame(crs, factory.createGeographicCRS("urn:ogc:def:crs:EPSG:6.11.2:4326"));
-        String message = ((Listener) listener).message;
-        assertTrue(message, message.contains("6.11.2"));
+        loggings.assertLoggingContains(0, "6.11.2");
+        loggings.assertNoUnexpectedLogging(1);
 
-        listener.maximumLogCount = 1;
+        loggings.messages.clear();
         assertSame(crs, factory.createGeographicCRS("urn:ogc:def:crs:EPSG:7.04:4326"));
-        message = ((Listener) listener).message;
-        assertTrue(message, message.contains("7.04"));
+        loggings.assertLoggingContains(0, "7.04");
+        loggings.assertNoUnexpectedLogging(1);
 
-        listener.maximumLogCount = 1;
+        loggings.messages.clear();
         assertSame(crs, factory.createGeographicCRS("urn:ogc:def:crs:EPSG:7.10:4326"));
-        message = ((Listener) listener).message;
-        assertTrue(message, message.contains("7.10"));
+        loggings.assertLoggingContains(0, "7.10");
+        loggings.assertNoUnexpectedLogging(1);
 
-        assertEquals(0, listener.maximumLogCount);
         assertSame(crs, factory.createGeographicCRS("urn:ogc:def:crs:EPSG::4326"));
+        loggings.assertNoUnexpectedLogging(1);
     }
 
     /**
@@ -171,6 +155,7 @@ public final strictfp class AuthorityFac
             // This is the expected exception.
             assertEquals("FOO", exception.getAuthority());
         }
+        loggings.assertNoUnexpectedLogging(0);
     }
 
     /**
@@ -207,6 +192,7 @@ public final strictfp class AuthorityFac
         } catch (NoSuchAuthorityCodeException e) {
             assertNotNull(e.getMessage());
         }
+        loggings.assertNoUnexpectedLogging(0);
     }
 
     /**
@@ -221,6 +207,7 @@ public final strictfp class AuthorityFac
         assertFalse(codes.isEmpty());
         assertTrue(codes.contains("CRS:84"));
         assertTrue(codes.contains("AUTO:42001") || codes.contains("AUTO2:42001"));
+        loggings.assertNoUnexpectedLogging(0);
     }
 
     /**
@@ -236,5 +223,6 @@ public final strictfp class AuthorityFac
         assertNotNull("With scan allowed, should find the CRS.", find);
         assertTrue(HardCodedCRS.WGS84.equals(find, ComparisonMode.DEBUG));
         assertSame(factory.createCoordinateReferenceSystem("CRS:84"), find);
+        loggings.assertNoUnexpectedLogging(0);
     }
 }

Modified: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/crs/DefaultProjectedCRSTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/crs/DefaultProjectedCRSTest.java?rev=1730054&r1=1730053&r2=1730054&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/crs/DefaultProjectedCRSTest.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/crs/DefaultProjectedCRSTest.java [UTF-8] Fri Feb 12 16:21:45 2016
@@ -33,7 +33,6 @@ import org.apache.sis.internal.referenci
 import org.apache.sis.internal.util.Constants;
 import org.apache.sis.internal.system.Loggers;
 import org.apache.sis.io.wkt.Convention;
-import org.apache.sis.util.logging.Logging;
 import org.apache.sis.util.ComparisonMode;
 import org.apache.sis.util.LenientComparable;
 
@@ -64,19 +63,15 @@ import static org.apache.sis.test.Refere
 public final strictfp class DefaultProjectedCRSTest extends XMLTestCase {
     /**
      * A JUnit rule for listening to log events emitted during execution of {@link #testWKT1_WithExplicitAxisLength()}.
-     * This rule verifies that the message logged contains the expected information. The expected message is something
-     * like "Parameter semi_minor could have been omitted but got a value that does not match the WGS84 ellipsoid".
+     * This rule is used by the test methods for verifying that the logged messages contain the expected information.
+     * The expected message is something like "Parameter semi_minor could have been omitted but got a value that does
+     * not match the WGS84 ellipsoid".
      *
      * <p>This field is public because JUnit requires us to do so, but should be considered as an implementation details
      * (it should have been a private field).</p>
      */
     @Rule
-    public final LoggingWatcher listener = new LoggingWatcher(Logging.getLogger(Loggers.COORDINATE_OPERATION)) {
-        @Override protected void verifyMessage(final String message) {
-            assertTrue(message, message.contains("semi_minor"));
-            assertTrue(message, message.contains("WGS84"));
-        }
-    };
+    public final LoggingWatcher loggings = new LoggingWatcher(Loggers.COORDINATE_OPERATION);
 
     /**
      * An XML file in this package containing a projected CRS definition.
@@ -132,6 +127,8 @@ public final strictfp class DefaultProje
                 "  AXIS[“Northing”, NORTH],\n" +
                 "  AUTHORITY[“EPSG”, “27572”]]",
                 crs);
+
+        loggings.assertNoUnexpectedLogging(0);
     }
 
     /**
@@ -163,6 +160,8 @@ public final strictfp class DefaultProje
                 "  AXIS[“Northing”, NORTH],\n" +
                 "  AUTHORITY[“EPSG”, “27572”]]",
                 crs);
+
+        loggings.assertNoUnexpectedLogging(0);
     }
 
     /**
@@ -197,6 +196,8 @@ public final strictfp class DefaultProje
                 "  AXIS[“Northing”, NORTH],\n" +
                 "  AUTHORITY[“EPSG”, “27572”]]",
                 crs);
+
+        loggings.assertNoUnexpectedLogging(0);
     }
 
     /**
@@ -234,6 +235,8 @@ public final strictfp class DefaultProje
                 "    Unit[“metre”, 1, Id[“EPSG”, 9001]],\n" +
                 "  Id[“EPSG”, 27572]]",
                 crs);
+
+        loggings.assertNoUnexpectedLogging(0);
     }
 
     /**
@@ -265,6 +268,8 @@ public final strictfp class DefaultProje
                 "    Unit[“metre”, 1],\n" +
                 "  Id[“EPSG”, 27572, URI[“urn:ogc:def:crs:EPSG::27572”]]]",
                 crs);
+
+        loggings.assertNoUnexpectedLogging(0);
         /*
          * Try again, but with mixed units. It should force the formatter to add explicit
          * unit declaration in PrimeMeridian[…] and some Parameter[…] elements.
@@ -290,6 +295,8 @@ public final strictfp class DefaultProje
                 "    Unit[“metre”, 1],\n" +
                 "  Id[“EPSG”, 27572, URI[“urn:ogc:def:crs:EPSG::27572”]]]",
                 crs);
+
+        loggings.assertNoUnexpectedLogging(0);
     }
 
     /**
@@ -322,6 +329,8 @@ public final strictfp class DefaultProje
                 "  ID[“EPSG”, 27572, URI[“urn:ogc:def:crs:EPSG::27572”]]]",
                 crs);
 
+        loggings.assertNoUnexpectedLogging(0);
+
         assertWktEquals(Convention.WKT2_SIMPLIFIED,
                 "ProjectedCRS[“NTF (Paris) / Lambert zone II”,\n" +
                 "  BaseGeodCRS[“NTF (Paris)”,\n" +
@@ -342,6 +351,8 @@ public final strictfp class DefaultProje
                 "    Unit[“metre”, 1],\n" +
                 "  Id[“EPSG”, 27572, URI[“urn:ogc:def:crs:EPSG::27572”]]]",
                 crs);
+
+        loggings.assertNoUnexpectedLogging(0);
     }
 
     /**
@@ -356,7 +367,6 @@ public final strictfp class DefaultProje
     @Test
     @DependsOnMethod("testWKT1")
     public void testWKT1_WithExplicitAxisLength() throws FactoryException {
-        listener.maximumLogCount = 1;
         final ProjectedCRS crs = new GeodeticObjectBuilder()
                 .setConversionMethod("Mercator (variant A)")
                 .setConversionName("Popular Visualisation Pseudo-Mercator")
@@ -386,7 +396,8 @@ public final strictfp class DefaultProje
                 "  AXIS[“Northing”, NORTH]]",
                 crs);
 
-        assertEquals("A warning should have been logged.", 0, listener.maximumLogCount);
+        loggings.assertLoggingContains(0, "semi_minor", "WGS84");
+        loggings.assertNoUnexpectedLogging(1);
     }
 
     /**
@@ -424,6 +435,8 @@ public final strictfp class DefaultProje
                 "    Axis[“Northing (N)”, north],\n" +
                 "    Unit[“metre”, 1]]",
                 crs);
+
+        loggings.assertNoUnexpectedLogging(0);
     }
 
     /**
@@ -459,6 +472,8 @@ public final strictfp class DefaultProje
          */
         assertMarshalEqualsFile(XML_FILE, crs, STRICT, new String[] {"gml:name"},
                 new String[] {"xmlns:*", "xsi:schemaLocation", "gml:id"});
+
+        loggings.assertNoUnexpectedLogging(0);
     }
 
     /**
@@ -478,5 +493,6 @@ public final strictfp class DefaultProje
         assertTrue ("IGNORE_METADATA", ((LenientComparable) standard).equals(normalized, ComparisonMode.IGNORE_METADATA));
         assertTrue ("APPROXIMATIVE",   ((LenientComparable) standard).equals(normalized, ComparisonMode.APPROXIMATIVE));
         assertTrue ("ALLOW_VARIANT",   ((LenientComparable) standard).equals(normalized, ComparisonMode.ALLOW_VARIANT));
+        loggings.assertNoUnexpectedLogging(0);
     }
 }

Modified: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/factory/MultiAuthoritiesFactoryTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/factory/MultiAuthoritiesFactoryTest.java?rev=1730054&r1=1730053&r2=1730054&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/factory/MultiAuthoritiesFactoryTest.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/factory/MultiAuthoritiesFactoryTest.java [UTF-8] Fri Feb 12 16:21:45 2016
@@ -39,7 +39,6 @@ import org.apache.sis.internal.system.Lo
 import org.apache.sis.metadata.iso.extent.Extents;
 import org.apache.sis.referencing.crs.HardCodedCRS;
 import org.apache.sis.referencing.datum.HardCodedDatum;
-import org.apache.sis.util.logging.Logging;
 import org.apache.sis.test.LoggingWatcher;
 import org.apache.sis.test.DependsOnMethod;
 import org.apache.sis.test.DependsOn;
@@ -61,29 +60,11 @@ import static org.apache.sis.test.Assert
 @DependsOn(AuthorityFactoryProxyTest.class)
 public final strictfp class MultiAuthoritiesFactoryTest extends TestCase {
     /**
-     * A JUnit {@linkplain Rule rule} for listening to log events. This field is public because JUnit requires
-     * us to do so, but should be considered as an implementation details (it should have been a private field).
+     * A JUnit {@link Rule} for listening to log events. This field is public because JUnit requires us to
+     * do so, but should be considered as an implementation details (it should have been a private field).
      */
     @Rule
-    public final LoggingWatcher listener = new Listener();
-
-    /**
-     * Implementation of the {@link MultiAuthoritiesFactoryTest#listener} rule.
-     */
-    private static final class Listener extends LoggingWatcher {
-        /** Expected keywords in the log message. */
-        String[] expectedKeywords;
-
-        /** Creates a new log listener. */
-        Listener() {super(Logging.getLogger(Loggers.CRS_FACTORY));}
-
-        /** Verifies the log message. */
-        @Override protected void verifyMessage(final String message) {
-            for (final String keyword : expectedKeywords) {
-                assertTrue(message, message.contains(keyword));
-            }
-        }
-    }
+    public final LoggingWatcher loggings = new LoggingWatcher(Loggers.CRS_FACTORY);
 
     /**
      * Tests consistency of the mock factory used by other tests in this class.
@@ -110,6 +91,7 @@ public final strictfp class MultiAuthori
                 assertInstanceOf(code, type, factory.createObject(code));
             }
         }
+        loggings.assertNoUnexpectedLogging(0);
     }
 
     /**
@@ -124,6 +106,7 @@ public final strictfp class MultiAuthori
                 Arrays.asList(mock1, mock2), null,
                 Arrays.asList(mock1, mock3), null);
         assertSetEquals(Arrays.asList("MOCK1", "MOCK2", "MOCK3"), factory.getCodeSpaces());
+        loggings.assertNoUnexpectedLogging(0);
     }
 
     /**
@@ -161,6 +144,7 @@ public final strictfp class MultiAuthori
             assertTrue(message, message.contains("MOCK1"));
             assertTrue(message, message.contains("9.9"));
         }
+        loggings.assertNoUnexpectedLogging(0);
     }
 
     /**
@@ -182,20 +166,21 @@ public final strictfp class MultiAuthori
 
         assertSame("MOCK1", mock1, factory.getAuthorityFactory(CRSAuthorityFactory.class, "mock1", null));
         assertSame("MOCK1", mock1, factory.getAuthorityFactory(CRSAuthorityFactory.class, "mock1", "2.3"));
+        loggings.assertNoUnexpectedLogging(0);
 
-        listener.maximumLogCount = 1;
-        ((Listener) listener).expectedKeywords = new String[] {"CRSAuthorityFactory", "AuthorityFactoryMock", "MOCK1", "2.3"};
         assertSame("MOCK3", mock3, factory.getAuthorityFactory(CRSAuthorityFactory.class, "mock3", null));
-        assertEquals("Expected a warning about the extraneous MOCK1 factory.", 0, listener.maximumLogCount);
+        loggings.assertLoggingContains(0, "CRSAuthorityFactory", "AuthorityFactoryMock", "MOCK1", "2.3");
+        loggings.assertNoUnexpectedLogging(1);
 
-        listener.maximumLogCount = 1;
-        ((Listener) listener).expectedKeywords = new String[] {"CRSAuthorityFactory", "AuthorityFactoryMock", "MOCK3"};
+        loggings.messages.clear();
         assertSame("MOCK5", mock5, factory.getAuthorityFactory(CRSAuthorityFactory.class, "mock5", null));
-        assertEquals("Expected a warning about the extraneous MOCK3 factory.", 0, listener.maximumLogCount);
+        loggings.assertLoggingContains(0, "CRSAuthorityFactory", "AuthorityFactoryMock", "MOCK3");
+        loggings.assertNoUnexpectedLogging(1);
 
         // Ask again the same factories. No logging should be emitted now, because we already logged.
         assertSame("MOCK3", mock3, factory.getAuthorityFactory(CRSAuthorityFactory.class, "mock3", null));
         assertSame("MOCK5", mock5, factory.getAuthorityFactory(CRSAuthorityFactory.class, "mock5", null));
+        loggings.assertNoUnexpectedLogging(1);
     }
 
     /**
@@ -226,6 +211,7 @@ public final strictfp class MultiAuthori
             final String message = e.getMessage();
             assertTrue(message, message.contains("MOCK2"));
         }
+        loggings.assertNoUnexpectedLogging(0);
     }
 
     /**
@@ -255,6 +241,7 @@ public final strictfp class MultiAuthori
             assertTrue(message, message.contains("datum"));
             assertTrue(message, message.contains("GeographicCRS"));
         }
+        loggings.assertNoUnexpectedLogging(0);
     }
 
     /**
@@ -281,6 +268,7 @@ public final strictfp class MultiAuthori
             assertTrue(message, message.contains("crs"));
             assertTrue(message, message.contains("Datum"));
         }
+        loggings.assertNoUnexpectedLogging(0);
     }
 
     /**
@@ -304,6 +292,7 @@ public final strictfp class MultiAuthori
         assertFalse("MOCK:6326", codes.contains("MOCK:6326"));      // A geodetic datum.
         assertFalse("isEmpty()", codes.isEmpty());
         assertArrayEquals(new String[] {"MOCK:4979", "MOCK:84", "MOCK:4326", "MOCK:5714", "MOCK:9905"}, codes.toArray());
+        loggings.assertNoUnexpectedLogging(0);
     }
 
     /**
@@ -325,10 +314,9 @@ public final strictfp class MultiAuthori
         /*
          * Following should log a warning telling that the authority factories do not match.
          */
-        listener.maximumLogCount = 1;
-        ((Listener) listener).expectedKeywords = new String[] {"MOCK:4326", "MOCK:2.3:84"};
         assertTrue(factory.createFromCoordinateReferenceSystemCodes("MOCK:4326", "MOCK:2.3:84").isEmpty());
-        assertEquals("Expected a warning about mismatched factories.", 0, listener.maximumLogCount);
+        loggings.assertLoggingContains(0, "MOCK:4326", "MOCK:2.3:84");
+        loggings.assertNoUnexpectedLogging(1);
     }
 
     /**
@@ -344,5 +332,6 @@ public final strictfp class MultiAuthori
         final MultiAuthoritiesFactory factory = new MultiAuthoritiesFactory(mock, null, mock, null);
         final IdentifiedObjectFinder finder = factory.newIdentifiedObjectFinder();
         assertSame(HardCodedDatum.WGS72, finder.findSingleton(HardCodedDatum.WGS72));
+        loggings.assertNoUnexpectedLogging(0);
     }
 }

Modified: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/factory/sql/EPSGFactoryTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/factory/sql/EPSGFactoryTest.java?rev=1730054&r1=1730053&r2=1730054&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/factory/sql/EPSGFactoryTest.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/factory/sql/EPSGFactoryTest.java [UTF-8] Fri Feb 12 16:21:45 2016
@@ -130,29 +130,11 @@ public final strictfp class EPSGFactoryT
     }
 
     /**
-     * Words that we expect to find in each log messages to be emitted.
-     */
-    private String[][] expectedLogWords;
-
-    /**
-     * A JUnit {@linkplain Rule rule} for listening to log events. This field is public
-     * because JUnit requires us to do so, but should be considered as an implementation
-     * details (it should have been a private field).
+     * A JUnit {@link Rule} for listening to log events. This field is public because JUnit requires us to
+     * do so, but should be considered as an implementation details (it should have been a private field).
      */
     @Rule
-    public final LoggingWatcher listener = new LoggingWatcher(Logging.getLogger(Loggers.CRS_FACTORY)) {
-        /**
-         * Ensures that the logging message contains some expected words.
-         */
-        @Override
-        protected void verifyMessage(final String message) {
-            if (expectedLogWords != null) {
-                for (final String word : expectedLogWords[expectedLogWords.length - (maximumLogCount + 1)]) {
-                    assertTrue(message, message.contains(word));
-                }
-            }
-        }
-    };
+    public final LoggingWatcher loggings = new LoggingWatcher(Loggers.CRS_FACTORY);
 
     /**
      * Tests {@link EPSGDataAccess#tableMatches(String, String)}.
@@ -161,6 +143,7 @@ public final strictfp class EPSGFactoryT
     public void testTableMatches() {
         assertTrue(EPSGDataAccess.tableMatches("Coordinate_Operation",          "epsg_coordoperation"));
         assertTrue(EPSGDataAccess.tableMatches("[Coordinate Reference System]", "epsg_coordinatereferencesystem"));
+        loggings.assertNoUnexpectedLogging(0);
     }
 
     /**
@@ -181,6 +164,7 @@ public final strictfp class EPSGFactoryT
 
         assertSame("CRS shall be cached", crs, factory.createCoordinateReferenceSystem("4326"));
         assertSame("Shall accept \"::\"", crs, factory.createGeographicCRS("EPSG::4326"));
+        loggings.assertNoUnexpectedLogging(0);
     }
 
     /**
@@ -201,6 +185,7 @@ public final strictfp class EPSGFactoryT
         assertTrue("Expected a transformation to WGS84.", bwp.length >= 1);
 
         assertSame("CRS shall be cached", crs, factory.createCoordinateReferenceSystem("4274"));
+        loggings.assertNoUnexpectedLogging(0);
     }
 
     /**
@@ -219,6 +204,7 @@ public final strictfp class EPSGFactoryT
                 AxisDirection.NORTH, AxisDirection.EAST, AxisDirection.UP);
 
         assertSame("CRS shall be cached", crs, factory.createCoordinateReferenceSystem("4993"));
+        loggings.assertNoUnexpectedLogging(0);
     }
 
     /**
@@ -236,6 +222,7 @@ public final strictfp class EPSGFactoryT
                 AxisDirection.GEOCENTRIC_X, AxisDirection.GEOCENTRIC_Y, AxisDirection.GEOCENTRIC_Z);
 
         assertSame("CRS shall be cached", crs, factory.createCoordinateReferenceSystem("4915"));
+        loggings.assertNoUnexpectedLogging(0);
     }
 
     /**
@@ -257,6 +244,7 @@ public final strictfp class EPSGFactoryT
         verifyTransverseMercatorParmeters(crs.getConversionFromBase().getParameterValues(), -93);
 
         assertSame("CRS shall be cached", crs, factory.createCoordinateReferenceSystem("2027"));
+        loggings.assertNoUnexpectedLogging(0);
     }
 
     /**
@@ -302,6 +290,7 @@ public final strictfp class EPSGFactoryT
         assertEquals("false_northing",         0, parameters.parameter("false_northing"    ).doubleValue(), STRICT);
 
         assertSame("CRS shall be cached", crs, factory.createCoordinateReferenceSystem("2442"));
+        loggings.assertNoUnexpectedLogging(0);
     }
 
     /**
@@ -340,6 +329,7 @@ public final strictfp class EPSGFactoryT
 
         assertNotDeepEquals(crs.getConversionFromBase(), variant.getConversionFromBase());
         assertNotDeepEquals(crs, variant);
+        loggings.assertNoUnexpectedLogging(0);
     }
 
     /**
@@ -369,6 +359,7 @@ public final strictfp class EPSGFactoryT
         assertSame(crs, factory.createObject("NTF (Paris) / Lambert zone I"));
         assertSame(crs, factory.createProjectedCRS("NTF Paris Lambert zone I"));
         assertSame(crs, factory.createObject("NTF Paris Lambert zone I"));
+        loggings.assertNoUnexpectedLogging(0);
     }
 
     /**
@@ -390,6 +381,7 @@ public final strictfp class EPSGFactoryT
         // TODO: test axis directions.
 
         assertSame("CRS shall be cached", crs, factory.createCoordinateReferenceSystem("3408"));
+        loggings.assertNoUnexpectedLogging(0);
     }
 
     /**
@@ -408,6 +400,7 @@ public final strictfp class EPSGFactoryT
         assertAxisDirectionsEqual("EPSG::4499", crs.getCoordinateSystem(), AxisDirection.EAST, AxisDirection.NORTH);
 
         assertSame("CRS shall be cached", crs, factory.createCoordinateReferenceSystem("3857"));
+        loggings.assertNoUnexpectedLogging(0);
     }
 
     /**
@@ -423,6 +416,7 @@ public final strictfp class EPSGFactoryT
         assertEpsgNameAndIdentifierEqual("Barcelona", 9301, crs.getDatum());
         assertAxisDirectionsEqual("EPSG::4500", crs.getCoordinateSystem(), AxisDirection.NORTH, AxisDirection.EAST);
         assertSame("CRS shall be cached", crs, factory.createCoordinateReferenceSystem("5801"));
+        loggings.assertNoUnexpectedLogging(0);
     }
 
     /**
@@ -438,6 +432,7 @@ public final strictfp class EPSGFactoryT
         assertEpsgNameAndIdentifierEqual("Black Sea", 5134, crs.getDatum());
         assertSame("CRS shall be cached", crs, factory.createCoordinateReferenceSystem("5735"));
         assertAxisDirectionsEqual("EPSG::6499", crs.getCoordinateSystem(), AxisDirection.UP);
+        loggings.assertNoUnexpectedLogging(0);
     }
 
     /**
@@ -469,6 +464,7 @@ public final strictfp class EPSGFactoryT
         assertEquals("eastBoundLongitude",  8.23, bbox.getEastBoundLongitude(), STRICT);
 
         assertSame("CRS shall be cached", crs, factory.createCoordinateReferenceSystem("7400"));
+        loggings.assertNoUnexpectedLogging(0);
     }
 
     /**
@@ -482,17 +478,14 @@ public final strictfp class EPSGFactoryT
     public void testDeprecatedGeographic() throws FactoryException {
         assumeNotNull(factory);
 
-        listener.maximumLogCount = 2;
-        expectedLogWords = new String[][] {
-            {"EPSG:6405"},                      // Coordinate System 6405 is no longer supported by EPSG
-            {"EPSG:63266405", "4326"}           // EPSG no longer support codes in the 60000000 series.
-        };
-
         final GeographicCRS crs = factory.createGeographicCRS("63266405");
         assertEpsgNameAndIdentifierEqual("WGS 84 (deg)", 63266405, crs);
         assertAxisDirectionsEqual(null, crs.getCoordinateSystem(), AxisDirection.NORTH, AxisDirection.EAST);
-
         assertSame("CRS shall be cached", crs, factory.createCoordinateReferenceSystem("63266405"));
+
+        loggings.assertLoggingContains(0, "EPSG:6405");                 // Coordinate System 6405 is no longer supported by EPSG
+        loggings.assertLoggingContains(1, "EPSG:63266405", "4326");     // EPSG no longer support codes in the 60000000 series.
+        loggings.assertNoUnexpectedLogging(2);
     }
 
     /**
@@ -506,18 +499,15 @@ public final strictfp class EPSGFactoryT
     public void testDeprecatedProjected() throws FactoryException {
         assumeNotNull(factory);
 
-        listener.maximumLogCount = 3;
-        expectedLogWords = new String[][] {
-            {"EPSG:9823",  "1029"},              // Operation method 9823 has been replaced by 1029
-            {"EPSG:19968", "4086"},              // Coordinate Operation 19968 has been replaced by 4086
-            {"EPSG:3786",  "4088"}               // Coordinate Reference System 3786 has been replaced by 4088
-        };
-
         final ProjectedCRS crs = factory.createProjectedCRS("3786");
         assertEpsgNameAndIdentifierEqual("World Equidistant Cylindrical (Sphere)", 3786, crs);
         assertEpsgNameAndIdentifierEqual("Equidistant Cylindrical (Spherical)", 9823, crs.getConversionFromBase().getMethod());
         assertAxisDirectionsEqual("EPSG::4499", crs.getCoordinateSystem(), AxisDirection.EAST, AxisDirection.NORTH);
-        assertEquals("All warnings should have been logged at this point.", 0, listener.maximumLogCount);
+
+        loggings.assertLoggingContains(0, "EPSG:9823",  "1029");    // Operation method 9823 has been replaced by 1029
+        loggings.assertLoggingContains(1, "EPSG:19968", "4086");    // Coordinate Operation 19968 has been replaced by 4086
+        loggings.assertLoggingContains(2, "EPSG:3786",  "4088");    // Coordinate Reference System 3786 has been replaced by 4088
+        loggings.assertNoUnexpectedLogging(3);
 
         final ProjectedCRS replacement = factory.createProjectedCRS("4088");
         assertEpsgNameAndIdentifierEqual("World Equidistant Cylindrical (Sphere)", 4088, replacement);
@@ -528,6 +518,8 @@ public final strictfp class EPSGFactoryT
 
         assertSame("CRS shall be cached", crs, factory.createCoordinateReferenceSystem("3786"));
         assertSame("CRS shall be cached", replacement, factory.createCoordinateReferenceSystem("4088"));
+
+        loggings.assertNoUnexpectedLogging(3);
     }
 
     /**
@@ -560,6 +552,7 @@ public final strictfp class EPSGFactoryT
             // This is the expected exception.
             assertEquals("WGS83", e.getAuthorityCode());
         }
+        loggings.assertNoUnexpectedLogging(0);
     }
 
     /**
@@ -726,6 +719,8 @@ public final strictfp class EPSGFactoryT
         @SuppressWarnings({"unchecked","rawtypes"})
         final Class<? extends IdentifiedObject> wrong = (Class) String.class;
         assertTrue("Dummy type", factory.getAuthorityCodes(wrong).isEmpty());
+
+        loggings.assertNoUnexpectedLogging(0);
     }
 
     /**
@@ -742,6 +737,7 @@ public final strictfp class EPSGFactoryT
         assertEquals("NTF (Paris) / Nord France",  factory.getDescriptionText("27591").toString(Locale.US));
         assertEquals("NTF (Paris) / France II",    factory.getDescriptionText("27582").toString(Locale.US));
         assertEquals("Ellipsoidal height",         factory.getDescriptionText(   "84").toString(Locale.US));
+        loggings.assertNoUnexpectedLogging(0);
     }
 
     /**
@@ -798,6 +794,7 @@ public final strictfp class EPSGFactoryT
             factory.printCacheContent(out);
             throw error;
         }
+        loggings.assertNoUnexpectedLogging(0);
     }
 
     /**
@@ -811,8 +808,9 @@ public final strictfp class EPSGFactoryT
         assumeNotNull(factory);
         final CoordinateOperation operation = factory.createCoordinateOperation("1764");
         assertEpsgNameAndIdentifierEqual("NTF (Paris) to NTF (2)", 1764, operation);
-        assertInstanceOf("EPSG::1764", Transformation.class, operation);
+        assertInstanceOf("EPSG:1764", Transformation.class, operation);
         assertSame("Operation shall be cached", operation, factory.createCoordinateOperation("1764"));
+        loggings.assertNoUnexpectedLogging(0);
     }
 
     /**
@@ -830,6 +828,7 @@ public final strictfp class EPSGFactoryT
         assertEpsgNameAndIdentifierEqual("BD72 to WGS 84 (1)", 1609, operation);
         assertEquals(1.0, ((AbstractCoordinateOperation) operation).getLinearAccuracy(), STRICT);
         assertSame("Operation shall be cached", operation, factory.createCoordinateOperation("1609"));
+        loggings.assertNoUnexpectedLogging(0);
     }
 
     /**
@@ -894,7 +893,6 @@ public final strictfp class EPSGFactoryT
         assertTrue("contains(“EPSG::1989”)", all.contains(operation3));
 
         int count = 0;
-        listener.maximumLogCount = all.size();              // Ignore log message for unsupported operation methods.
         for (final CoordinateOperation tr : all) {
             assertSame("sourceCRS", sourceCRS, tr.getSourceCRS());
             assertSame("targetCRS", targetCRS, tr.getTargetCRS());
@@ -951,6 +949,7 @@ public final strictfp class EPSGFactoryT
          */
         finder.setSearchDomain(IdentifiedObjectFinder.Domain.DECLARATION);
         assertSame("The CRS should still in the cache.", found, finder.findSingleton(crs));
+        loggings.assertNoUnexpectedLogging(0);
     }
 
     /**
@@ -1005,5 +1004,6 @@ public final strictfp class EPSGFactoryT
         assertEpsgNameAndIdentifierEqual("Beijing 1954 / 3-degree Gauss-Kruger CM 135E",  2442, it.next());
         assertEpsgNameAndIdentifierEqual("Beijing 1954 / Gauss-Kruger CM 135E", 21463, it.next());
         assertFalse("Expected no more element.", it.hasNext());
+        loggings.assertNoUnexpectedLogging(0);
     }
 }

Modified: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/factory/sql/EPSGInstallerTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/factory/sql/EPSGInstallerTest.java?rev=1730054&r1=1730053&r2=1730054&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/factory/sql/EPSGInstallerTest.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/factory/sql/EPSGInstallerTest.java [UTF-8] Fri Feb 12 16:21:45 2016
@@ -31,7 +31,6 @@ import org.opengis.referencing.crs.Geogr
 import org.opengis.referencing.crs.ProjectedCRS;
 import org.apache.sis.referencing.CommonCRS;
 import org.apache.sis.internal.system.Loggers;
-import org.apache.sis.util.logging.Logging;
 import org.apache.sis.util.ComparisonMode;
 import org.apache.sis.util.Utilities;
 
@@ -65,22 +64,13 @@ import static org.junit.Assume.*;
 public final strictfp class EPSGInstallerTest extends TestCase {
     /**
      * A JUnit rule for listening to log events emitted during execution of tests.
-     * This rule verifies that the log message contains the expected information.
+     * This rule is used by tests that verifies the log message content.
      *
      * <p>This field is public because JUnit requires us to do so, but should be considered
      * as an implementation details (it should have been a private field).</p>
      */
     @Rule
-    public final LoggingWatcher listener = new LoggingWatcher(Logging.getLogger(Loggers.CRS_FACTORY)) {
-        @Override protected void verifyMessage(final String message) {
-            log = message;      // Verified later by the tests in the enclosing class.
-        }
-    };
-
-    /**
-     * The logging message caught by the {@link #listener}.
-     */
-    private String log;
+    public final LoggingWatcher loggings = new LoggingWatcher(Loggers.CRS_FACTORY);
 
     /**
      * Tests the {@link EPSGInstaller#REPLACE_STATEMENT} pattern.
@@ -106,6 +96,8 @@ public final strictfp class EPSGInstalle
         assertTrue(Pattern.matches(EPSGInstaller.REPLACE_STATEMENT,
                 "UPDATE epsg.\"Coordinate Axis\"\n" +
                 "SET coord_axis_orientation = replace(coord_axis_orientation, CHR(182), CHR(10))"));
+
+        loggings.assertNoUnexpectedLogging(0);
     }
 
     /**
@@ -134,8 +126,8 @@ public final strictfp class EPSGInstalle
         } finally {
             TestDatabase.drop(ds);
         }
-        assertTrue(log, log.contains("EPSG"));
-        assertTrue(log, log.contains("jdbc:derby:memory:test"));
+        loggings.assertLoggingContains(0, "EPSG", "jdbc:derby:memory:test");
+        loggings.assertNoUnexpectedLogging(1);
     }
 
     /**
@@ -161,8 +153,8 @@ public final strictfp class EPSGInstalle
                 s.execute("SHUTDOWN");
             }
         }
-        assertTrue(log, log.contains("EPSG"));
-        assertTrue(log, log.contains("jdbc:hsqldb:mem:test"));
+        loggings.assertLoggingContains(0, "EPSG", "jdbc:hsqldb:mem:test");
+        loggings.assertNoUnexpectedLogging(1);
     }
 
     /**
@@ -172,12 +164,12 @@ public final strictfp class EPSGInstalle
     private void createAndTest(final DataSource ds, final InstallationScriptProvider scriptProvider)
             throws SQLException, FactoryException
     {
-        listener.maximumLogCount = 100;
         final Map<String,Object> properties = new HashMap<>();
         assertNull(properties.put("dataSource", ds));
         assertNull(properties.put("scriptProvider", scriptProvider));
         assertEquals("Should not contain EPSG tables before we created them.", 0, countCRSTables(ds));
-        assertEquals("Should not yet have logged anything at this point.", 100, listener.maximumLogCount);
+        loggings.assertNoUnexpectedLogging(0);  // Should not yet have logged anything at this point.
+
         try (EPSGFactory factory = new EPSGFactory(properties)) {
             /*
              * Fetch the "WGS 84" coordinate reference system.
@@ -208,7 +200,6 @@ public final strictfp class EPSGInstalle
             assertFalse("4329", codes.contains("4329"));
         }
         assertEquals("Should contain EPSG tables after we created them.", 1, countCRSTables(ds));
-        assertEquals("Should have logged a message about the database creation.", 99, listener.maximumLogCount);
     }
 
     /**

Modified: sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/test/LoggingWatcher.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/test/LoggingWatcher.java?rev=1730054&r1=1730053&r2=1730054&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/test/LoggingWatcher.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/test/LoggingWatcher.java [UTF-8] Fri Feb 12 16:21:45 2016
@@ -16,6 +16,8 @@
  */
 package org.apache.sis.test;
 
+import java.util.List;
+import java.util.ArrayList;
 import java.util.logging.Filter;
 import java.util.logging.Logger;
 import java.util.logging.LogRecord;
@@ -27,44 +29,39 @@ import static org.junit.Assert.*;
 
 
 /**
- * Watches the logs sent to the given logger. Logs will be allowed only if the test was
- * expected to cause some logging events to occur, otherwise a test failure will occurs.
- *
- * <div class="note">Usage example</div>
- * Create a rule in the JUnit test class like below:
+ * Watches the logs sent to the given logger.
+ * For using, create a rule in the JUnit test class like below:
  *
  * {@preformat java
  *     &#64;Rule
- *     public final LoggingWatcher listener = new LoggingWatcher(Logging.getLogger(Loggers.XML)) {
- *         &#64;Override protected void verifyMessage(final String message) {
- *             assertTrue(message.contains("An expected word in the logging message"));
- *         }
- *     };
+ *     public final LoggingWatcher loggings = new LoggingWatcher(Logging.getLogger(Loggers.XML));
+ * }
+ *
+ * In every tests that do not expect loggings, invoke the following method last:
+ *
+ * {@preformat java
+ *     loggings.assertNoUnexpectedLogging(0);
  * }
  *
- * Then, <em>only</em> in the test which are expected to emit a warning, add the following line
+ * In tests that are expected to emit warnings, add the following lines
  * (replace 1 by a higher value if more than one logging is expected):
  *
  * {@preformat java
- *     listener.maximumLogCount = 1;
+ *     // Do the test here.
+ *     loggings.assertLoggingContains(0, "Some keywords that are expected to be found in the message");
+ *     loggings.assertNoUnexpectedLogging(1);
  * }
  *
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.6
- * @version 0.6
+ * @version 0.7
  * @module
  */
-public strictfp class LoggingWatcher extends TestWatcher implements Filter {
+public final strictfp class LoggingWatcher extends TestWatcher implements Filter {
     /**
-     * The maximal number of logs expected by the test. If this value is positive, then it is
-     * decremented when {@link #isLoggable(LogRecord)} is invoked until the value reach zero.
-     * If the value is zero and {@code isLoggable(LogRecord)} is invoked, then a test failure
-     * occurs.
-     *
-     * <p>The initial value of this field is 0. Test cases shall set this field to a non-zero
-     * value in order to allow log events.</p>
+     * The logged messages.
      */
-    public int maximumLogCount;
+    public final List<String> messages = new ArrayList<>();
 
     /**
      * The logger to watch.
@@ -87,6 +84,15 @@ public strictfp class LoggingWatcher ext
     }
 
     /**
+     * Creates a new watcher for the given logger.
+     *
+     * @param logger The name of logger to watch.
+     */
+    public LoggingWatcher(final String logger) {
+        this.logger = Logger.getLogger(logger);
+    }
+
+    /**
      * Invoked when a test is about to start. This method installs this {@link Filter}
      * for the log messages before the tests are run. This installation will cause the
      * {@link #isLoggable(LogRecord)} method to be invoked when a message is logged.
@@ -99,7 +105,6 @@ public strictfp class LoggingWatcher ext
     protected final void starting(final Description description) {
         assertNull(logger.getFilter());
         logger.setFilter(this);
-        maximumLogCount = 0;
     }
 
     /**
@@ -114,26 +119,42 @@ public strictfp class LoggingWatcher ext
     }
 
     /**
-     * Invoked (indirectly) when a tested method has emitted a log message. This method verifies
-     * if we were expecting a log message, then decrements the {@link #maximumLogCount} value.
+     * Invoked (indirectly) when a tested method has emitted a log message.
+     * This method adds the logging message to the {@link #messages} list.
      */
     @Override
     public final boolean isLoggable(final LogRecord record) {
-        if (maximumLogCount <= 0) {
-            fail("Unexpected logging:\n" + formatter.format(record));
-        }
-        maximumLogCount--;
-        verifyMessage(formatter.formatMessage(record));
+        messages.add(formatter.formatMessage(record));
         return TestCase.VERBOSE;
     }
 
     /**
-     * Invoked by {@link #isLoggable(LogRecord)} when a tested method has emitted a log message.
-     * The default implementation does nothing. Subclasses can override this method in order to
-     * perform additional check.
+     * Verifies that a logging message exists at the given index and contains the given keywords.
+     *
+     * @param index    Index of the logging message to verify.
+     * @param keywords The keywords that we are expected to find in the logging message.
+     */
+    public void assertLoggingContains(final int index, final String... keywords) {
+        final int size = messages.size();
+        if (index >= size) {
+            fail("Expected at least " + (index + 1) + " logging messages but got " + size);
+        }
+        final String message = messages.get(index);
+        for (final String word : keywords) {
+            if (!message.contains(word)) {
+                fail("Expected the logging message to contains the “"+ word + "” word but got:\n" + message);
+            }
+        }
+    }
+
+    /**
+     * Verifies that no more than {@code maxCount} messages have been logged.
      *
-     * @param message The logging message.
+     * @param maxCount The maximum number of logging messages.
      */
-    protected void verifyMessage(final String message) {
+    public void assertNoUnexpectedLogging(final int maxCount) {
+        if (messages.size() > maxCount) {
+            fail("Unexpected logging message: " + messages.get(maxCount));
+        }
     }
 }



Mime
View raw message