(no commit message)
authorErik Brakkee <erik@brakkee.org>
Thu, 22 Jul 2010 23:22:41 +0000 (23:22 +0000)
committerErik Brakkee <erik@brakkee.org>
Thu, 22 Jul 2010 23:22:41 +0000 (23:22 +0000)
wicket/joe/src/test/java/org/wamblee/wicket/model/DetachableEntityTest.java

index e4cf731711bc897dea589c919ae96a2ca9550ce5..3346be63e0ad23ef30ae1c49b13aaab5843d957d 100644 (file)
@@ -28,22 +28,27 @@ public class DetachableEntityTest {
         
     }
     
+    private X initialValue; 
     private Detachable<X> detachable;
     private DetachableEntity<X> entity; 
     
     @Before
     public void setUp() { 
+        initialValue = mock(X.class);
         detachable = mock(Detachable.class);
+        when(detachable.get()).thenReturn(initialValue);
         entity = new DetachableEntity<X>(detachable);
     }
 
     @Test
     public void testGetObject() {
         X x = new X(); 
+        reset(detachable);
         when(detachable.get()).thenReturn(x);
         X value = entity.getObject();
-        assertSame(x, value);
-        verify(detachable).get();
+        // we did not detach it yet so the old value should be returned.
+        assertSame(initialValue, value);
+        verifyNoMoreInteractions(detachable);
     }
 
     @Test
@@ -51,9 +56,12 @@ public class DetachableEntityTest {
         X x = new X(); 
         when(detachable.get()).thenReturn(x);
         
-        entity.onDetach();
+        entity.detach();
         verify(detachable).detach();
         
+        reset(detachable);
+        when(detachable.get()).thenReturn(x);
+        
         X y = entity.getObject();
         assertSame(x, y); 
         verify(detachable).get();