Modified staticmethod mocking to remove compile-time dependency on JUnit (see ROO-314 and related issues)
This commit is contained in:
@@ -16,8 +16,6 @@
|
||||
|
||||
package org.springframework.mock.staticmock;
|
||||
|
||||
import java.rmi.RemoteException;
|
||||
|
||||
import javax.persistence.PersistenceException;
|
||||
|
||||
import junit.framework.Assert;
|
||||
@@ -25,9 +23,8 @@ import junit.framework.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
import org.springframework.mock.staticmock.JUnitStaticEntityMockingControl;
|
||||
import org.springframework.mock.staticmock.MockStaticEntityMethods;
|
||||
import org.springframework.remoting.RemoteAccessException;
|
||||
|
||||
import static org.springframework.mock.staticmock.AnnotationDrivenStaticEntityMockingControl.*;
|
||||
|
||||
|
||||
/**
|
||||
@@ -38,22 +35,22 @@ import org.springframework.remoting.RemoteAccessException;
|
||||
*/
|
||||
@MockStaticEntityMethods
|
||||
@RunWith(JUnit4.class)
|
||||
public class JUnitStaticEntityMockingControlTest {
|
||||
public class AnnotationDrivenStaticEntityMockingControlTest {
|
||||
|
||||
@Test
|
||||
public void testNoArgIntReturn() {
|
||||
int expectedCount = 13;
|
||||
Person.countPeople();
|
||||
JUnitStaticEntityMockingControl.expectReturn(expectedCount);
|
||||
JUnitStaticEntityMockingControl.playback();
|
||||
expectReturn(expectedCount);
|
||||
playback();
|
||||
Assert.assertEquals(expectedCount, Person.countPeople());
|
||||
}
|
||||
|
||||
@Test(expected=PersistenceException.class)
|
||||
public void testNoArgThrows() {
|
||||
Person.countPeople();
|
||||
JUnitStaticEntityMockingControl.expectThrow(new PersistenceException());
|
||||
JUnitStaticEntityMockingControl.playback();
|
||||
expectThrow(new PersistenceException());
|
||||
playback();
|
||||
Person.countPeople();
|
||||
}
|
||||
|
||||
@@ -62,8 +59,8 @@ public class JUnitStaticEntityMockingControlTest {
|
||||
long id = 13;
|
||||
Person found = new Person();
|
||||
Person.findPerson(id);
|
||||
JUnitStaticEntityMockingControl.expectReturn(found);
|
||||
JUnitStaticEntityMockingControl.playback();
|
||||
expectReturn(found);
|
||||
playback();
|
||||
Assert.assertEquals(found, Person.findPerson(id));
|
||||
}
|
||||
|
||||
@@ -74,15 +71,15 @@ public class JUnitStaticEntityMockingControlTest {
|
||||
long id2 = 24;
|
||||
Person found1 = new Person();
|
||||
Person.findPerson(id1);
|
||||
JUnitStaticEntityMockingControl.expectReturn(found1);
|
||||
expectReturn(found1);
|
||||
Person found2 = new Person();
|
||||
Person.findPerson(id2);
|
||||
JUnitStaticEntityMockingControl.expectReturn(found2);
|
||||
expectReturn(found2);
|
||||
Person.findPerson(id1);
|
||||
JUnitStaticEntityMockingControl.expectReturn(found1);
|
||||
expectReturn(found1);
|
||||
Person.countPeople();
|
||||
JUnitStaticEntityMockingControl.expectReturn(0);
|
||||
JUnitStaticEntityMockingControl.playback();
|
||||
expectReturn(0);
|
||||
playback();
|
||||
|
||||
Assert.assertEquals(found1, Person.findPerson(id1));
|
||||
Assert.assertEquals(found2, Person.findPerson(id2));
|
||||
@@ -116,8 +113,8 @@ public class JUnitStaticEntityMockingControlTest {
|
||||
long id = 13;
|
||||
Person found = new Person();
|
||||
Person.findPerson(id);
|
||||
JUnitStaticEntityMockingControl.expectReturn(found);
|
||||
JUnitStaticEntityMockingControl.playback();
|
||||
expectReturn(found);
|
||||
playback();
|
||||
called(found, id);
|
||||
}
|
||||
|
||||
@@ -8,13 +8,13 @@ import junit.framework.Assert;
|
||||
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.springframework.mock.staticmock.JUnitStaticEntityMockingControl;
|
||||
import org.springframework.mock.staticmock.AnnotationDrivenStaticEntityMockingControl;
|
||||
import org.springframework.mock.staticmock.MockStaticEntityMethods;
|
||||
|
||||
//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
|
||||
@Ignore // This isn't meant for direct testing; rather it is driven from AnnotationDrivenStaticEntityMockingControl
|
||||
public class Delegate {
|
||||
|
||||
@Test
|
||||
@@ -22,8 +22,8 @@ public class Delegate {
|
||||
long id = 13;
|
||||
Person found = new Person();
|
||||
Person.findPerson(id);
|
||||
JUnitStaticEntityMockingControl.expectReturn(found);
|
||||
JUnitStaticEntityMockingControl.playback();
|
||||
AnnotationDrivenStaticEntityMockingControl.expectReturn(found);
|
||||
AnnotationDrivenStaticEntityMockingControl.playback();
|
||||
Assert.assertEquals(found, Person.findPerson(id + 1));
|
||||
}
|
||||
|
||||
@@ -32,8 +32,8 @@ public class Delegate {
|
||||
long id = 13;
|
||||
Person found = new Person();
|
||||
Person.findPerson(id);
|
||||
JUnitStaticEntityMockingControl.expectThrow(new PersistenceException());
|
||||
JUnitStaticEntityMockingControl.playback();
|
||||
AnnotationDrivenStaticEntityMockingControl.expectThrow(new PersistenceException());
|
||||
AnnotationDrivenStaticEntityMockingControl.playback();
|
||||
Assert.assertEquals(found, Person.findPerson(id + 1));
|
||||
}
|
||||
|
||||
@@ -42,10 +42,10 @@ public class Delegate {
|
||||
long id = 13;
|
||||
Person found = new Person();
|
||||
Person.findPerson(id);
|
||||
JUnitStaticEntityMockingControl.expectReturn(found);
|
||||
AnnotationDrivenStaticEntityMockingControl.expectReturn(found);
|
||||
Person.countPeople();
|
||||
JUnitStaticEntityMockingControl.expectReturn(25);
|
||||
JUnitStaticEntityMockingControl.playback();
|
||||
AnnotationDrivenStaticEntityMockingControl.expectReturn(25);
|
||||
AnnotationDrivenStaticEntityMockingControl.playback();
|
||||
Assert.assertEquals(found, Person.findPerson(id));
|
||||
}
|
||||
|
||||
@@ -57,19 +57,19 @@ public class Delegate {
|
||||
@Test
|
||||
public void doesntEverSetReturn() {
|
||||
Person.countPeople();
|
||||
JUnitStaticEntityMockingControl.playback();
|
||||
AnnotationDrivenStaticEntityMockingControl.playback();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rejectUnexpectedCall() {
|
||||
JUnitStaticEntityMockingControl.playback();
|
||||
AnnotationDrivenStaticEntityMockingControl.playback();
|
||||
Person.countPeople();
|
||||
}
|
||||
|
||||
@Test(expected=RemoteException.class)
|
||||
public void testVerificationFailsEvenWhenTestFailsInExpectedManner() throws RemoteException {
|
||||
Person.countPeople();
|
||||
JUnitStaticEntityMockingControl.playback();
|
||||
AnnotationDrivenStaticEntityMockingControl.playback();
|
||||
// No calls to allow verification failure
|
||||
throw new RemoteException();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user