Fixed test by moving Delegate to its own file

This commit is contained in:
Ramnivas Laddad 2009-10-27 17:38:50 +00:00
parent 064343d056
commit dee410c0c4
2 changed files with 74 additions and 62 deletions

View File

@ -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();
}
}

View File

@ -145,65 +145,3 @@ public class JUnitStaticEntityMockingControlTest {
}
}
// Used because verification failures occur after method returns,
// so we can't test for them in the test case itself
@MockStaticEntityMethods
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();
}
}