@@ -0,0 +1,1512 @@
+package net.spy.memcached;%0A%0Aimport java.lang.reflect.InvocationTargetException;%0Aimport java.lang.reflect.Method;%0Aimport java.net.InetSocketAddress;%0Aimport java.net.SocketAddress;%0A%0Aimport org.jmock.Mock;%0Aimport org.jmock.MockObjectTestCase;%0A%0A/**%0A * Test readonliness of the MemcachedNodeROImpl%0A */%0Apublic class MemcachedNodeROImplTest extends MockObjectTestCase %7B%0A%0A%09public void testReadOnliness() throws Exception %7B%0A%09%09SocketAddress sa=new InetSocketAddress(11211);%0A%09%09Mock m = mock(MemcachedNode.class, %22node%22);%0A%09%09MemcachedNodeROImpl node=%0A%09%09%09new MemcachedNodeROImpl((MemcachedNode)m.proxy());%0A%09%09m.expects(once()).method(%22getSocketAddress%22).will(returnValue(sa));%0A%0A%09%09assertSame(sa, node.getSocketAddress());%0A%09%09assertEquals(m.proxy().toString(), node.toString());%0A%0A%09%09for(Method meth : MemcachedNode.class.getMethods()) %7B%0A%09%09%09if(meth.getName().equals(%22toString%22)) %7B%0A%09%09%09%09// ok%0A%09%09%09%7D else if(meth.getName().equals(%22getSocketAddress%22)) %7B%0A%09%09%09%09// ok%0A%09%09%09%7D else %7B%0A%09%09%09%09Object%5B%5D args=new Object%5Bmeth.getParameterTypes().length%5D;%0A%09%09%09%09fillArgs(meth.getParameterTypes(), args);%0A%09%09%09%09try %7B%0A%09%09%09%09%09meth.invoke(node, args);%0A%09%09%09%09%09fail(%22Failed to break on %22 + meth.getName());%0A%09%09%09%09%7D catch(InvocationTargetException e) %7B%0A%09%09%09%09%09assertSame(UnsupportedOperationException.class,%0A%09%09%09%09%09%09e.getCause().getClass());%0A%09%09%09%09%7D%0A%09%09%09%7D%0A%09%09%7D%0A%09%7D%0A%0A%09private void fillArgs(Class%3C?%3E%5B%5D parameterTypes, Object%5B%5D args) %7B%0A%09%09int i=0;%0A%09%09for(Class%3C?%3E c : parameterTypes) %7B%0A%09%09%09if(c == Boolean.TYPE) %7B%0A%09%09%09%09args%5Bi++%5D = false;%0A%09%09%09%7D else %7B%0A%09%09%09%09args%5Bi++%5D = null;%0A%09%09%09%7D%0A%09%09%7D%0A%09%7D%0A%0A%7D%0A

Test the readonliness of MemcachedNodeROImpl.