|
1 | 1 | /*
|
2 |
| - * Copyright 2014 the original author or authors. |
| 2 | + * Copyright 2014-2016 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
32 | 32 | * Unit tests for {@link PropertyAccessingMethodInterceptor}.
|
33 | 33 | *
|
34 | 34 | * @author Oliver Gierke
|
| 35 | + * @author Mark Paluch |
35 | 36 | */
|
36 | 37 | @RunWith(MockitoJUnitRunner.class)
|
37 | 38 | public class PropertyAccessingMethodInterceptorUnitTests {
|
@@ -63,67 +64,68 @@ public void throwsAppropriateExceptionIfThePropertyCannotBeFound() throws Throwa
|
63 | 64 | new PropertyAccessingMethodInterceptor(new Source()).invoke(invocation);
|
64 | 65 | }
|
65 | 66 |
|
66 |
| - /** |
67 |
| - * @see DATACMNS-820 |
68 |
| - */ |
69 |
| - @Test |
70 |
| - public void triggersWritePropertyAccessOnTarget() throws Throwable { |
| 67 | + /** |
| 68 | + * @see DATAREST-221 |
| 69 | + */ |
| 70 | + @Test |
| 71 | + public void forwardsObjectMethodInvocation() throws Throwable { |
71 | 72 |
|
72 |
| - Source source = new Source(); |
73 |
| - source.firstname = "Dave"; |
| 73 | + when(invocation.getMethod()).thenReturn(Object.class.getMethod("toString")); |
74 | 74 |
|
75 |
| - when(invocation.getMethod()).thenReturn(Projection.class.getMethod("setFirstname", String.class)); |
76 |
| - when(invocation.getArguments()).thenReturn(new Object[] { "Carl" }); |
77 |
| - MethodInterceptor interceptor = new PropertyAccessingMethodInterceptor(source); |
| 75 | + new PropertyAccessingMethodInterceptor(new Source()).invoke(invocation); |
| 76 | + } |
78 | 77 |
|
79 |
| - interceptor.invoke(invocation); |
| 78 | + /** |
| 79 | + * @see DATACMNS-630 |
| 80 | + */ |
| 81 | + @Test(expected = IllegalStateException.class) |
| 82 | + public void rejectsNonAccessorMethod() throws Throwable { |
80 | 83 |
|
81 |
| - assertThat(source.firstname, is((Object) "Carl")); |
82 |
| - } |
| 84 | + when(invocation.getMethod()).thenReturn(Projection.class.getMethod("someGarbage")); |
83 | 85 |
|
84 |
| - /** |
85 |
| - * @see DATACMNS-820 |
86 |
| - */ |
87 |
| - @Test(expected = IllegalStateException.class) |
88 |
| - public void throwsAppropriateExceptionIfTheInvocationHasNoArguments() throws Throwable { |
| 86 | + new PropertyAccessingMethodInterceptor(new Source()).invoke(invocation); |
| 87 | + } |
89 | 88 |
|
90 |
| - Source source = new Source(); |
| 89 | + /** |
| 90 | + * @see DATACMNS-820 |
| 91 | + */ |
| 92 | + @Test |
| 93 | + public void triggersWritePropertyAccessOnTarget() throws Throwable { |
91 | 94 |
|
92 |
| - when(invocation.getMethod()).thenReturn(Projection.class.getMethod("setFirstname", String.class)); |
93 |
| - when(invocation.getArguments()).thenReturn(new Object[0]); |
94 |
| - MethodInterceptor interceptor = new PropertyAccessingMethodInterceptor(source); |
| 95 | + Source source = new Source(); |
| 96 | + source.firstname = "Dave"; |
95 | 97 |
|
96 |
| - interceptor.invoke(invocation); |
97 |
| - } |
| 98 | + when(invocation.getMethod()).thenReturn(Projection.class.getMethod("setFirstname", String.class)); |
| 99 | + when(invocation.getArguments()).thenReturn(new Object[] { "Carl" }); |
98 | 100 |
|
99 |
| - /** |
100 |
| - * @see DATACMNS-820 |
101 |
| - */ |
102 |
| - @Test(expected = NotWritablePropertyException.class) |
103 |
| - public void throwsAppropriateExceptionIfThePropertyCannotWritten() throws Throwable { |
| 101 | + new PropertyAccessingMethodInterceptor(source).invoke(invocation); |
104 | 102 |
|
105 |
| - when(invocation.getMethod()).thenReturn(Projection.class.getMethod("setGarbage", String.class)); |
106 |
| - when(invocation.getArguments()).thenReturn(new Object[] { "Carl" }); |
107 |
| - new PropertyAccessingMethodInterceptor(new Source()).invoke(invocation); |
108 |
| - } |
| 103 | + assertThat(source.firstname, is((Object) "Carl")); |
| 104 | + } |
109 | 105 |
|
110 | 106 | /**
|
111 |
| - * @see DATAREST-221 |
| 107 | + * @see DATACMNS-820 |
112 | 108 | */
|
113 |
| - @Test |
114 |
| - public void forwardsObjectMethodInvocation() throws Throwable { |
| 109 | + @Test(expected = IllegalStateException.class) |
| 110 | + public void throwsAppropriateExceptionIfTheInvocationHasNoArguments() throws Throwable { |
115 | 111 |
|
116 |
| - when(invocation.getMethod()).thenReturn(Object.class.getMethod("toString")); |
117 |
| - new PropertyAccessingMethodInterceptor(new Source()).invoke(invocation); |
| 112 | + Source source = new Source(); |
| 113 | + |
| 114 | + when(invocation.getMethod()).thenReturn(Projection.class.getMethod("setFirstname", String.class)); |
| 115 | + when(invocation.getArguments()).thenReturn(new Object[0]); |
| 116 | + |
| 117 | + new PropertyAccessingMethodInterceptor(source).invoke(invocation); |
118 | 118 | }
|
119 | 119 |
|
120 | 120 | /**
|
121 |
| - * @see DATACMNS-630 |
| 121 | + * @see DATACMNS-820 |
122 | 122 | */
|
123 |
| - @Test(expected = IllegalStateException.class) |
124 |
| - public void rejectsNonAccessorMethod() throws Throwable { |
| 123 | + @Test(expected = NotWritablePropertyException.class) |
| 124 | + public void throwsAppropriateExceptionIfThePropertyCannotWritten() throws Throwable { |
| 125 | + |
| 126 | + when(invocation.getMethod()).thenReturn(Projection.class.getMethod("setGarbage", String.class)); |
| 127 | + when(invocation.getArguments()).thenReturn(new Object[] { "Carl" }); |
125 | 128 |
|
126 |
| - when(invocation.getMethod()).thenReturn(Projection.class.getMethod("someGarbage")); |
127 | 129 | new PropertyAccessingMethodInterceptor(new Source()).invoke(invocation);
|
128 | 130 | }
|
129 | 131 |
|
|
0 commit comments