JavaProxyObserver implements FeatureObserver { public <T> T observe(Object obj, FeatureContext context) { throwIllegalArgumentExceptionIfNull(context, "FeatureContext instance is required."); throwIllegalArgumentExceptionIfNull(obj, "observable object is required."); throwIllegalArgumentExceptionIfFalse(obj.getClass().getInterfaces().length != 0, "observable object must implement an interface."); return (T) Proxy.newProxyInstance(obj.getClass().getClassLoader(), obj.getClass().getInterfaces(), new ProxyInvocationHandler(obj, context)); }  T observe(Object obj, FeatureContext context);  }
@Test(expected = IllegalArgumentException.class) public void observe_WithoutContext_throwsException() { observer.observe(new JavaProxiedClass(), null); }
@Test(expected = IllegalArgumentException.class) public void observe_WithoutObservableObject_throwsException() { observer.observe(null, context); }
@Test(expected = IllegalArgumentException.class) public void observe_WithoutImplementingObject_throwsException() { observer.observe(new JavaProxyObserverTest(), context); }
@Test public void observe_withObject_returnsInvocationHandler() { Serializable object = observer.observe(new JavaProxiedClass(), context); assertThat(Proxy.isProxyClass(object.getClass()),equalTo(true)); assertThat(Proxy.getInvocationHandler(object).getClass().toString(), equalTo(JavaProxyObserver.ProxyInvocationHandler.class.toString())); }