Browse Source

Fixed test by moving Delegate to its own file

git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@2203 50f2f4bb-b051-0410-bef5-90022cba6387
pull/1/head
Ramnivas Laddad 16 years ago
parent
commit
77bb2bdfb1
  1. 74
      org.springframework.aspects/src/test/java/org/springframework/mock/static_mock/Delegate.java
  2. 62
      org.springframework.aspects/src/test/java/org/springframework/mock/static_mock/JUnitStaticEntityMockingControlTest.java

74
org.springframework.aspects/src/test/java/org/springframework/mock/static_mock/Delegate.java

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

62
org.springframework.aspects/src/test/java/org/springframework/mock/static_mock/JUnitStaticEntityMockingControlTest.java

@ -145,65 +145,3 @@ public class JUnitStaticEntityMockingControlTest { @@ -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();
}
}

Loading…
Cancel
Save