From: chris c. <drc...@ya...> - 2003-06-30 08:02:45
|
Hi Steve, here is the failing test of the DynamicUtil in DynamicUtilTest public void testProxyToString() throws Exception { Mock mockDummyInterface = new Mock(DummyInterface.class, "an example"); DummyInterface proxyDummyInterface = (DummyInterface) mockDummyInterface.proxy(); assertEquals("should get correct string", "an example", DynamicUtil.proxyToString(proxyDummyInterface)); assertEquals("should get correct string for array", "[<an example>]", DynamicUtil.proxyToString(new DummyInterface[] { proxyDummyInterface })); List list = new ArrayList(); list.add(proxyDummyInterface); assertEquals("should get correct string for list", "[an example]", DynamicUtil.proxyToString(list)); class MyClass { DummyInterface aField; MyClass(DummyInterface aDummy) { aField = aDummy; } public String toString() { return "myClass contains:" + aField; } } MyClass myClass = new MyClass(proxyDummyInterface); assertEquals("should get string back from contained field", "myClass contains:", DynamicUtil.proxyToString(myClass)); } The first two asserts pass, the second two do not. The other thing I would like to do is refactor the MockTest. I want to do this because I tried out my one line change to Mock and it made every single test fail. In trying to fix them I noticed that there is a lot of duplication in the test and that some small changes to the CallFactory interface would make the test a great deal simpler. For instance replacing this method in Mock public void expect(String methodName, ConstraintMatcher args) { calls.addExpect(callFactory.createCallExpectation(callFactory.createCallSignature(methodName, args, callFactory.createVoidStub()))); } with something like this: public void expect(String methodName, ConstraintMatcher args) { calls.addExpect(callFactory.createCallExpectation(methodName, args)); } and having changed the DefaultCallFactory to handle it would make it a lot simpler to setup the expectations in the MockTest. Alternatively I would suggest not using mocks to test Mock, I don't think you need to. I think plain old fashioned exo-testing would cut it. This would have the advantage of providing examples of usage and decoupling the test from implementation, making it simpler to integrate with Nat's changes. Chris |