Browse Source
git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@2203 50f2f4bb-b051-0410-bef5-90022cba6387pull/1/head
2 changed files with 74 additions and 62 deletions
@ -0,0 +1,74 @@
@@ -0,0 +1,74 @@
|
||||
package org.springframework.mock.static_mock; |
||||
|
||||
import java.rmi.RemoteException; |
||||
|
||||
import javax.persistence.PersistenceException; |
||||
|
||||
import junit.framework.Assert; |
||||
|
||||
import org.junit.Ignore; |
||||
import org.junit.Test; |
||||
|
||||
//Used because verification failures occur after method returns,
|
||||
//so we can't test for them in the test case itself
|
||||
@MockStaticEntityMethods |
||||
@Ignore // This isn't meant for direct testing; rather it is driven from JUnintStaticEntityMockingControlTest
|
||||
public class Delegate { |
||||
|
||||
@Test |
||||
public void testArgMethodNoMatchExpectReturn() { |
||||
long id = 13; |
||||
Person found = new Person(); |
||||
Person.findPerson(id); |
||||
JUnitStaticEntityMockingControl.expectReturn(found); |
||||
JUnitStaticEntityMockingControl.playback(); |
||||
Assert.assertEquals(found, Person.findPerson(id + 1)); |
||||
} |
||||
|
||||
@Test |
||||
public void testArgMethodNoMatchExpectThrow() { |
||||
long id = 13; |
||||
Person found = new Person(); |
||||
Person.findPerson(id); |
||||
JUnitStaticEntityMockingControl.expectThrow(new PersistenceException()); |
||||
JUnitStaticEntityMockingControl.playback(); |
||||
Assert.assertEquals(found, Person.findPerson(id + 1)); |
||||
} |
||||
|
||||
@Test |
||||
public void failTooFewCalls() { |
||||
long id = 13; |
||||
Person found = new Person(); |
||||
Person.findPerson(id); |
||||
JUnitStaticEntityMockingControl.expectReturn(found); |
||||
Person.countPeople(); |
||||
JUnitStaticEntityMockingControl.expectReturn(25); |
||||
JUnitStaticEntityMockingControl.playback(); |
||||
Assert.assertEquals(found, Person.findPerson(id)); |
||||
} |
||||
|
||||
@Test |
||||
public void doesntEverReplay() { |
||||
Person.countPeople(); |
||||
} |
||||
|
||||
@Test |
||||
public void doesntEverSetReturn() { |
||||
Person.countPeople(); |
||||
JUnitStaticEntityMockingControl.playback(); |
||||
} |
||||
|
||||
@Test |
||||
public void rejectUnexpectedCall() { |
||||
JUnitStaticEntityMockingControl.playback(); |
||||
Person.countPeople(); |
||||
} |
||||
|
||||
@Test(expected=RemoteException.class) |
||||
public void testVerificationFailsEvenWhenTestFailsInExpectedManner() throws RemoteException { |
||||
Person.countPeople(); |
||||
JUnitStaticEntityMockingControl.playback(); |
||||
// No calls to allow verification failure
|
||||
throw new RemoteException(); |
||||
} |
||||
} |
||||
Loading…
Reference in new issue