### Question:
ObjectMethodInvocationHandler extends CXFInvocationHandlerBase { public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { Object ret = null; LOG.fine(this + " on " + method); if (method.getDeclaringClass().equals(Object.class)) { if (EQUALS_METHOD_NAME.equals(method.getName())) { ret = doEquals(args[0]); } else if (TO_STRING_METHOD_NAME.equals(method.getName())) { ret = doToString(); } else { ret = method.invoke(getData().getTarget(), args); } } else { ret = invokeNext(proxy, method, args); } return ret; } ObjectMethodInvocationHandler(CXFInvocationHandlerData data); Object invoke(Object proxy, Method method, Object[] args);  }### Answer:
@Test public void testToString() throws Throwable { Method toString = Object.class.getMethod("toString", new Class[0]); Object result = handler.invoke(testTarget, toString, null); assertFalse("object method must not be passed to next handler in chain", dummyHandler.invokeCalled); assertTrue("object must be a String", result instanceof String); assertTrue("checking toString method ", ((String)result).startsWith("ConnectionHandle")); }
@Test public void testEqualsDoesNotCallNext() throws Throwable { Method equals = Object.class.getMethod("equals", new Class[] {Object.class}); handler.invoke(testTarget, equals, new Object[] {this}); assertFalse("object method must not be passed to next handler in chain", dummyHandler.invokeCalled); }
@Test public void testToString() throws Throwable { Method toString = Object.class.getMethod("toString", new Class[0]); Object result = handler.invoke(testTarget, toString, null); assertTrue("object method must not be passed to next handler in chain", !dummyHandler.invokeCalled); assertTrue("object must be a String", result instanceof String); assertTrue("checking toString method ", ((String)result).startsWith("ConnectionHandle")); }
@Test public void testEqualsDoesNotCallNext() throws Throwable { Method equals = Object.class.getMethod("equals", new Class[] {Object.class}); handler.invoke(testTarget, equals, new Object[] {this}); assertTrue("object method must not be passed to next handler in chain", !dummyHandler.invokeCalled); }
@Test public void testNonObjecMethod() throws Throwable { DummyHandler dummyHandler1 = new DummyHandler(); handler.setNext(dummyHandler1); final Method method = TestTarget.class.getMethod("testMethod", new Class[0]); handler.invoke(testTarget, method, new Object[0]); assertTrue("non object method must be passed to next handler in chain", dummyHandler1.invokeCalled); }