use of org.springframework.core.testfixture.TimeStamped in project spring-framework by spring-projects.
the class ProxyFactoryTests method testGetsAllInterfaces.
@Test
public void testGetsAllInterfaces() {
// 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(), ","));
assertThat(factory.getProxiedInterfaces().length).as("Found correct number of interfaces").isEqualTo(5);
ITestBean tb = (ITestBean) factory.getProxy();
assertThat(tb).as("Picked up secondary interface").isInstanceOf(IOther.class);
raw.setAge(25);
assertThat(tb.getAge() == raw.getAge()).isTrue();
long t = 555555L;
TimestampIntroductionInterceptor ti = new TimestampIntroductionInterceptor(t);
Class<?>[] oldProxiedInterfaces = factory.getProxiedInterfaces();
factory.addAdvisor(0, new DefaultIntroductionAdvisor(ti, TimeStamped.class));
Class<?>[] newProxiedInterfaces = factory.getProxiedInterfaces();
assertThat(newProxiedInterfaces.length).as("Advisor proxies one more interface after introduction").isEqualTo(oldProxiedInterfaces.length + 1);
TimeStamped ts = (TimeStamped) factory.getProxy();
assertThat(ts.getTimeStamp() == t).isTrue();
// Shouldn't fail;
((IOther) ts).absquatulate();
}
use of org.springframework.core.testfixture.TimeStamped in project spring-framework by spring-projects.
the class ProxyFactoryTests method testAddRepeatedInterface.
@Test
public void testAddRepeatedInterface() {
TimeStamped tst = () -> {
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()).isInstanceOf(TimeStamped.class);
}
use of org.springframework.core.testfixture.TimeStamped in project spring-framework by spring-projects.
the class DelegatingIntroductionInterceptorTests method testIntroductionInterceptorWithInterfaceHierarchy.
@Test
public void testIntroductionInterceptorWithInterfaceHierarchy() throws Exception {
TestBean raw = new TestBean();
assertThat(!(raw instanceof SubTimeStamped)).isTrue();
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();
assertThat(tsp.getTimeStamp() == timestamp).isTrue();
}
use of org.springframework.core.testfixture.TimeStamped in project spring-framework by spring-projects.
the class DelegatingIntroductionInterceptorTests method testIntroductionInterceptorWithSuperInterface.
@Test
public void testIntroductionInterceptorWithSuperInterface() throws Exception {
TestBean raw = new TestBean();
assertThat(!(raw instanceof TimeStamped)).isTrue();
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();
assertThat(!(tsp instanceof SubTimeStamped)).isTrue();
assertThat(tsp.getTimeStamp() == timestamp).isTrue();
}
use of org.springframework.core.testfixture.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();
assertThat(ts.getTimeStamp() == t).isTrue();
((ITester) ts).foo();
((ITestBean) ts).getAge();
}
Aggregations