Update of /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/test/mock2
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31747/input/javasrc/biz/xsoftware/test/mock2
Modified Files:
TestMockCreator.java
Log Message:
whoops, accidentally deleted some code.
Index: TestMockCreator.java
===================================================================
RCS file: /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/test/mock2/TestMockCreator.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** TestMockCreator.java 2 Mar 2006 10:47:18 -0000 1.5
--- TestMockCreator.java 2 Mar 2006 10:52:34 -0000 1.6
***************
*** 1,4 ****
--- 1,5 ----
package biz.xsoftware.test.mock2;
+ import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
***************
*** 11,85 ****
public class TestMockCreator extends TestCase {
!
! private static final Logger log = Logger.getLogger(TestMockCreator.class.getName());
!
! public TestMockCreator(String name){
super(name);
}
!
! public void testMockCreator()throws Exception{
MockObject m = MockObjectFactory.createMock(ListenerOne.class);
! // ListenerOne l=(ListenerOne)m;
!
!
!
! String methodName="callMeSecond";
!
! CalledMethod method=m.expect(methodName);
!
! // String param="some params";
! // l.callMeSecond(param);
!
try {
method.getParameters();
fail("Since verify was not called, CalledMethod methods should not work");
! } catch(IllegalStateException e) {
}
! //assertEquals("the methodName should be the same",methodName,method.getMethodName());
! //assertEquals("params should equal", param, method.getParameters()[0]);
! //assertEquals("param count should be 1", 1, method.getParameters().length);
}
public void testNoVerifyCalled() throws Exception {
MockObject m = MockObjectFactory.createMock(ListenerOne.class);
! // ListenerOne l=(ListenerOne)m;
String methodName1 = "callMeFirst";
! String methodName2="callMeSecond";
! CalledMethod callMeFirst =m.expect(methodName1);
! //eclipse complains this is never read so don't bother having it for now...
! //CalledMethod callMeSecond=
! m.expect(methodName2);
!
try {
callMeFirst.getParameters();
fail("The method was not called yet and verify() was not called, so above should throw exceptoin");
! } catch(IllegalStateException e) {
}
}
!
public void testTwoMethods() throws Exception {
MockObject m = MockObjectFactory.createMock(ListenerOne.class);
! ListenerOne l=(ListenerOne)m;
String methodName1 = "callMeFirst";
! String methodName2="callMeSecond";
! CalledMethod callMeFirst =m.expect(methodName1);
! CalledMethod callMeSecond=m.expect(methodName2);
!
int var1 = 4;
l.callMeFirst(var1);
! String param="some params";
l.callMeSecond(param);
m.verify();
!
! assertEquals("the methodName should be the same",methodName1,callMeFirst.getMethodName());
Object[] array = callMeFirst.getParameters();
assertEquals("params should equal", var1, array[0]);
! assertEquals("param count should be 1", 1, callMeFirst.getParameters().length);
!
! assertEquals("the methodName should be the same",methodName2,callMeSecond.getMethodName());
! assertEquals("params should equal", param, callMeSecond.getParameters()[0]);
! assertEquals("param count should be 1", 1, callMeSecond.getParameters().length);
}
--- 12,94 ----
public class TestMockCreator extends TestCase {
!
! private static final Logger log = Logger.getLogger(TestMockCreator.class
! .getName());
!
! public TestMockCreator(String name) {
super(name);
}
!
! public void testMockCreator() throws Exception {
MockObject m = MockObjectFactory.createMock(ListenerOne.class);
! // ListenerOne l=(ListenerOne)m;
!
! String methodName = "callMeSecond";
!
! CalledMethod method = m.expect(methodName);
!
! // String param="some params";
! // l.callMeSecond(param);
!
try {
method.getParameters();
fail("Since verify was not called, CalledMethod methods should not work");
! } catch (IllegalStateException e) {
}
! // assertEquals("the methodName should be the
! // same",methodName,method.getMethodName());
! // assertEquals("params should equal", param,
! // method.getParameters()[0]);
! // assertEquals("param count should be 1", 1,
! // method.getParameters().length);
}
public void testNoVerifyCalled() throws Exception {
MockObject m = MockObjectFactory.createMock(ListenerOne.class);
! // ListenerOne l=(ListenerOne)m;
String methodName1 = "callMeFirst";
! String methodName2 = "callMeSecond";
! CalledMethod callMeFirst = m.expect(methodName1);
! // eclipse complains this is never read so don't bother having it for
! // now...
! // CalledMethod callMeSecond=
! m.expect(methodName2);
!
try {
callMeFirst.getParameters();
fail("The method was not called yet and verify() was not called, so above should throw exceptoin");
! } catch (IllegalStateException e) {
}
}
!
public void testTwoMethods() throws Exception {
MockObject m = MockObjectFactory.createMock(ListenerOne.class);
! ListenerOne l = (ListenerOne) m;
String methodName1 = "callMeFirst";
! String methodName2 = "callMeSecond";
! CalledMethod callMeFirst = m.expect(methodName1);
! CalledMethod callMeSecond = m.expect(methodName2);
!
int var1 = 4;
l.callMeFirst(var1);
! String param = "some params";
l.callMeSecond(param);
m.verify();
!
! assertEquals("the methodName should be the same", methodName1,
! callMeFirst.getMethodName());
Object[] array = callMeFirst.getParameters();
assertEquals("params should equal", var1, array[0]);
! assertEquals("param count should be 1", 1,
! callMeFirst.getParameters().length);
!
! assertEquals("the methodName should be the same", methodName2,
! callMeSecond.getMethodName());
! assertEquals("params should equal", param,
! callMeSecond.getParameters()[0]);
! assertEquals("param count should be 1", 1,
! callMeSecond.getParameters().length);
}
***************
*** 104,108 ****
log.log(Level.WARNING, "exception", e);
throw new RuntimeException(e);
! }
}
};
--- 113,117 ----
log.log(Level.WARNING, "exception", e);
throw new RuntimeException(e);
! }
}
};
***************
*** 125,171 ****
callMeSecond.getParameters().length);
}
!
public void testFailure() throws Exception {
MockObject m = MockObjectFactory.createMock(ListenerOne.class);
! ListenerOne l=(ListenerOne)m;
!
! String param="some params";
l.callMeSecond(param);
!
! String methodName="callMeSecond";
!
! CalledMethod method=m.expect(methodName);
!
try {
! assertEquals("params should equal", param, method.getParameters()[0]);
fail("This should fail since m.verify() is not called");
! } catch(IllegalStateException e) {
assertEquals(Messages.VERIFY_NOT_CALLED, e.getMessage());
}
}
-
- public void testExpectWithRetVal() throws Exception{
- MockObject m=MockObjectFactory.createMock(ListenerOne.class);
- ListenerOne l=(ListenerOne)m;
-
- Object returnVal="OK";
- String methodName="callWithRetVal";
- CalledMethod method=m.expect(returnVal,methodName);
-
- String param="some params";
- String retVal=l.callWithRetVal(param);
-
- m.verify();
-
- assertEquals("The method name should be equal",method.getMethodName(),methodName);
- assertEquals("the params should be the same ",method.getParameters()[0],param);
- assertEquals("the length of param should be equal",1,method.getParameters().length);
- assertEquals("the return value should be the same",returnVal,retVal);
-
- }
-
- public void testRemoveCalledMethod(){
-
- }
}
--- 134,211 ----
callMeSecond.getParameters().length);
}
!
public void testFailure() throws Exception {
MockObject m = MockObjectFactory.createMock(ListenerOne.class);
! ListenerOne l = (ListenerOne) m;
!
! String param = "some params";
l.callMeSecond(param);
!
! String methodName = "callMeSecond";
!
! CalledMethod method = m.expect(methodName);
!
try {
! assertEquals("params should equal", param,
! method.getParameters()[0]);
fail("This should fail since m.verify() is not called");
! } catch (IllegalStateException e) {
assertEquals(Messages.VERIFY_NOT_CALLED, e.getMessage());
}
}
+ public void testExpectWithRetVal() throws Exception {
+ MockObject m = MockObjectFactory.createMock(ListenerOne.class);
+ ListenerOne l = (ListenerOne) m;
+
+ Object returnVal = "OK";
+ String methodName = "callWithRetVal";
+ CalledMethod method = m.expect(returnVal, methodName);
+
+ String param = "some params";
+ String retVal = l.callWithRetVal(param);
+
+ m.verify();
+
+ assertEquals("The method name should be equal", method.getMethodName(),
+ methodName);
+ assertEquals("the params should be the same ",
+ method.getParameters()[0], param);
+ assertEquals("the length of param should be equal", 1, method
+ .getParameters().length);
+ assertEquals("the return value should be the same", returnVal, retVal);
+
+ }
+
+ public void testRemoveCalledMethod() {
+
+ }
+
+ public void testExceptionThrows() throws Exception {
+ MockObject m = MockObjectFactory.createMock(ListenerOne.class);
+ ListenerOne l = (ListenerOne) m;
+
+ String methodName = "callMeSecond";
+ String message = "Make sure systemUnderTest handles exception";
+
+ //variable never used. eclipse is complaining...
+ //CalledMethod calledMethod =
+ m.expect(methodName, new IOException(
+ message));
+
+ String param = "params";
+ try {
+ l.callMeSecond(param);
+ fail("Exception should be thrown earlier, try to find why it did not!!!");
+ } catch (IOException e) {
+
+ assertEquals(message, e.getMessage());
+ }
+
+ m.verify();
+ }
+
+ public void testExpectWithBehavior() throws Exception {
+ //MockObject m = MockObjectFactory.createMock(ListenerOne.class);
+ }
}
|