Java Code Examples for org.springframework.tests.sample.beans.ITestBean#setAge()

The following examples show how to use org.springframework.tests.sample.beans.ITestBean#setAge() . 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: JndiObjectFactoryBeanTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void testLookupWithProxyInterfaceAndLazyLookup() throws Exception {
	JndiObjectFactoryBean jof = new JndiObjectFactoryBean();
	final TestBean tb = new TestBean();
	jof.setJndiTemplate(new JndiTemplate() {
		@Override
		public Object lookup(String name) {
			if ("foo".equals(name)) {
				tb.setName("tb");
				return tb;
			}
			return null;
		}
	});
	jof.setJndiName("foo");
	jof.setProxyInterface(ITestBean.class);
	jof.setLookupOnStartup(false);
	jof.afterPropertiesSet();
	assertTrue(jof.getObject() instanceof ITestBean);
	ITestBean proxy = (ITestBean) jof.getObject();
	assertNull(tb.getName());
	assertEquals(0, tb.getAge());
	proxy.setAge(99);
	assertEquals("tb", tb.getName());
	assertEquals(99, tb.getAge());
}
 
Example 2
Source File: ProxyFactoryTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void testRemoveAdvisorByReference() {
	TestBean target = new TestBean();
	ProxyFactory pf = new ProxyFactory(target);
	NopInterceptor nop = new NopInterceptor();
	CountingBeforeAdvice cba = new CountingBeforeAdvice();
	Advisor advisor = new DefaultPointcutAdvisor(cba);
	pf.addAdvice(nop);
	pf.addAdvisor(advisor);
	ITestBean proxied = (ITestBean) pf.getProxy();
	proxied.setAge(5);
	assertEquals(1, cba.getCalls());
	assertEquals(1, nop.getCount());
	assertTrue(pf.removeAdvisor(advisor));
	assertEquals(5, proxied.getAge());
	assertEquals(1, cba.getCalls());
	assertEquals(2, nop.getCount());
	assertFalse(pf.removeAdvisor(new DefaultPointcutAdvisor(null)));
}
 
Example 3
Source File: AdvisorAutoProxyCreatorIntegrationTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
public void testTransactionAttributeOnMethod() throws Exception {
	BeanFactory bf = getBeanFactory();
	ITestBean test = (ITestBean) bf.getBean("test");

	CallCountingTransactionManager txMan = (CallCountingTransactionManager) bf.getBean(TXMANAGER_BEAN_NAME);
	OrderedTxCheckAdvisor txc = (OrderedTxCheckAdvisor) bf.getBean("orderedBeforeTransaction");
	assertEquals(0, txc.getCountingBeforeAdvice().getCalls());

	assertEquals(0, txMan.commits);
	assertEquals("Initial value was correct", 4, test.getAge());
	int newAge = 5;
	test.setAge(newAge);
	assertEquals(1, txc.getCountingBeforeAdvice().getCalls());

	assertEquals("New value set correctly", newAge, test.getAge());
	assertEquals("Transaction counts match", 1, txMan.commits);
}
 
Example 4
Source File: BenchmarkTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
private long testAfterReturningAdviceWithoutJoinPoint(String file, int howmany, String technology) {
	ClassPathXmlApplicationContext bf = new ClassPathXmlApplicationContext(file, CLASS);

	StopWatch sw = new StopWatch();
	sw.start(howmany + " repeated after returning advice invocations with " + technology);
	ITestBean adrian = (ITestBean) bf.getBean("adrian");

	assertTrue(AopUtils.isAopProxy(adrian));
	Advised a = (Advised) adrian;
	assertTrue(a.getAdvisors().length >= 3);
	// Hits joinpoint
	adrian.setAge(25);

	for (int i = 0; i < howmany; i++) {
		adrian.setAge(i);
	}

	sw.stop();
	System.out.println(sw.prettyPrint());
	return sw.getLastTaskTimeMillis();
}
 
Example 5
Source File: AbstractAopProxyTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void testReplaceArgument() throws Throwable {
	TestBean tb = new TestBean();
	ProxyFactory pc = new ProxyFactory();
	pc.addInterface(ITestBean.class);
	pc.setTarget(tb);
	pc.addAdvisor(new StringSetterNullReplacementAdvice());

	ITestBean t = (ITestBean) pc.getProxy();
	int newAge = 5;
	t.setAge(newAge);
	assertEquals(newAge, t.getAge());
	String newName = "greg";
	t.setName(newName);
	assertEquals(newName, t.getName());

	t.setName(null);
	// Null replacement magic should work
	assertEquals("", t.getName());
}
 
Example 6
Source File: AbstractAopProxyTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void testReentrance() {
	int age1 = 33;

	TestBean target1 = new TestBean();
	ProxyFactory pf1 = new ProxyFactory(target1);
	NopInterceptor di1 = new NopInterceptor();
	pf1.addAdvice(0, di1);
	ITestBean advised1 = (ITestBean) createProxy(pf1);
	advised1.setAge(age1); // = 1 invocation
	advised1.setSpouse(advised1); // = 2 invocations

	assertEquals("one was invoked correct number of times", 2, di1.getCount());

	assertEquals("Advised one has correct age", age1, advised1.getAge()); // = 3 invocations
	assertEquals("one was invoked correct number of times", 3, di1.getCount());

	// = 5 invocations, as reentrant call to spouse is advised also
	assertEquals("Advised spouse has correct age", age1, advised1.getSpouse().getAge());

	assertEquals("one was invoked correct number of times", 5, di1.getCount());
}
 
Example 7
Source File: BeanNameAutoProxyCreatorTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@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 8
Source File: BeanNameAutoProxyCreatorTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
private void jdkAssertions(ITestBean tb, int nopInterceptorCount)  {
	NopInterceptor nop = (NopInterceptor) beanFactory.getBean("nopInterceptor");
	assertEquals(0, nop.getCount());
	assertTrue(AopUtils.isJdkDynamicProxy(tb));
	int age = 5;
	tb.setAge(age);
	assertEquals(age, tb.getAge());
	assertEquals(2 * nopInterceptorCount, nop.getCount());
}
 
Example 9
Source File: HttpInvokerTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void httpInvokerProxyFactoryBeanAndServiceExporterWithIOException() throws Exception {
	TestBean target = new TestBean("myname", 99);

	final HttpInvokerServiceExporter exporter = new HttpInvokerServiceExporter();
	exporter.setServiceInterface(ITestBean.class);
	exporter.setService(target);
	exporter.afterPropertiesSet();

	HttpInvokerProxyFactoryBean pfb = new HttpInvokerProxyFactoryBean();
	pfb.setServiceInterface(ITestBean.class);
	pfb.setServiceUrl("http://myurl");

	pfb.setHttpInvokerRequestExecutor(new HttpInvokerRequestExecutor() {
		@Override
		public RemoteInvocationResult executeRequest(
				HttpInvokerClientConfiguration config, RemoteInvocation invocation) throws IOException {
			throw new IOException("argh");
		}
	});

	pfb.afterPropertiesSet();
	ITestBean proxy = (ITestBean) pfb.getObject();
	try {
		proxy.setAge(50);
		fail("Should have thrown RemoteAccessException");
	}
	catch (RemoteAccessException ex) {
		// expected
		assertTrue(ex.getCause() instanceof IOException);
	}
}
 
Example 10
Source File: AbstractAopProxyTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void testCanCastProxyToProxyConfig() throws Throwable {
	TestBean tb = new TestBean();
	ProxyFactory pc = new ProxyFactory(tb);
	NopInterceptor di = new NopInterceptor();
	pc.addAdvice(0, di);

	ITestBean t = (ITestBean) createProxy(pc);
	assertEquals(0, di.getCount());
	t.setAge(23);
	assertEquals(23, t.getAge());
	assertEquals(2, di.getCount());

	Advised advised = (Advised) t;
	assertEquals("Have 1 advisor", 1, advised.getAdvisors().length);
	assertEquals(di, advised.getAdvisors()[0].getAdvice());
	NopInterceptor di2 = new NopInterceptor();
	advised.addAdvice(1, di2);
	t.getName();
	assertEquals(3, di.getCount());
	assertEquals(1, di2.getCount());
	// will remove di
	advised.removeAdvisor(0);
	t.getAge();
	// Unchanged
	assertEquals(3, di.getCount());
	assertEquals(2, di2.getCount());

	CountingBeforeAdvice cba = new CountingBeforeAdvice();
	assertEquals(0, cba.getCalls());
	advised.addAdvice(cba);
	t.setAge(16);
	assertEquals(16, t.getAge());
	assertEquals(2, cba.getCalls());
}
 
Example 11
Source File: AspectJAutoProxyCreatorTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void testPerTargetAspect() throws SecurityException, NoSuchMethodException {
	ClassPathXmlApplicationContext bf = newContext("pertarget.xml");

	ITestBean adrian1 = (ITestBean) bf.getBean("adrian");
	assertTrue(AopUtils.isAopProxy(adrian1));

	// Does not trigger advice or count
	int explicitlySetAge = 25;
	adrian1.setAge(explicitlySetAge);

	assertEquals("Setter does not initiate advice", explicitlySetAge, adrian1.getAge());
	// Fire aspect

	AspectMetadata am = new AspectMetadata(PerTargetAspect.class, "someBean");
	assertTrue(am.getPerClausePointcut().getMethodMatcher().matches(TestBean.class.getMethod("getSpouse"), null));

	adrian1.getSpouse();

	assertEquals("Advice has now been instantiated", 0, adrian1.getAge());
	adrian1.setAge(11);
	assertEquals("Any int setter increments", 2, adrian1.getAge());
	adrian1.setName("Adrian");
	//assertEquals("Any other setter does not increment", 2, adrian1.getAge());

	ITestBean adrian2 = (ITestBean) bf.getBean("adrian");
	assertNotSame(adrian1, adrian2);
	assertTrue(AopUtils.isAopProxy(adrian1));
	assertEquals(34, adrian2.getAge());
	adrian2.getSpouse();
	assertEquals("Aspect now fired", 0, adrian2.getAge());
	assertEquals(1, adrian2.getAge());
	assertEquals(2, adrian2.getAge());
	assertEquals(3, adrian1.getAge());
}
 
Example 12
Source File: BeanNameAutoProxyCreatorTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@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 13
Source File: ProxyFactoryBeanTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * Note that we can't add or remove interfaces without reconfiguring the
 * singleton.
 */
@Test
public void testCanAddAndRemoveAdvicesOnSingleton() {
	ITestBean it = (ITestBean) factory.getBean("test1");
	Advised pc = (Advised) it;
	it.getAge();
	NopInterceptor di = new NopInterceptor();
	pc.addAdvice(0, di);
	assertEquals(0, di.getCount());
	it.setAge(25);
	assertEquals(25, it.getAge());
	assertEquals(2, di.getCount());
}
 
Example 14
Source File: JndiObjectFactoryBeanTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void testLookupWithProxyInterface() throws Exception {
	JndiObjectFactoryBean jof = new JndiObjectFactoryBean();
	TestBean tb = new TestBean();
	jof.setJndiTemplate(new ExpectedLookupTemplate("foo", tb));
	jof.setJndiName("foo");
	jof.setProxyInterface(ITestBean.class);
	jof.afterPropertiesSet();
	assertTrue(jof.getObject() instanceof ITestBean);
	ITestBean proxy = (ITestBean) jof.getObject();
	assertEquals(0, tb.getAge());
	proxy.setAge(99);
	assertEquals(99, tb.getAge());
}
 
Example 15
Source File: ProxyFactoryTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void testReplaceAdvisor() {
	TestBean target = new TestBean();
	ProxyFactory pf = new ProxyFactory(target);
	NopInterceptor nop = new NopInterceptor();
	CountingBeforeAdvice cba1 = new CountingBeforeAdvice();
	CountingBeforeAdvice cba2 = new CountingBeforeAdvice();
	Advisor advisor1 = new DefaultPointcutAdvisor(cba1);
	Advisor advisor2 = new DefaultPointcutAdvisor(cba2);
	pf.addAdvisor(advisor1);
	pf.addAdvice(nop);
	ITestBean proxied = (ITestBean) pf.getProxy();
	// Use the type cast feature
	// Replace etc methods on advised should be same as on ProxyFactory
	Advised advised = (Advised) proxied;
	proxied.setAge(5);
	assertEquals(1, cba1.getCalls());
	assertEquals(0, cba2.getCalls());
	assertEquals(1, nop.getCount());
	assertFalse(advised.replaceAdvisor(new DefaultPointcutAdvisor(new NopInterceptor()), advisor2));
	assertTrue(advised.replaceAdvisor(advisor1, advisor2));
	assertEquals(advisor2, pf.getAdvisors()[0]);
	assertEquals(5, proxied.getAge());
	assertEquals(1, cba1.getCalls());
	assertEquals(2, nop.getCount());
	assertEquals(1, cba2.getCalls());
	assertFalse(pf.replaceAdvisor(new DefaultPointcutAdvisor(null), advisor1));
}
 
Example 16
Source File: AbstractAopProxyTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * There are times when we want to call proceed() twice.
 * We can do this if we clone the invocation.
 */
@Test
public void testCloneInvocationToProceedThreeTimes() throws Throwable {
	TestBean tb = new TestBean();
	ProxyFactory pc = new ProxyFactory(tb);
	pc.addInterface(ITestBean.class);

	MethodInterceptor twoBirthdayInterceptor = new MethodInterceptor() {
		@Override
		public Object invoke(MethodInvocation mi) throws Throwable {
			// Clone the invocation to proceed three times
			// "The Moor's Last Sigh": this technology can cause premature aging
			MethodInvocation clone1 = ((ReflectiveMethodInvocation) mi).invocableClone();
			MethodInvocation clone2 = ((ReflectiveMethodInvocation) mi).invocableClone();
			clone1.proceed();
			clone2.proceed();
			return mi.proceed();
		}
	};
	@SuppressWarnings("serial")
	StaticMethodMatcherPointcutAdvisor advisor = new StaticMethodMatcherPointcutAdvisor(twoBirthdayInterceptor) {
		@Override
		public boolean matches(Method m, @Nullable Class<?> targetClass) {
			return "haveBirthday".equals(m.getName());
		}
	};
	pc.addAdvisor(advisor);
	ITestBean it = (ITestBean) createProxy(pc);

	final int age = 20;
	it.setAge(age);
	assertEquals(age, it.getAge());
	// Should return the age before the third, AOP-induced birthday
	assertEquals(age + 2, it.haveBirthday());
	// Return the final age produced by 3 birthdays
	assertEquals(age + 3, it.getAge());
}
 
Example 17
Source File: AbstractAopProxyTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void testMultiAdvice() throws Throwable {
	CountingMultiAdvice cca = new CountingMultiAdvice();
	@SuppressWarnings("serial")
	Advisor matchesNoArgs = new StaticMethodMatcherPointcutAdvisor(cca) {
		@Override
		public boolean matches(Method m, Class<?> targetClass) {
			return m.getParameterTypes().length == 0 || "exceptional".equals(m.getName());
		}
	};
	TestBean target = new TestBean();
	target.setAge(80);
	ProxyFactory pf = new ProxyFactory(target);
	pf.addAdvice(new NopInterceptor());
	pf.addAdvisor(matchesNoArgs);
	assertEquals("Advisor was added", matchesNoArgs, pf.getAdvisors()[1]);
	ITestBean proxied = (ITestBean) createProxy(pf);

	assertEquals(0, cca.getCalls());
	assertEquals(0, cca.getCalls("getAge"));
	assertEquals(target.getAge(), proxied.getAge());
	assertEquals(2, cca.getCalls());
	assertEquals(2, cca.getCalls("getAge"));
	assertEquals(0, cca.getCalls("setAge"));
	// Won't be advised
	proxied.setAge(26);
	assertEquals(2, cca.getCalls());
	assertEquals(26, proxied.getAge());
	assertEquals(4, cca.getCalls());
	try {
		proxied.exceptional(new SpecializedUncheckedException("foo", (SQLException)null));
		fail("Should have thrown CannotGetJdbcConnectionException");
	}
	catch (SpecializedUncheckedException ex) {
		// expected
	}
	assertEquals(6, cca.getCalls());
}
 
Example 18
Source File: HttpInvokerTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void httpInvokerProxyFactoryBeanAndServiceExporterWithIOException() throws Exception {
	TestBean target = new TestBean("myname", 99);

	final HttpInvokerServiceExporter exporter = new HttpInvokerServiceExporter();
	exporter.setServiceInterface(ITestBean.class);
	exporter.setService(target);
	exporter.afterPropertiesSet();

	HttpInvokerProxyFactoryBean pfb = new HttpInvokerProxyFactoryBean();
	pfb.setServiceInterface(ITestBean.class);
	pfb.setServiceUrl("http://myurl");

	pfb.setHttpInvokerRequestExecutor(new HttpInvokerRequestExecutor() {
		@Override
		public RemoteInvocationResult executeRequest(
				HttpInvokerClientConfiguration config, RemoteInvocation invocation) throws IOException {
			throw new IOException("argh");
		}
	});

	pfb.afterPropertiesSet();
	ITestBean proxy = (ITestBean) pfb.getObject();
	try {
		proxy.setAge(50);
		fail("Should have thrown RemoteAccessException");
	}
	catch (RemoteAccessException ex) {
		// expected
		assertTrue(ex.getCause() instanceof IOException);
	}
}
 
Example 19
Source File: AbstractAopProxyTests.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
/**
 * Check that the two MethodInvocations necessary are independent and
 * don't conflict.
 * Check also proxy exposure.
 */
@Test
public void testOneAdvisedObjectCallsAnother() {
	int age1 = 33;
	int age2 = 37;

	TestBean target1 = new TestBean();
	ProxyFactory pf1 = new ProxyFactory(target1);
	// Permit proxy and invocation checkers to get context from AopContext
	pf1.setExposeProxy(true);
	NopInterceptor di1 = new NopInterceptor();
	pf1.addAdvice(0, di1);
	pf1.addAdvice(1, new ProxyMatcherInterceptor());
	pf1.addAdvice(2, new CheckMethodInvocationIsSameInAndOutInterceptor());
	pf1.addAdvice(1, new CheckMethodInvocationViaThreadLocalIsSameInAndOutInterceptor());
	// Must be first
	pf1.addAdvice(0, ExposeInvocationInterceptor.INSTANCE);
	ITestBean advised1 = (ITestBean) pf1.getProxy();
	advised1.setAge(age1); // = 1 invocation

	TestBean target2 = new TestBean();
	ProxyFactory pf2 = new ProxyFactory(target2);
	pf2.setExposeProxy(true);
	NopInterceptor di2 = new NopInterceptor();
	pf2.addAdvice(0, di2);
	pf2.addAdvice(1, new ProxyMatcherInterceptor());
	pf2.addAdvice(2, new CheckMethodInvocationIsSameInAndOutInterceptor());
	pf2.addAdvice(1, new CheckMethodInvocationViaThreadLocalIsSameInAndOutInterceptor());
	pf2.addAdvice(0, ExposeInvocationInterceptor.INSTANCE);
	ITestBean advised2 = (ITestBean) createProxy(pf2);
	advised2.setAge(age2);
	advised1.setSpouse(advised2); // = 2 invocations

	assertEquals("Advised one has correct age", age1, advised1.getAge()); // = 3 invocations
	assertEquals("Advised two has correct age", age2, advised2.getAge());
	// Means extra call on advised 2
	assertEquals("Advised one spouse has correct age", age2, advised1.getSpouse().getAge()); // = 4 invocations on 1 and another one on 2

	assertEquals("one was invoked correct number of times", 4, di1.getCount());
	// Got hit by call to advised1.getSpouse().getAge()
	assertEquals("one was invoked correct number of times", 3, di2.getCount());
}
 
Example 20
Source File: AbstractAspectJAdvisorFactoryTests.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@Test
@Ignore
public void testIntroductionWithArgumentBinding() {
	TestBean target = new TestBean();

	List<Advisor> advisors = getFixture().getAdvisors(
			new SingletonMetadataAwareAspectInstanceFactory(new MakeITestBeanModifiable(),"someBean"));
	advisors.addAll(getFixture().getAdvisors(
			new SingletonMetadataAwareAspectInstanceFactory(new MakeLockable(),"someBean")));

	Modifiable modifiable = (Modifiable) createProxy(target,
			advisors,
			ITestBean.class);
	assertThat(modifiable, instanceOf(Modifiable.class));
	Lockable lockable = (Lockable) modifiable;
	assertFalse(lockable.locked());

	ITestBean itb = (ITestBean) modifiable;
	assertFalse(modifiable.isModified());
	int oldAge = itb.getAge();
	itb.setAge(oldAge + 1);
	assertTrue(modifiable.isModified());
	modifiable.acceptChanges();
	assertFalse(modifiable.isModified());
	itb.setAge(itb.getAge());
	assertFalse("Setting same value does not modify", modifiable.isModified());
	itb.setName("And now for something completely different");
	assertTrue(modifiable.isModified());

	lockable.lock();
	assertTrue(lockable.locked());
	try {
		itb.setName("Else");
		fail("Should be locked");
	}
	catch (IllegalStateException ex) {
		// Ok
	}
	lockable.unlock();
	itb.setName("Tony");
}