<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>
<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>
import junit.framework.TestCase;
import org.apache.oro.io.AwkFilenameFilter;
-import org.wamblee.test.ResettableMock;
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;
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() {
_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.
+++ /dev/null
-/**
- *
- */
-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
import java.util.Arrays;
-import org.hibernate.annotations.common.reflection.ReflectionUtil;
import org.wamblee.reflection.ReflectionUtils;
public class DefaultRequiredInterface implements RequiredInterface {