cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r1099201 - in /cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access: MockTransactionDelegate.java UserTransactionTest.java
Date Tue, 03 May 2011 19:08:51 GMT
Author: aadamchik
Date: Tue May  3 19:08:50 2011
New Revision: 1099201

URL: http://svn.apache.org/viewvc?rev=1099201&view=rev
Log:
unit tests - refactoring mocks use

Removed:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/MockTransactionDelegate.java
Modified:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/UserTransactionTest.java

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/UserTransactionTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/UserTransactionTest.java?rev=1099201&r1=1099200&r2=1099201&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/UserTransactionTest.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/UserTransactionTest.java
Tue May  3 19:08:50 2011
@@ -19,6 +19,14 @@
 
 package org.apache.cayenne.access;
 
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.atLeast;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
 import java.sql.Connection;
 
 import org.apache.cayenne.ObjectContext;
@@ -31,50 +39,27 @@ import org.apache.cayenne.unit.di.server
 public class UserTransactionTest extends ServerCase {
 
     @Inject
-    protected ObjectContext context;
+    private ObjectContext context;
 
     public void testCommit() throws Exception {
 
         Artist a = context.newObject(Artist.class);
         a.setArtistName("AAA");
 
-        final boolean[] willAddConnectionCalled = new boolean[1];
-        final boolean[] willCommitCalled = new boolean[1];
-        final boolean[] didCommitCalled = new boolean[1];
-
-        TransactionDelegate delegate = new MockTransactionDelegate() {
-
-            @Override
-            public boolean willAddConnection(
-                    Transaction transaction,
-                    Connection connection) {
-                willAddConnectionCalled[0] = true;
-                return true;
-            }
-
-            @Override
-            public boolean willCommit(Transaction transaction) {
-                willCommitCalled[0] = true;
-                return true;
-            }
+        TransactionDelegate delegate = mock(TransactionDelegate.class);
+        Transaction t = Transaction.internalTransaction(delegate);
 
-            @Override
-            public void didCommit(Transaction transaction) {
-                didCommitCalled[0] = true;
-            }
-        };
+        when(delegate.willAddConnection(eq(t), any(Connection.class))).thenReturn(true);
+        when(delegate.willCommit(t)).thenReturn(true);
 
-        Transaction t = Transaction.internalTransaction(delegate);
         Transaction.bindThreadTransaction(t);
 
         try {
             context.commitChanges();
 
-            assertTrue("User transaction was ignored", willAddConnectionCalled[0]);
-            assertFalse(
-                    "User transaction was unexpectedly committed",
-                    willCommitCalled[0]);
-            assertFalse("User transaction was unexpectedly committed", didCommitCalled[0]);
+            verify(delegate, atLeast(1)).willAddConnection(eq(t), any(Connection.class));
+            verify(delegate, never()).willCommit(eq(t));
+            verify(delegate, never()).didCommit(eq(t));
         }
         finally {
 
@@ -86,6 +71,5 @@ public class UserTransactionTest extends
             }
             Transaction.bindThreadTransaction(null);
         }
-
     }
 }



Mime
View raw message