Update of /cvsroot/mocklib/mocklib3/input/javasrc/biz/xsoftware/test/mock
In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv27320/input/javasrc/biz/xsoftware/test/mock
Added Files:
SimpleTest.java
Log Message:
New testcase for simple scenario
--- NEW FILE: SimpleTest.java ---
/*
* Copyright 2009 mocklib.sourceforge.net
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package biz.xsoftware.test.mock;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
import biz.xsoftware.mock.CalledMethod;
import biz.xsoftware.mock.MockObject;
import biz.xsoftware.mock.MockObjectFactory;
public class SimpleTest {
// The interface we want to mock
private static interface Foo {
public String bar(String arg);
}
@Test
public void testFoo() {
// creates an instace of the mock object
MockObject mockFoo = MockObjectFactory.createMock(Foo.class);
// set the desired return value
mockFoo.addReturnValue("bar", "hi there");
// The mock object can now be cast as an actual implmentation
// of the interface that was created
Foo foo = (Foo) mockFoo;
// make a call to the method in the interface
String returnVal = foo.bar("test arg");
// verify return value matches expected value
assertEquals("hi there", returnVal);
// to verify the test we want to make sure that the interface was
// called - if foo wasn't called this will throw an exception
CalledMethod calledMethod = mockFoo.expect("bar");
// calledMethod now contains more detailed information about
// the call to foo.bar so we can do further validation if needed
// for this example we'll just make sure that the argument
// passed in equals "test arg"
assertEquals("test arg", calledMethod.getAllParams()[0]);
}
}
|