@Test public void testProxyThrows() throws Exception { MyInterface impl = (MyInterface) DuckTypeProxy.getProxy( MyInterface.class, Lists.newArrayList(new Object()), DuckTypeProxy.THROW); try { impl.getString(); fail("should have thrown USOE"); } catch (UnsupportedOperationException yay) { } }
@Test public void testNullParameter() throws Exception { Object obj = new Object() { public String get(String string) { return "how about: " + string; } }; MyInterface impl = (MyInterface) DuckTypeProxy.getProxy(MyInterface.class, Lists.newArrayList(obj), DuckTypeProxy.THROW); assertEquals("how about: null", impl.get((String) null)); }
@Test public void testProxyReturns() throws Exception { Object obj = new Object() { public String getString() { return "who's you're daddy?"; } }; MyInterface impl = (MyInterface) DuckTypeProxy.getProxy(MyInterface.class, Lists.newArrayList(obj), DuckTypeProxy.THROW); assertEquals("who's you're daddy?", impl.getString()); }