/** * Test that the proxy returns itself when the * target returns {@code this} */ @Test public void testTargetReturnsThis() throws Throwable { // Test return value TestBean raw = new OwnSpouse(); ProxyCreatorSupport pc = new ProxyCreatorSupport(); pc.setInterfaces(ITestBean.class); pc.setTarget(raw); ITestBean tb = (ITestBean) createProxy(pc); assertSame("this return is wrapped in proxy", tb, tb.getSpouse()); }
@Test public void testProxyNotWrappedIfIncompatible() { FooBar bean = new FooBar(); ProxyCreatorSupport as = new ProxyCreatorSupport(); as.setInterfaces(Foo.class); as.setTarget(bean); Foo proxy = (Foo) createProxy(as); assertSame("Target should be returned when return types are incompatible", bean, proxy.getBarThis()); assertSame("Proxy should be returned when return types are compatible", proxy, proxy.getFooThis()); }