Index: core/xwiki-shared-tests/src/main/java/org/xwiki/test/AbstractGarbageCollectableVerifyingTestCase.java
===================================================================
--- core/xwiki-shared-tests/src/main/java/org/xwiki/test/AbstractGarbageCollectableVerifyingTestCase.java	(revision 0)
+++ core/xwiki-shared-tests/src/main/java/org/xwiki/test/AbstractGarbageCollectableVerifyingTestCase.java	(revision 0)
@@ -0,0 +1,120 @@
+/*
+ * See the NOTICE file distributed with this work for additional
+ * information regarding copyright ownership.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.xwiki.test;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import junit.framework.TestCase;
+import org.jmock.util.Verifier;
+import org.jmock.core.Verifiable;
+import org.jmock.cglib.MockObjectTestCase;
+
+/**
+ * Override methods in VerifyingTestCase so that objectsThatRequireVerification won't keep holding references to objects
+ * which should be garbage collected.
+ *
+ * @version $Id$
+ * @since 2.3M1
+ */
+public abstract class AbstractGarbageCollectableVerifyingTestCase extends MockObjectTestCase
+{
+    /** Same functionality as VerifyingTestCase.objectsThatRequireVerification but is garbaged at teardown. */
+    private List<Verifiable> objectsThatRequireVerification = new ArrayList<Verifiable>();
+
+    /**
+     * Simple constructor.
+     */
+    public AbstractGarbageCollectableVerifyingTestCase()
+    {
+        super();
+    }
+
+    /**
+     * Constructor with name given.
+     *
+     * @param testName The name to give this test.
+     */
+    public AbstractGarbageCollectableVerifyingTestCase(String testName)
+    {
+        super(testName);
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @see org.jmock.cglib.MockObjectTestCase#registerToVerify(Verifiable)
+     */
+    public void runBare() throws Throwable {
+        setUp();
+        try {
+            runTest();
+            verify();
+        }
+        finally {
+            tearDown();
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @see org.jmock.cglib.MockObjectTestCase#registerToVerify(Verifiable)
+     */
+    public void registerToVerify(Verifiable verifiable)
+    {
+        objectsThatRequireVerification.add(verifiable);
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @see org.jmock.cglib.MockObjectTestCase#unregisterToVerify(Verifiable)
+     */
+    public void unregisterToVerify(Verifiable verifiable)
+    {
+        objectsThatRequireVerification.remove(verifiable);
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @see org.jmock.cglib.MockObjectTestCase#verify()
+     */
+    public void verify()
+    {
+        for (Iterator iterator = objectsThatRequireVerification.iterator(); iterator.hasNext();) {
+            Verifiable verifiable = (Verifiable) iterator.next();
+            verifiable.verify();
+        }
+        Verifier.verifyObject(this);
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @see org.jmock.cglib.MockObjectTestCase#tearDown()
+     */
+    @Override
+    protected void tearDown() throws Exception
+    {
+        objectsThatRequireVerification = null;
+    }
+}

Property changes on: core/xwiki-shared-tests/src/main/java/org/xwiki/test/AbstractGarbageCollectableVerifyingTestCase.java
___________________________________________________________________
Name: svn:keywords
   + Author Id Revision HeadURL
Name: svn:eol-style
   + native

Index: core/xwiki-shared-tests/src/main/java/org/xwiki/test/AbstractXWikiComponentTestCase.java
===================================================================
--- core/xwiki-shared-tests/src/main/java/org/xwiki/test/AbstractXWikiComponentTestCase.java	(revision 27504)
+++ core/xwiki-shared-tests/src/main/java/org/xwiki/test/AbstractXWikiComponentTestCase.java	(working copy)
@@ -26,7 +26,7 @@
  * Tests which needs to have XWiki Components set up should extend this class which makes the Component Manager
  * available. Use this class for JUnit 3.x tests. For Junit 4.x tests use {@link AbstractComponentTestCase} instead.
  */
-public abstract class AbstractXWikiComponentTestCase extends MockObjectTestCase
+public abstract class AbstractXWikiComponentTestCase extends AbstractGarbageCollectableVerifyingTestCase
 {
     private XWikiComponentInitializer initializer = new XWikiComponentInitializer();
 
@@ -75,6 +75,7 @@
     protected void tearDown() throws Exception
     {
         this.initializer.shutdown();
+        super.tearDown();
     }
 
     /**
