From e7327ee620f451ef9230f5113ce8b5818aa970fc Mon Sep 17 00:00:00 2001
From: erik <erik@77661180-640e-0410-b3a8-9f9b13e6d0e0>
Date: Sat, 29 Mar 2008 22:54:06 +0000
Subject: [PATCH] Seitched to using easymock because 1. it is easier (less
 typing) 2. it is more flexible in defining the order in which methods are
 invoked on objects and between objects.

---
 trunk/pom.xml                                 | 20 +-----
 .../org/wamblee/observer/ObservableTest.java  | 64 ++++++++++---------
 2 files changed, 36 insertions(+), 48 deletions(-)

diff --git a/trunk/pom.xml b/trunk/pom.xml
index 3626101e..f423fd83 100644
--- a/trunk/pom.xml
+++ b/trunk/pom.xml
@@ -32,23 +32,9 @@
             <scope>test</scope>
         </dependency>
         <dependency>
-            <groupId>org.jmock</groupId>
-            <artifactId>jmock</artifactId>
-            <version>${jmock.version}</version>
-            <scope>test</scope>
-        </dependency>
-        <dependency>
-            <groupId>org.jmock</groupId>
-            <artifactId>jmock-junit4</artifactId>
-            <version>${jmock.version}</version>
-            <scope>test</scope>
-        </dependency>
-
-        <dependency>
-            <groupId>org.jmock</groupId>
-            <artifactId>jmock-legacy</artifactId>
-            <version>${jmock.version}</version>
-            <scope>test</scope>
+            <groupId>org.easymock</groupId>
+            <artifactId>easymock</artifactId>
+            <version>2.3</version>
         </dependency>
     </dependencies>
 
diff --git a/trunk/support/src/test/java/org/wamblee/observer/ObservableTest.java b/trunk/support/src/test/java/org/wamblee/observer/ObservableTest.java
index 8ea3e587..ff37ccb9 100644
--- a/trunk/support/src/test/java/org/wamblee/observer/ObservableTest.java
+++ b/trunk/support/src/test/java/org/wamblee/observer/ObservableTest.java
@@ -16,13 +16,18 @@
 
 package org.wamblee.observer;
 
+import static org.easymock.EasyMock.createControl;
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.createStrictMock;
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.verify;
+
 import java.util.ArrayList;
 import java.util.List;
 
 import junit.framework.TestCase;
 
-import org.jmock.Expectations;
-import org.jmock.Mockery;
+import org.easymock.IMocksControl;
 
 /**
  * Test of the observer pattern implementation.
@@ -37,7 +42,6 @@ public class ObservableTest extends TestCase {
 
 	private Integer _observed;
 	private Observable<Integer, String> _observable;
-	private Mockery _context;
 
 	/*
 	 * (non-Javadoc)
@@ -50,28 +54,24 @@ public class ObservableTest extends TestCase {
 		_observed = new Integer(1);
 		_observable = new Observable<Integer, String>(_observed,
 				new DefaultObserverNotifier());
-		_context = new Mockery();
-
 	}
 
 	/**
 	 * Tests subscription and notification of one subscriber.
 	 */
 	public void testOneObserver() {
-		final Observer observer = _context.mock(Observer.class);
-		long subscription = _observable.subscribe(observer);
+		final Observer mockObserver = createStrictMock(Observer.class);
+		long subscription = _observable.subscribe(mockObserver);
 
 		assertEquals(1, _observable.getObserverCount());
 
 		final String message = "hallo";
-		_context.checking(new Expectations() {
-			{
-				one(observer).send(_observed, message);
-			}
-		});
+		mockObserver.send(_observed, message);
+		replay(mockObserver);
 
 		_observable.send(message);
-		_context.assertIsSatisfied();
+		verify(mockObserver);
+
 		_observable.unsubscribe(subscription);
 		assertEquals(0, _observable.getObserverCount());
 
@@ -88,9 +88,11 @@ public class ObservableTest extends TestCase {
 		final int nsubscribers = SUBSCRIBER_COUNT;
 		final Observer[] mocks = new Observer[nsubscribers];
 
+		IMocksControl control = createControl();
+
 		List<Long> subscriptions = new ArrayList<Long>();
 		for (int i = 0; i < nsubscribers; i++) {
-			mocks[i] = _context.mock(Observer.class, "" + i);
+			mocks[i] = control.createMock("mock" + i, Observer.class);
 			long subscription = _observable.subscribe(mocks[i]);
 			assertTrue(subscriptions.add(subscription));
 		}
@@ -98,16 +100,14 @@ public class ObservableTest extends TestCase {
 		assertEquals(nsubscribers, _observable.getObserverCount());
 
 		final String message = "hallo";
-		_context.checking(new Expectations() {
-			{
-				for (int i = 0; i < nsubscribers; i++) {
-					one(mocks[i]).send(_observed, message);
-				}
-			}
-		});
+
+		for (int i = 0; i < nsubscribers; i++) {
+			mocks[i].send(_observed, message);
+		}
+		control.replay();
 
 		_observable.send(message);
-		_context.assertIsSatisfied();
+		control.verify();
 
 		for (int i = nsubscribers / 2; i < nsubscribers; i++) {
 			_observable.unsubscribe(subscriptions.get(i));
@@ -115,16 +115,16 @@ public class ObservableTest extends TestCase {
 		assertEquals(nsubscribers - (nsubscribers - nsubscribers / 2),
 				_observable.getObserverCount());
 
+		control.reset();
 		final String message2 = "blabla";
-		_context.checking(new Expectations() {
-			{
-				for (int i = 0; i < nsubscribers / 2; i++) {
-					one(mocks[i]).send(_observed, message2);
-				}
-			}
-		});
+
+		for (int i = 0; i < nsubscribers / 2; i++) {
+			mocks[i].send(_observed, message2);
+		}
+		control.replay();
+
 		_observable.send(message2);
-		_context.assertIsSatisfied();
+		control.verify();
 	}
 
 	/**
@@ -133,7 +133,9 @@ public class ObservableTest extends TestCase {
 	 * 
 	 */
 	public void testUnsubscribeWithWrongSubscription() {
-		Observer<Integer, String> observer = _context.mock(Observer.class);
+		Observer<Integer, String> observer = createMock(Observer.class);
+		replay(observer);
+		
 		long subscription = _observable.subscribe(observer);
 
 		assertEquals(1, _observable.getObserverCount());
-- 
2.31.1