Update of /cvsroot/mocklib/mocklib3/input/javasrc/biz/xsoftware/impl/mock/test
In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv19035/input/javasrc/biz/xsoftware/impl/mock/test
Added Files:
ListenerOne.java TestOrderedCalls.java MockOne.java
Log Message:
changes to mocklib3 to prepare for delivery.
--- NEW FILE: ListenerOne.java ---
/*
* Created on Apr 24, 2004
*
* To change the template for this generated file go to
* Window - Preferences - Java - Code Generation - Code and Comments
*/
package biz.xsoftware.impl.mock.test;
import java.io.IOException;
/**
* @author Dean Hiller
*
* To change the template for this generated type comment go to
* Window - Preferences - Java - Code Generation - Code and Comments
*/
public interface ListenerOne {
public void callMeFirst(int s);
public void callMeSecond(String s) throws IOException;
public void multipleParams(String x, Integer i);
}
--- NEW FILE: MockOne.java ---
/*
* Created on Apr 24, 2004
*
* To change the template for this generated file go to
* Window - Preferences - Java - Code Generation - Code and Comments
*/
package biz.xsoftware.impl.mock.test;
import biz.xsoftware.impl.mock.MockSuperclass;
/**
* @author Dean Hiller
*
* To change the template for this generated type comment go to
* Window - Preferences - Java - Code Generation - Code and Comments
*/
public class MockOne extends MockSuperclass implements ListenerOne {
public static final String FIRST = "callMeFirst";
public static final String SECOND = "callMeSecond";
public static final String EXTRA = "callMeExtra";
public static final String MULTIPLE_PARAMS = "multipleParams";
public MockOne(int delay) {
super(delay);
}
/* (non-Javadoc)
* @see test.biz.xsoftware.testlib.test.ListenerOne#callMeFirst()
*/
public void callMeFirst(int s) {
methodCalled(FIRST, new Integer(s));
}
/* (non-Javadoc)
* @see test.biz.xsoftware.testlib.test.ListenerOne#callMeSecond()
*/
public void callMeSecond(String s) {
methodCalled(SECOND, s);
}
public void callMeExtra() {
methodCalled(EXTRA, null);
}
/* (non-Javadoc)
* @see biz.xsoftware.test.ListenerOne#multipleParams(java.lang.String, java.lang.Integer)
*/
public void multipleParams(String x, Integer i) {
methodCalled(MULTIPLE_PARAMS, new Object[] { x, i });
}
/* (non-Javadoc)
* @see biz.xsoftware.mock.MockSuperclass#getClasses()
*/
@Override
public Class[] getClasses() {
return new Class[] { MockOne.class };
}
public Object inst() {
// TODO Auto-generated method stub
return null;
}
}
--- NEW FILE: TestOrderedCalls.java ---
/*
* Created on Apr 24, 2004
*
* To change the template for this generated file go to
* Window - Preferences - Java - Code Generation - Code and Comments
*/
package biz.xsoftware.impl.mock.test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import junit.textui.TestRunner;
import biz.xsoftware.mock.ExpectFailedException;
/**
* @author Dean Hiller
*
* To change the template for this generated type comment go to
* Window - Preferences - Java - Code Generation - Code and Comments
*/
public class TestOrderedCalls extends TestCase {
//private final static Logger log = Logger.getLogger(TestOrderedCalls.class.getName());
/**
* @param name
*/
public TestOrderedCalls(String name) {
super(name);
}
public void testBasicEventBeforeExpect() {
MockOne one = new MockOne(3000);
one.callMeFirst(4);
one.expect(MockOne.FIRST);
}
public void testBasicExpectBeforeEvent() {
final MockOne one = new MockOne(3000);
Thread r = new Thread() {
@Override
public void run() {
delay(1000);
one.callMeFirst(4);
}
};
r.start();
one.expect(MockOne.FIRST);
}
public void testOrderAfter() {
MockOne one = new MockOne(3000);
one.callMeFirst(4);
one.callMeSecond("dummy");
String[] evts = new String[] { MockOne.FIRST, MockOne.SECOND };
one.expect(evts);
}
public void testOrderBefore() {
final MockOne one = new MockOne(3000);
Thread r = new Thread() {
@Override
public void run() {
delay(1000);
one.callMeFirst(4);
one.callMeSecond("dummy");
}
};
r.start();
String[] evts = new String[] { MockOne.FIRST, MockOne.SECOND };
one.expect(evts);
}
public void testOrderAfterFails() {
MockOne one = new MockOne(3000);
one.callMeFirst(7);
one.callMeSecond("dummy");
String[] evts = new String[] { MockOne.SECOND, MockOne.FIRST };
try {
one.expect(evts);
fail("Should have failed this test case");
} catch(ExpectFailedException e) { /*gulp*/ }
}
public void testOrderBeforeFails() {
final MockOne one = new MockOne(3000);
Thread r = new Thread() {
@Override
public void run() {
delay(1000);
one.callMeFirst(14);
one.callMeSecond("dummy");
}
};
String[] evts = new String[] { MockOne.SECOND, MockOne.FIRST };
try {
r.run();
one.expect(evts);
fail("Should have failed this test case");
} catch(ExpectFailedException e) { /*gulp*/ }
}
public void testLeftOverEventFails() {
MockOne one = new MockOne(3000);
one.callMeFirst(234);
one.callMeSecond("dummy");
one.callMeFirst(43);
String[] evts = new String[] { MockOne.FIRST, MockOne.SECOND };
try {
one.expect(evts);
fail("Should have failed this test case");
} catch(ExpectFailedException e) { /*gulp*/ }
}
public void testExceptionThrown() {
MockOne one = new MockOne(3000);
RuntimeException e = new IllegalStateException("Test for robustness");
one.addThrowException(e, MockOne.FIRST);
try {
one.callMeFirst(324);
fail("Should have thrown exception");
} catch(IllegalStateException e2) {}
one.callMeSecond("dummy");
String[] methods = new String[] {MockOne.FIRST, MockOne.SECOND };
one.expect(methods);
}
private void delay(int time) {
try {
Thread.sleep(time);
} catch (InterruptedException e) {
throw new RuntimeException("Sleep ended abrubtly");
}
}
public static void main(String[] args) {
TestSuite suite = new TestSuite();
suite.addTest(new TestOrderedCalls("testExceptionThrown"));
// suite.addTest(new TestMockSuperclass("testMockCreator"));
// suite.addTest(new TestMockSuperclass("testMockCreatorFail"));
// suite.addTest(new TestMockSuperclass("testMockCreatorCreatesCar"));
// suite.addTest(new TestMockSuperclass("testThrowCheckedException"));
TestRunner.run(suite);
}
}
|