org.springframework.tests.TimeStamped Java Examples
The following examples show how to use
org.springframework.tests.TimeStamped.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AbstractAopProxyTests.java From spring-analysis-note with MIT License | 6 votes |
@Test public void testAdviceImplementsIntroductionInfo() throws Throwable { TestBean tb = new TestBean(); String name = "tony"; tb.setName(name); ProxyFactory pc = new ProxyFactory(tb); NopInterceptor di = new NopInterceptor(); pc.addAdvice(di); final long ts = 37; pc.addAdvice(new DelegatingIntroductionInterceptor(new TimeStamped() { @Override public long getTimeStamp() { return ts; } })); ITestBean proxied = (ITestBean) createProxy(pc); assertEquals(name, proxied.getName()); TimeStamped intro = (TimeStamped) proxied; assertEquals(ts, intro.getTimeStamp()); }
Example #2
Source File: AbstractAopProxyTests.java From java-technology-stack with MIT License | 6 votes |
@Test public void testAdviceImplementsIntroductionInfo() throws Throwable { TestBean tb = new TestBean(); String name = "tony"; tb.setName(name); ProxyFactory pc = new ProxyFactory(tb); NopInterceptor di = new NopInterceptor(); pc.addAdvice(di); final long ts = 37; pc.addAdvice(new DelegatingIntroductionInterceptor(new TimeStamped() { @Override public long getTimeStamp() { return ts; } })); ITestBean proxied = (ITestBean) createProxy(pc); assertEquals(name, proxied.getName()); TimeStamped intro = (TimeStamped) proxied; assertEquals(ts, intro.getTimeStamp()); }
Example #3
Source File: DelegatingIntroductionInterceptorTests.java From java-technology-stack with MIT License | 6 votes |
@Test public void testIntroductionMasksTargetImplementation() throws Exception { final long t = 1001L; @SuppressWarnings("serial") class TestII extends DelegatingIntroductionInterceptor implements TimeStamped { @Override public long getTimeStamp() { return t; } } DelegatingIntroductionInterceptor ii = new TestII(); // != t TestBean target = new TargetClass(t + 1); ProxyFactory pf = new ProxyFactory(target); pf.addAdvisor(0, new DefaultIntroductionAdvisor(ii)); TimeStamped ts = (TimeStamped) pf.getProxy(); // From introduction interceptor, not target assertTrue(ts.getTimeStamp() == t); }
Example #4
Source File: DelegatingIntroductionInterceptorTests.java From java-technology-stack with MIT License | 6 votes |
@Test public void testSerializableDelegatingIntroductionInterceptorSerializable() throws Exception { SerializablePerson serializableTarget = new SerializablePerson(); String name = "Tony"; serializableTarget.setName("Tony"); ProxyFactory factory = new ProxyFactory(serializableTarget); factory.addInterface(Person.class); long time = 1000; TimeStamped ts = new SerializableTimeStamped(time); factory.addAdvisor(new DefaultIntroductionAdvisor(new DelegatingIntroductionInterceptor(ts))); factory.addAdvice(new SerializableNopInterceptor()); Person p = (Person) factory.getProxy(); assertEquals(name, p.getName()); assertEquals(time, ((TimeStamped) p).getTimeStamp()); Person p1 = (Person) SerializationTestUtils.serializeAndDeserialize(p); assertEquals(name, p1.getName()); assertEquals(time, ((TimeStamped) p1).getTimeStamp()); }
Example #5
Source File: DelegatingIntroductionInterceptorTests.java From java-technology-stack with MIT License | 6 votes |
@SuppressWarnings("serial") @Test public void testIntroductionInterceptorDoesntReplaceToString() throws Exception { TestBean raw = new TestBean(); assertTrue(! (raw instanceof TimeStamped)); ProxyFactory factory = new ProxyFactory(raw); TimeStamped ts = new SerializableTimeStamped(0); factory.addAdvisor(0, new DefaultIntroductionAdvisor(new DelegatingIntroductionInterceptor(ts) { @Override public String toString() { throw new UnsupportedOperationException("Shouldn't be invoked"); } })); TimeStamped tsp = (TimeStamped) factory.getProxy(); assertEquals(0, tsp.getTimeStamp()); assertEquals(raw.toString(), tsp.toString()); }
Example #6
Source File: DelegatingIntroductionInterceptorTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@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); }
Example #7
Source File: DelegatingIntroductionInterceptorTests.java From java-technology-stack with MIT License | 6 votes |
@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); }
Example #8
Source File: DelegatingIntroductionInterceptorTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@SuppressWarnings("serial") @Test public void testIntroductionInterceptorDoesntReplaceToString() throws Exception { TestBean raw = new TestBean(); assertTrue(! (raw instanceof TimeStamped)); ProxyFactory factory = new ProxyFactory(raw); TimeStamped ts = new SerializableTimeStamped(0); factory.addAdvisor(0, new DefaultIntroductionAdvisor(new DelegatingIntroductionInterceptor(ts) { @Override public String toString() { throw new UnsupportedOperationException("Shouldn't be invoked"); } })); TimeStamped tsp = (TimeStamped) factory.getProxy(); assertEquals(0, tsp.getTimeStamp()); assertEquals(raw.toString(), tsp.toString()); }
Example #9
Source File: DelegatingIntroductionInterceptorTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Test public void testSerializableDelegatingIntroductionInterceptorSerializable() throws Exception { SerializablePerson serializableTarget = new SerializablePerson(); String name = "Tony"; serializableTarget.setName("Tony"); ProxyFactory factory = new ProxyFactory(serializableTarget); factory.addInterface(Person.class); long time = 1000; TimeStamped ts = new SerializableTimeStamped(time); factory.addAdvisor(new DefaultIntroductionAdvisor(new DelegatingIntroductionInterceptor(ts))); factory.addAdvice(new SerializableNopInterceptor()); Person p = (Person) factory.getProxy(); assertEquals(name, p.getName()); assertEquals(time, ((TimeStamped) p).getTimeStamp()); Person p1 = (Person) SerializationTestUtils.serializeAndDeserialize(p); assertEquals(name, p1.getName()); assertEquals(time, ((TimeStamped) p1).getTimeStamp()); }
Example #10
Source File: DelegatingIntroductionInterceptorTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Test public void testIntroductionMasksTargetImplementation() throws Exception { final long t = 1001L; @SuppressWarnings("serial") class TestII extends DelegatingIntroductionInterceptor implements TimeStamped { @Override public long getTimeStamp() { return t; } } DelegatingIntroductionInterceptor ii = new TestII(); // != t TestBean target = new TargetClass(t + 1); ProxyFactory pf = new ProxyFactory(target); pf.addAdvisor(0, new DefaultIntroductionAdvisor(ii)); TimeStamped ts = (TimeStamped) pf.getProxy(); // From introduction interceptor, not target assertTrue(ts.getTimeStamp() == t); }
Example #11
Source File: DelegatingIntroductionInterceptorTests.java From spring-analysis-note with MIT License | 6 votes |
@Test public void testIntroductionMasksTargetImplementation() throws Exception { final long t = 1001L; @SuppressWarnings("serial") class TestII extends DelegatingIntroductionInterceptor implements TimeStamped { @Override public long getTimeStamp() { return t; } } DelegatingIntroductionInterceptor ii = new TestII(); // != t TestBean target = new TargetClass(t + 1); ProxyFactory pf = new ProxyFactory(target); pf.addAdvisor(0, new DefaultIntroductionAdvisor(ii)); TimeStamped ts = (TimeStamped) pf.getProxy(); // From introduction interceptor, not target assertTrue(ts.getTimeStamp() == t); }
Example #12
Source File: DelegatingIntroductionInterceptorTests.java From spring-analysis-note with MIT License | 6 votes |
@Test public void testSerializableDelegatingIntroductionInterceptorSerializable() throws Exception { SerializablePerson serializableTarget = new SerializablePerson(); String name = "Tony"; serializableTarget.setName("Tony"); ProxyFactory factory = new ProxyFactory(serializableTarget); factory.addInterface(Person.class); long time = 1000; TimeStamped ts = new SerializableTimeStamped(time); factory.addAdvisor(new DefaultIntroductionAdvisor(new DelegatingIntroductionInterceptor(ts))); factory.addAdvice(new SerializableNopInterceptor()); Person p = (Person) factory.getProxy(); assertEquals(name, p.getName()); assertEquals(time, ((TimeStamped) p).getTimeStamp()); Person p1 = (Person) SerializationTestUtils.serializeAndDeserialize(p); assertEquals(name, p1.getName()); assertEquals(time, ((TimeStamped) p1).getTimeStamp()); }
Example #13
Source File: DelegatingIntroductionInterceptorTests.java From spring-analysis-note with MIT License | 6 votes |
@SuppressWarnings("serial") @Test public void testIntroductionInterceptorDoesntReplaceToString() throws Exception { TestBean raw = new TestBean(); assertTrue(! (raw instanceof TimeStamped)); ProxyFactory factory = new ProxyFactory(raw); TimeStamped ts = new SerializableTimeStamped(0); factory.addAdvisor(0, new DefaultIntroductionAdvisor(new DelegatingIntroductionInterceptor(ts) { @Override public String toString() { throw new UnsupportedOperationException("Shouldn't be invoked"); } })); TimeStamped tsp = (TimeStamped) factory.getProxy(); assertEquals(0, tsp.getTimeStamp()); assertEquals(raw.toString(), tsp.toString()); }
Example #14
Source File: AbstractAopProxyTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Test public void testAdviceImplementsIntroductionInfo() throws Throwable { TestBean tb = new TestBean(); String name = "tony"; tb.setName(name); ProxyFactory pc = new ProxyFactory(tb); NopInterceptor di = new NopInterceptor(); pc.addAdvice(di); final long ts = 37; pc.addAdvice(new DelegatingIntroductionInterceptor(new TimeStamped() { @Override public long getTimeStamp() { return ts; } })); ITestBean proxied = (ITestBean) createProxy(pc); assertEquals(name, proxied.getName()); TimeStamped intro = (TimeStamped) proxied; assertEquals(ts, intro.getTimeStamp()); }
Example #15
Source File: DelegatingIntroductionInterceptorTests.java From spring-analysis-note with MIT License | 6 votes |
@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); }
Example #16
Source File: ProxyFactoryTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@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)); }
Example #17
Source File: ProxyFactoryTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@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(); }
Example #18
Source File: ProxyFactoryTests.java From java-technology-stack with MIT License | 5 votes |
@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)); }
Example #19
Source File: BeanNameAutoProxyCreatorTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void testJdkIntroduction() { ITestBean tb = (ITestBean) beanFactory.getBean("introductionUsingJdk"); NopInterceptor nop = (NopInterceptor) beanFactory.getBean("introductionNopInterceptor"); assertEquals(0, nop.getCount()); assertTrue(AopUtils.isJdkDynamicProxy(tb)); int age = 5; tb.setAge(age); assertEquals(age, tb.getAge()); assertTrue("Introduction was made", tb instanceof TimeStamped); assertEquals(0, ((TimeStamped) tb).getTimeStamp()); assertEquals(3, nop.getCount()); assertEquals("introductionUsingJdk", tb.getName()); ITestBean tb2 = (ITestBean) beanFactory.getBean("second-introductionUsingJdk"); // Check two per-instance mixins were distinct Lockable lockable1 = (Lockable) tb; Lockable lockable2 = (Lockable) tb2; assertFalse(lockable1.locked()); assertFalse(lockable2.locked()); tb.setAge(65); assertEquals(65, tb.getAge()); lockable1.lock(); assertTrue(lockable1.locked()); // Shouldn't affect second assertFalse(lockable2.locked()); // Can still mod second object tb2.setAge(12); // But can't mod first try { tb.setAge(6); fail("Mixin should have locked this object"); } catch (LockedException ex) { // Ok } }
Example #20
Source File: BeanNameAutoProxyCreatorTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void testJdkIntroductionAppliesToCreatedObjectsNotFactoryBean() { ITestBean tb = (ITestBean) beanFactory.getBean("factory-introductionUsingJdk"); NopInterceptor nop = (NopInterceptor) beanFactory.getBean("introductionNopInterceptor"); assertEquals("NOP should not have done any work yet", 0, nop.getCount()); assertTrue(AopUtils.isJdkDynamicProxy(tb)); int age = 5; tb.setAge(age); assertEquals(age, tb.getAge()); assertTrue("Introduction was made", tb instanceof TimeStamped); assertEquals(0, ((TimeStamped) tb).getTimeStamp()); assertEquals(3, nop.getCount()); ITestBean tb2 = (ITestBean) beanFactory.getBean("second-introductionUsingJdk"); // Check two per-instance mixins were distinct Lockable lockable1 = (Lockable) tb; Lockable lockable2 = (Lockable) tb2; assertFalse(lockable1.locked()); assertFalse(lockable2.locked()); tb.setAge(65); assertEquals(65, tb.getAge()); lockable1.lock(); assertTrue(lockable1.locked()); // Shouldn't affect second assertFalse(lockable2.locked()); // Can still mod second object tb2.setAge(12); // But can't mod first try { tb.setAge(6); fail("Mixin should have locked this object"); } catch (LockedException ex) { // Ok } }
Example #21
Source File: DelegatingIntroductionInterceptorTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@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(); }
Example #22
Source File: DelegatingIntroductionInterceptorTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@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); }
Example #23
Source File: DelegatingIntroductionInterceptorTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void testIntroductionInterceptorWithDelegation() throws Exception { TestBean raw = new TestBean(); assertTrue(! (raw instanceof TimeStamped)); ProxyFactory factory = new ProxyFactory(raw); TimeStamped ts = mock(TimeStamped.class); long timestamp = 111L; given(ts.getTimeStamp()).willReturn(timestamp); factory.addAdvisor(0, new DefaultIntroductionAdvisor(new DelegatingIntroductionInterceptor(ts))); TimeStamped tsp = (TimeStamped) factory.getProxy(); assertTrue(tsp.getTimeStamp() == timestamp); }
Example #24
Source File: AbstractAopProxyTests.java From java-technology-stack with MIT License | 5 votes |
/** * Note that an introduction can't throw an unexpected checked exception, * as it's constrained by the interface. */ @Test public void testIntroductionThrowsUncheckedException() throws Throwable { TestBean target = new TestBean(); target.setAge(21); ProxyFactory pc = new ProxyFactory(target); @SuppressWarnings("serial") class MyDi extends DelegatingIntroductionInterceptor implements TimeStamped { /** * @see test.util.TimeStamped#getTimeStamp() */ @Override public long getTimeStamp() { throw new UnsupportedOperationException(); } } pc.addAdvisor(new DefaultIntroductionAdvisor(new MyDi())); TimeStamped ts = (TimeStamped) createProxy(pc); try { ts.getTimeStamp(); fail("Should throw UnsupportedOperationException"); } catch (UnsupportedOperationException ex) { } }
Example #25
Source File: AbstractAopProxyTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
/** * Note that an introduction can't throw an unexpected checked exception, * as it's constained by the interface. */ @Test public void testIntroductionThrowsUncheckedException() throws Throwable { TestBean target = new TestBean(); target.setAge(21); ProxyFactory pc = new ProxyFactory(target); @SuppressWarnings("serial") class MyDi extends DelegatingIntroductionInterceptor implements TimeStamped { /** * @see test.util.TimeStamped#getTimeStamp() */ @Override public long getTimeStamp() { throw new UnsupportedOperationException(); } } pc.addAdvisor(new DefaultIntroductionAdvisor(new MyDi())); TimeStamped ts = (TimeStamped) createProxy(pc); try { ts.getTimeStamp(); fail("Should throw UnsupportedOperationException"); } catch (UnsupportedOperationException ex) { } }
Example #26
Source File: AbstractAopProxyTests.java From spring-analysis-note with MIT License | 5 votes |
/** * Note that an introduction can't throw an unexpected checked exception, * as it's constrained by the interface. */ @Test public void testIntroductionThrowsUncheckedException() throws Throwable { TestBean target = new TestBean(); target.setAge(21); ProxyFactory pc = new ProxyFactory(target); @SuppressWarnings("serial") class MyDi extends DelegatingIntroductionInterceptor implements TimeStamped { /** * @see test.util.TimeStamped#getTimeStamp() */ @Override public long getTimeStamp() { throw new UnsupportedOperationException(); } } pc.addAdvisor(new DefaultIntroductionAdvisor(new MyDi())); TimeStamped ts = (TimeStamped) createProxy(pc); try { ts.getTimeStamp(); fail("Should throw UnsupportedOperationException"); } catch (UnsupportedOperationException ex) { } }
Example #27
Source File: DelegatingIntroductionInterceptorTests.java From spring-analysis-note with MIT License | 5 votes |
@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); }
Example #28
Source File: DelegatingIntroductionInterceptorTests.java From spring-analysis-note with MIT License | 5 votes |
@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(); }
Example #29
Source File: ProxyFactoryTests.java From spring-analysis-note with MIT License | 5 votes |
@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)); }
Example #30
Source File: ProxyFactoryTests.java From spring-analysis-note with MIT License | 5 votes |
@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(); }