support/general no longer depends on hibernate-jpa
authorErik Brakkee <erik@brakkee.org>
Sat, 3 Apr 2010 20:03:15 +0000 (20:03 +0000)
committerErik Brakkee <erik@brakkee.org>
Sat, 3 Apr 2010 20:03:15 +0000 (20:03 +0000)
pom.xml
support/general/pom.xml
support/general/src/test/java/org/wamblee/io/DirectoryMonitorTest.java
support/general/src/test/java/org/wamblee/test/ResettableMock.java [deleted file]
system/general/src/main/java/org/wamblee/system/core/DefaultRequiredInterface.java

diff --git a/pom.xml b/pom.xml
index 2885b4b8ab3037d9f9f01f1500558ae603f01ef6..06e2aeb8f5673b6ce70b165368cee797de21ff2d 100644 (file)
--- a/pom.xml
+++ b/pom.xml
@@ -22,7 +22,6 @@
         <dependency>
             <groupId>junit</groupId>
             <artifactId>junit</artifactId>
-            <version>4.4</version>
             <scope>test</scope>
         </dependency>
         <dependency>
     </dependencies>
 
     <dependencyManagement>
-        <dependencies>
-            
+        <dependencies> 
+               
+                 <dependency>
+            <groupId>oro</groupId>
+            <artifactId>oro</artifactId>
+            <version>2.0.6</version>
+          </dependency>
+
+               
+            <dependency>
+              <groupId>javax.transaction</groupId>
+              <artifactId>transaction-api</artifactId>
+              <version>1.1</version>
+            </dependency>
+
+            <dependency>
+              <groupId>junit</groupId>
+              <artifactId>junit</artifactId>
+              <version>4.4</version>
+            </dependency>
             <dependency>
                 <groupId>org.dbunit</groupId>
                 <artifactId>dbunit</artifactId>
index 90dec8da58e72c56336e2e51f9ed558ec28c6539..c07f8dc683e362d8ff341d481583d0ddd93cf0f9 100644 (file)
   <name>wamblee.org support general library</name>
   <url>http://wamblee.org</url>
   <dependencies>
+    <dependency>
+      <groupId>oro</groupId>
+      <artifactId>oro</artifactId>
+    </dependency>
     <dependency>
       <groupId>commons-logging</groupId>
       <artifactId>commons-logging</artifactId>
       <groupId>commons-beanutils</groupId>
       <artifactId>commons-beanutils</artifactId>
     </dependency>
-    <dependency>
-      <groupId>org.wamblee</groupId>
-      <artifactId>wamblee-hibernate-jpa</artifactId>
-      <version>0.2-SNAPSHOT</version>
-    </dependency>
     <!-- should be possible to remove the dependence on log4j -->
     <dependency>
       <groupId>log4j</groupId>
index 347857da528b1ef04905ab2a630c1c3f122cb5c3..12db916e78a9ea8615b6c4e1b7cc8d4b8b6bbfb1 100644 (file)
@@ -19,7 +19,6 @@ import static org.mockito.Mockito.*;
 import junit.framework.TestCase;
 
 import org.apache.oro.io.AwkFilenameFilter;
-import org.wamblee.test.ResettableMock;
 
 public class DirectoryMonitorTest extends TestCase {
 
@@ -27,7 +26,7 @@ public class DirectoryMonitorTest extends TestCase {
        private static final String FILE1 = "file1.txt";
 
        private TestData _data;
-       private ResettableMock<DirectoryMonitor.Listener> _listener;
+       private DirectoryMonitor.Listener _listener;
 
        private DirectoryMonitor _monitor;
 
@@ -36,50 +35,49 @@ public class DirectoryMonitorTest extends TestCase {
                super.setUp();
                _data = new TestData(this);
                _data.clean();
-               _listener = new ResettableMock<DirectoryMonitor.Listener>(
-                               DirectoryMonitor.Listener.class);
+               _listener = mock(DirectoryMonitor.Listener.class);
                _monitor = new DirectoryMonitor(_data.getRoot(), new AwkFilenameFilter(
-                               REGEX), _listener.getProxy());
+                               REGEX), _listener);
        }
 
        public void testEmptyDir() {
                // Nothing is expected to be called.
                for (int i = 0; i < 10; i++) {
                        _monitor.poll();
-                       verifyNoMoreInteractions(_listener.getMock());
+                       verifyNoMoreInteractions(_listener);
                }
        }
 
        public void testFileCreated() {
                _data.createFile(FILE1, "hello");
                _monitor.poll();
-               verify(_listener.getMock()).fileCreated(_data.getFile(FILE1));
+               verify(_listener).fileCreated(_data.getFile(FILE1));
        }
 
        public void testFileDeleted() {
                _data.createFile(FILE1, "hello");
                _monitor.poll();
-               _listener.reset();
+               reset(_listener);
 
                _data.deleteFile(FILE1);
                _monitor.poll();
 
-               verify(_listener.getMock()).fileDeleted(_data.getFile(FILE1));
-               verifyNoMoreInteractions(_listener.getMock());
+               verify(_listener).fileDeleted(_data.getFile(FILE1));
+               verifyNoMoreInteractions(_listener);
        }
 
        public void testFileChanged() throws InterruptedException {
                _data.createFile(FILE1, "hello");
                _monitor.poll();
-               _listener.reset();
+               reset(_listener);
 
                Thread.sleep(2000);
                _data.deleteFile(FILE1);
                _data.createFile(FILE1, "bla");
 
                _monitor.poll();
-               verify(_listener.getMock()).fileChanged(_data.getFile(FILE1));
-               verifyNoMoreInteractions(_listener.getMock());
+               verify(_listener).fileChanged(_data.getFile(FILE1));
+               verifyNoMoreInteractions(_listener);
        }
 
        public void testFileFilterIsUsed() {
@@ -87,34 +85,34 @@ public class DirectoryMonitorTest extends TestCase {
 
                _data.createFile("file.xml", "hello");
                _monitor.poll();
-               verifyNoMoreInteractions(_listener.getMock());
+               verifyNoMoreInteractions(_listener);
        }
 
        public void testDirectoryIsIgnored() {
                _monitor.poll();
                _data.createDir(FILE1);
                _monitor.poll();
-               verifyNoMoreInteractions(_listener.getMock());
+               verifyNoMoreInteractions(_listener);
        }
 
        public void testExceptionsWIllLeadToRepeatedNotifications() { 
                _monitor.poll();
                _data.createFile(FILE1, "hello");
                
-               stubVoid(_listener.getMock()).toThrow(new RuntimeException()).on().
+               stubVoid(_listener).toThrow(new RuntimeException()).on().
                 fileCreated(_data.getFile(FILE1));
                
                try { 
                    _monitor.poll();
                } catch (RuntimeException e) { 
-                       _listener.reset(); 
+                       reset(_listener); 
                        
                        // polling again should lead to the same filecreated call.
                        // this time no exception is thrown.
                        
                        _monitor.poll();
-                       verify(_listener.getMock()).fileCreated(_data.getFile(FILE1));
-                       verifyNoMoreInteractions(_listener.getMock());
+                       verify(_listener).fileCreated(_data.getFile(FILE1));
+                       verifyNoMoreInteractions(_listener);
                        return; 
                }
                fail(); // should not get here.
diff --git a/support/general/src/test/java/org/wamblee/test/ResettableMock.java b/support/general/src/test/java/org/wamblee/test/ResettableMock.java
deleted file mode 100644 (file)
index 4e32156..0000000
+++ /dev/null
@@ -1,112 +0,0 @@
-/**
- * 
- */
-package org.wamblee.test;
-
-import static org.mockito.Mockito.*;
-
-import java.lang.reflect.InvocationHandler;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.lang.reflect.Proxy;
-
-import net.sf.cglib.proxy.Enhancer;
-import net.sf.cglib.proxy.MethodInterceptor;
-import net.sf.cglib.proxy.MethodProxy;
-
-/**
- * Resettable mock is a utility to support reset functionality for mockito.
- * 
- * @author Erik Brakkee
- * 
- * @param <T>
- */
-public class ResettableMock<T> {
-
-    private static class MockitoInvocationHandler<T> implements
-            MethodInterceptor {
-
-        private Class<T> _class;
-        private T _mock;
-
-        public MockitoInvocationHandler(Class<T> aClass) {
-            _class = aClass;
-            _mock = mock(aClass);
-        }
-
-        public void reset() {
-            _mock = mock(_class);
-        }
-
-        public T getMock() {
-            return _mock;
-        }
-
-        @Override
-        public Object intercept(Object aProxy, Method aInterceptedMethod,
-                Object[] aArgs, MethodProxy aMethodProxy) throws Throwable {
-            try {
-                return aInterceptedMethod.invoke(_mock, aArgs);
-            } catch (InvocationTargetException e) {
-                throw e.getCause();
-            }
-        }
-    }
-
-    /**
-     * Invocation handler that delegates to the current mockito mock and allows
-     * creation of a new mock.
-     */
-    private ResettableMock.MockitoInvocationHandler<T> _handler;
-
-    /**
-     * Proxy object to be passed to tested classes.
-     */
-    private T _proxy;
-
-    /**
-     * Constructs the resettable mock.
-     * 
-     * @param aType
-     *            Type to mock. Must be an interface or a non-final class with a 
-     *            default constructor.
-     */
-    public ResettableMock(Class<T> aType) {
-        if (!aType.isInterface()) {
-            throw new IllegalArgumentException("Class '" + aType.getName()
-                    + "' must be an interface");
-        }
-        _handler = new MockitoInvocationHandler(aType);
-        Enhancer enhancer = new Enhancer();
-        enhancer.setSuperclass(aType);
-        enhancer.setCallback(_handler);
-        _proxy = (T) enhancer.create();
-    }
-
-    /**
-     * Resets the mock effectively forgetting all previous interactions and
-     * verifications.
-     */
-    public void reset() {
-        _handler.reset();
-    }
-
-    /**
-     * Gets the current mock object to pass to mockito calls.
-     * 
-     * @return Mock object.
-     */
-    public T getMock() {
-        return _handler.getMock();
-    }
-
-    /**
-     * Returns the proxy that your tested classes will used.
-     * 
-     * @return Proxy object.
-     */
-    public T getProxy() {
-        return _proxy;
-    }
-
-}
\ No newline at end of file
index 2983ca6f4796007a95241e4b6a807c0dc94eb8c5..4e0db74be375620f8f60dd5b383a2e1a5017de32 100644 (file)
@@ -17,7 +17,6 @@ package org.wamblee.system.core;
 
 import java.util.Arrays;
 
-import org.hibernate.annotations.common.reflection.ReflectionUtil;
 import org.wamblee.reflection.ReflectionUtils;
 
 public class DefaultRequiredInterface implements RequiredInterface {