@ -1,5 +1,5 @@
@@ -1,5 +1,5 @@
/ *
* Copyright 2014 the original author or authors .
* Copyright 2014 - 2016 the original author or authors .
*
* Licensed under the Apache License , Version 2 . 0 ( the "License" ) ;
* you may not use this file except in compliance with the License .
@ -32,6 +32,7 @@ import org.springframework.beans.NotWritablePropertyException;
@@ -32,6 +32,7 @@ import org.springframework.beans.NotWritablePropertyException;
* Unit tests for { @link PropertyAccessingMethodInterceptor } .
*
* @author Oliver Gierke
* @author Mark Paluch
* /
@RunWith ( MockitoJUnitRunner . class )
public class PropertyAccessingMethodInterceptorUnitTests {
@ -63,67 +64,68 @@ public class PropertyAccessingMethodInterceptorUnitTests {
@@ -63,67 +64,68 @@ public class PropertyAccessingMethodInterceptorUnitTests {
new PropertyAccessingMethodInterceptor ( new Source ( ) ) . invoke ( invocation ) ;
}
/ * *
* @see DATACMNS - 820
* /
@Test
public void triggersWritePropertyAccessOnTarget ( ) throws Throwable {
/ * *
* @see DATAREST - 221
* /
@Test
public void forwardsObjectMethodInvocation ( ) throws Throwable {
Source source = new Source ( ) ;
source . firstname = "Dave" ;
when ( invocation . getMethod ( ) ) . thenReturn ( Object . class . getMethod ( "toString" ) ) ;
when ( invocation . getMethod ( ) ) . thenReturn ( Projection . class . getMethod ( "setFirstname" , String . class ) ) ;
when ( invocation . getArguments ( ) ) . thenReturn ( new Object [ ] { "Carl" } ) ;
MethodInterceptor interceptor = new PropertyAccessingMethodInterceptor ( source ) ;
new PropertyAccessingMethodInterceptor ( new Source ( ) ) . invoke ( invocation ) ;
}
interceptor . invoke ( invocation ) ;
/ * *
* @see DATACMNS - 630
* /
@Test ( expected = IllegalStateException . class )
public void rejectsNonAccessorMethod ( ) throws Throwable {
assertThat ( source . firstname , is ( ( Object ) "Carl" ) ) ;
}
when ( invocation . getMethod ( ) ) . thenReturn ( Projection . class . getMethod ( "someGarbage" ) ) ;
/ * *
* @see DATACMNS - 820
* /
@Test ( expected = IllegalStateException . class )
public void throwsAppropriateExceptionIfTheInvocationHasNoArguments ( ) throws Throwable {
new PropertyAccessingMethodInterceptor ( new Source ( ) ) . invoke ( invocation ) ;
}
Source source = new Source ( ) ;
/ * *
* @see DATACMNS - 820
* /
@Test
public void triggersWritePropertyAccessOnTarget ( ) throws Throwable {
when ( invocation . getMethod ( ) ) . thenReturn ( Projection . class . getMethod ( "setFirstname" , String . class ) ) ;
when ( invocation . getArguments ( ) ) . thenReturn ( new Object [ 0 ] ) ;
MethodInterceptor interceptor = new PropertyAccessingMethodInterceptor ( source ) ;
Source source = new Source ( ) ;
source . firstname = "Dave" ;
interceptor . invoke ( invocation ) ;
}
when ( invocation . getMethod ( ) ) . thenReturn ( Projection . class . getMethod ( "setFirstname" , String . class ) ) ;
when ( invocation . getArguments ( ) ) . thenReturn ( new Object [ ] { "Carl" } ) ;
/ * *
* @see DATACMNS - 820
* /
@Test ( expected = NotWritablePropertyException . class )
public void throwsAppropriateExceptionIfThePropertyCannotWritten ( ) throws Throwable {
new PropertyAccessingMethodInterceptor ( source ) . invoke ( invocation ) ;
when ( invocation . getMethod ( ) ) . thenReturn ( Projection . class . getMethod ( "setGarbage" , String . class ) ) ;
when ( invocation . getArguments ( ) ) . thenReturn ( new Object [ ] { "Carl" } ) ;
new PropertyAccessingMethodInterceptor ( new Source ( ) ) . invoke ( invocation ) ;
}
assertThat ( source . firstname , is ( ( Object ) "Carl" ) ) ;
}
/ * *
* @see DATAREST - 221
* @see DATACMNS - 820
* /
@Test
public void forwardsObjectMethodInvocation ( ) throws Throwable {
@Test ( expected = IllegalStateException . class )
public void throwsAppropriateExceptionIfTheInvocationHasNoArguments ( ) throws Throwable {
when ( invocation . getMethod ( ) ) . thenReturn ( Object . class . getMethod ( "toString" ) ) ;
new PropertyAccessingMethodInterceptor ( new Source ( ) ) . invoke ( invocation ) ;
Source source = new Source ( ) ;
when ( invocation . getMethod ( ) ) . thenReturn ( Projection . class . getMethod ( "setFirstname" , String . class ) ) ;
when ( invocation . getArguments ( ) ) . thenReturn ( new Object [ 0 ] ) ;
new PropertyAccessingMethodInterceptor ( source ) . invoke ( invocation ) ;
}
/ * *
* @see DATACMNS - 630
* @see DATACMNS - 82 0
* /
@Test ( expected = IllegalStateException . class )
public void rejectsNonAccessorMethod ( ) throws Throwable {
@Test ( expected = NotWritablePropertyException . class )
public void throwsAppropriateExceptionIfThePropertyCannotWritten ( ) throws Throwable {
when ( invocation . getMethod ( ) ) . thenReturn ( Projection . class . getMethod ( "setGarbage" , String . class ) ) ;
when ( invocation . getArguments ( ) ) . thenReturn ( new Object [ ] { "Carl" } ) ;
when ( invocation . getMethod ( ) ) . thenReturn ( Projection . class . getMethod ( "someGarbage" ) ) ;
new PropertyAccessingMethodInterceptor ( new Source ( ) ) . invoke ( invocation ) ;
}