[Contestj-developer] contestj/contestj2/src/test/java/org/contestj/test/mock/method MethodMockTest
Status: Inactive
Brought to you by:
thomasra
|
From: Ståle P. <st...@us...> - 2007-06-20 14:54:17
|
Update of /cvsroot/contestj/contestj/contestj2/src/test/java/org/contestj/test/mock/method In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv14426/contestj2/src/test/java/org/contestj/test/mock/method Added Files: MethodMockTest.java Log Message: Initial upload of Contestj2 even though it supports most of the Contestj features its not ready to be used atm. --- NEW FILE: MethodMockTest.java --- package org.contestj.test.mock.method; import org.contestj.mockservice.MockInvocationHandler; import org.contestj.mockservice.MockMethod; import org.contestj.mockservice.MockService; import org.contestj.test.mock.clazz.Bar; import org.contestj.test.mock.clazz.Foo; import junit.framework.TestCase; public class MethodMockTest extends TestCase { public void testMethodMock() { MockMethod method = new MockMethod(Bar.class.getName(), "getData"); method.setupInvoke(new Integer(2)); MockService.getInstance().addMockMethod(method); Foo f = new Foo(); int i = f.business2(); assertEquals("Test failed, bah! ", 4, i); } public void testMethodWithParamsMock() { MockMethod method = new MockMethod(Bar.class.getName(), "getData2", new Class[] {int.class}); method.setupInvoke(new Integer(2)); MockService.getInstance().addMockMethod(method); Foo f = new Foo(); int i = f.business3(); assertEquals("Test failed, bah! ", 4, i); } public void testStaticMethodMock() { MockMethod method = new MockMethod(Bar.class.getName(), "getData3"); method.setupInvoke(new Integer(4)); MockService.getInstance().addMockMethod(method); Foo f = new Foo(); int i = f.business4(); assertEquals("Test failed, bah! ", 4, i); } public void testVoidMethodMock() { MockMethod method = new MockMethod(Bar.class.getName(), "doStuff"); method.setupInvoke(new Integer(1)); MockService.getInstance().addMockMethod(method); Bar b = new Bar(); try { b.doStuff(); assertTrue("Void tests sucessfully mocked", true); } catch(Exception e) { assertTrue("Failed to mock void tests", false); } } public void testInvocationHandlerMethodMock() { Bar b = new Bar(); String input = "input"; MockInvocationHandler handler = new MockInvocationHandler() { public Object invoke(Object[] args) { //String s = (String) args; System.out.println("Inside invoke object, got: "+args[0].toString()); //return "blada"; return args[0]; } }; MockMethod mockMethod = new MockMethod(Bar.class.getName(), "returnStuff", new Class[] {String.class} ); mockMethod.setInvocationHandler(handler); //mockMethod.setTimedOnly(true, timeToWait); MockService.getInstance().addMockMethod(mockMethod); System.out.println("testing...."); assertEquals("Should have been original value", input, b.returnStuff(input)); } } |