From b104d6aeab5242cd03098e220a5652554c9d73b5 Mon Sep 17 00:00:00 2001 From: erik Date: Sat, 3 Apr 2010 20:03:15 +0000 Subject: [PATCH] support/general no longer depends on hibernate-jpa --- pom.xml | 23 +++- support/general/pom.xml | 9 +- .../org/wamblee/io/DirectoryMonitorTest.java | 36 +++--- .../java/org/wamblee/test/ResettableMock.java | 112 ------------------ .../system/core/DefaultRequiredInterface.java | 1 - 5 files changed, 41 insertions(+), 140 deletions(-) delete mode 100644 support/general/src/test/java/org/wamblee/test/ResettableMock.java diff --git a/pom.xml b/pom.xml index 2885b4b8..06e2aeb8 100644 --- a/pom.xml +++ b/pom.xml @@ -22,7 +22,6 @@ junit junit - 4.4 test @@ -78,8 +77,26 @@ - - + + + + oro + oro + 2.0.6 + + + + + javax.transaction + transaction-api + 1.1 + + + + junit + junit + 4.4 + org.dbunit dbunit diff --git a/support/general/pom.xml b/support/general/pom.xml index 90dec8da..c07f8dc6 100644 --- a/support/general/pom.xml +++ b/support/general/pom.xml @@ -15,6 +15,10 @@ wamblee.org support general library http://wamblee.org + + oro + oro + commons-logging commons-logging @@ -38,11 +42,6 @@ commons-beanutils commons-beanutils - - org.wamblee - wamblee-hibernate-jpa - 0.2-SNAPSHOT - log4j diff --git a/support/general/src/test/java/org/wamblee/io/DirectoryMonitorTest.java b/support/general/src/test/java/org/wamblee/io/DirectoryMonitorTest.java index 347857da..12db916e 100644 --- a/support/general/src/test/java/org/wamblee/io/DirectoryMonitorTest.java +++ b/support/general/src/test/java/org/wamblee/io/DirectoryMonitorTest.java @@ -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 _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.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 index 4e321566..00000000 --- a/support/general/src/test/java/org/wamblee/test/ResettableMock.java +++ /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 - */ -public class ResettableMock { - - private static class MockitoInvocationHandler implements - MethodInterceptor { - - private Class _class; - private T _mock; - - public MockitoInvocationHandler(Class 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 _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 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 diff --git a/system/general/src/main/java/org/wamblee/system/core/DefaultRequiredInterface.java b/system/general/src/main/java/org/wamblee/system/core/DefaultRequiredInterface.java index 2983ca6f..4e0db74b 100644 --- a/system/general/src/main/java/org/wamblee/system/core/DefaultRequiredInterface.java +++ b/system/general/src/main/java/org/wamblee/system/core/DefaultRequiredInterface.java @@ -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 { -- 2.31.1