use of org.springframework.tests.TimeStamped in project spring-framework by spring-projects.
the class ProxyFactoryTests method testAddRepeatedInterface.
@Test
public void testAddRepeatedInterface() {
TimeStamped tst = new TimeStamped() {
@Override
public long getTimeStamp() {
throw new UnsupportedOperationException("getTimeStamp");
}
};
ProxyFactory pf = new ProxyFactory(tst);
// We've already implicitly added this interface.
// This call should be ignored without error
pf.addInterface(TimeStamped.class);
// All cool
assertThat(pf.getProxy(), instanceOf(TimeStamped.class));
}
use of org.springframework.tests.TimeStamped in project spring-framework by spring-projects.
the class ProxyFactoryTests method testGetsAllInterfaces.
@Test
public void testGetsAllInterfaces() throws Exception {
// Extend to get new interface
class TestBeanSubclass extends TestBean implements Comparable<Object> {
@Override
public int compareTo(Object arg0) {
throw new UnsupportedOperationException("compareTo");
}
}
TestBeanSubclass raw = new TestBeanSubclass();
ProxyFactory factory = new ProxyFactory(raw);
//System.out.println("Proxied interfaces are " + StringUtils.arrayToDelimitedString(factory.getProxiedInterfaces(), ","));
assertEquals("Found correct number of interfaces", 5, factory.getProxiedInterfaces().length);
ITestBean tb = (ITestBean) factory.getProxy();
assertThat("Picked up secondary interface", tb, instanceOf(IOther.class));
raw.setAge(25);
assertTrue(tb.getAge() == raw.getAge());
long t = 555555L;
TimestampIntroductionInterceptor ti = new TimestampIntroductionInterceptor(t);
Class<?>[] oldProxiedInterfaces = factory.getProxiedInterfaces();
factory.addAdvisor(0, new DefaultIntroductionAdvisor(ti, TimeStamped.class));
Class<?>[] newProxiedInterfaces = factory.getProxiedInterfaces();
assertEquals("Advisor proxies one more interface after introduction", oldProxiedInterfaces.length + 1, newProxiedInterfaces.length);
TimeStamped ts = (TimeStamped) factory.getProxy();
assertTrue(ts.getTimeStamp() == t);
// Shouldn't fail;
((IOther) ts).absquatulate();
}
use of org.springframework.tests.TimeStamped in project spring-framework by spring-projects.
the class DelegatingIntroductionInterceptorTests method testAutomaticInterfaceRecognitionInDelegate.
@Test
public void testAutomaticInterfaceRecognitionInDelegate() throws Exception {
final long t = 1001L;
class Tester implements TimeStamped, ITester {
@Override
public void foo() throws Exception {
}
@Override
public long getTimeStamp() {
return t;
}
}
DelegatingIntroductionInterceptor ii = new DelegatingIntroductionInterceptor(new Tester());
TestBean target = new TestBean();
ProxyFactory pf = new ProxyFactory(target);
pf.addAdvisor(0, new DefaultIntroductionAdvisor(ii));
//assertTrue(Arrays.binarySearch(pf.getProxiedInterfaces(), TimeStamped.class) != -1);
TimeStamped ts = (TimeStamped) pf.getProxy();
assertTrue(ts.getTimeStamp() == t);
((ITester) ts).foo();
((ITestBean) ts).getAge();
}
use of org.springframework.tests.TimeStamped in project spring-framework by spring-projects.
the class DelegatingIntroductionInterceptorTests method testIntroductionInterceptorWithSuperInterface.
@Test
public void testIntroductionInterceptorWithSuperInterface() throws Exception {
TestBean raw = new TestBean();
assertTrue(!(raw instanceof TimeStamped));
ProxyFactory factory = new ProxyFactory(raw);
TimeStamped ts = mock(SubTimeStamped.class);
long timestamp = 111L;
given(ts.getTimeStamp()).willReturn(timestamp);
factory.addAdvisor(0, new DefaultIntroductionAdvisor(new DelegatingIntroductionInterceptor(ts), TimeStamped.class));
TimeStamped tsp = (TimeStamped) factory.getProxy();
assertTrue(!(tsp instanceof SubTimeStamped));
assertTrue(tsp.getTimeStamp() == timestamp);
}
use of org.springframework.tests.TimeStamped in project spring-framework by spring-projects.
the class DelegatingIntroductionInterceptorTests method testIntroductionInterceptorWithInterfaceHierarchy.
@Test
public void testIntroductionInterceptorWithInterfaceHierarchy() throws Exception {
TestBean raw = new TestBean();
assertTrue(!(raw instanceof SubTimeStamped));
ProxyFactory factory = new ProxyFactory(raw);
TimeStamped ts = mock(SubTimeStamped.class);
long timestamp = 111L;
given(ts.getTimeStamp()).willReturn(timestamp);
factory.addAdvisor(0, new DefaultIntroductionAdvisor(new DelegatingIntroductionInterceptor(ts), SubTimeStamped.class));
SubTimeStamped tsp = (SubTimeStamped) factory.getProxy();
assertTrue(tsp.getTimeStamp() == timestamp);
}
Aggregations