use of org.aopalliance.intercept.MethodInterceptor in project spring-data-commons by spring-projects.
the class ProjectingMethodInterceptorUnitTests method appliesProjectionToNonEmptyMap.
// DATAREST-394, DATAREST-408
@Test
@SuppressWarnings("unchecked")
public void appliesProjectionToNonEmptyMap() throws Throwable {
MethodInterceptor methodInterceptor = new ProjectingMethodInterceptor(new ProxyProjectionFactory(), interceptor, conversionService);
Object result = methodInterceptor.invoke(mockInvocationOf("getHelperMap", Collections.singletonMap("foo", mock(Helper.class))));
assertThat(result).isInstanceOf(Map.class);
Map<String, Object> projections = (Map<String, Object>) result;
assertThat(projections).hasSize(1);
assertThat(projections).matches(map -> map.get("foo") instanceof HelperProjection);
}
use of org.aopalliance.intercept.MethodInterceptor in project spring-data-commons by spring-projects.
the class ProjectingMethodInterceptorUnitTests method retunsDelegateResultAsIsIfTypesMatch.
// DATAREST-221
@Test
public void retunsDelegateResultAsIsIfTypesMatch() throws Throwable {
MethodInterceptor methodInterceptor = new ProjectingMethodInterceptor(factory, interceptor, conversionService);
when(invocation.getMethod()).thenReturn(Helper.class.getMethod("getString"));
when(interceptor.invoke(invocation)).thenReturn("Foo");
assertThat(methodInterceptor.invoke(invocation)).isEqualTo("Foo");
}
use of org.aopalliance.intercept.MethodInterceptor in project spring-data-commons by spring-projects.
the class ProjectingMethodInterceptorUnitTests method appliesProjectionToNonEmptySets.
// DATAREST-394, DATAREST-408
@Test
@SuppressWarnings("unchecked")
public void appliesProjectionToNonEmptySets() throws Throwable {
MethodInterceptor methodInterceptor = new ProjectingMethodInterceptor(new ProxyProjectionFactory(), interceptor, conversionService);
Object result = methodInterceptor.invoke(mockInvocationOf("getHelperCollection", Collections.singleton(mock(Helper.class))));
assertThat(result).isInstanceOf(Set.class);
Set<Object> projections = (Set<Object>) result;
assertThat(projections).hasSize(1);
assertThat(projections).hasOnlyElementsOfType(HelperProjection.class);
}
use of org.aopalliance.intercept.MethodInterceptor in project spring-data-commons by spring-projects.
the class ProjectingMethodInterceptorUnitTests method allowsMaskingAnArrayIntoACollection.
// DATAREST-394, DATAREST-408
@Test
@SuppressWarnings("unchecked")
public void allowsMaskingAnArrayIntoACollection() throws Throwable {
MethodInterceptor methodInterceptor = new ProjectingMethodInterceptor(new ProxyProjectionFactory(), interceptor, conversionService);
Object result = methodInterceptor.invoke(mockInvocationOf("getHelperArray", new Helper[] { mock(Helper.class) }));
assertThat(result).isInstanceOf(Collection.class);
Collection<Object> projections = (Collection<Object>) result;
assertThat(projections).hasSize(1);
assertThat(projections).hasOnlyElementsOfType(HelperProjection.class);
}
use of org.aopalliance.intercept.MethodInterceptor in project spring-data-commons by spring-projects.
the class PropertyAccessingMethodInterceptorUnitTests method triggersPropertyAccessOnTarget.
// DATAREST-221
@Test
public void triggersPropertyAccessOnTarget() throws Throwable {
Source source = new Source();
source.firstname = "Dave";
when(invocation.getMethod()).thenReturn(Projection.class.getMethod("getFirstname"));
MethodInterceptor interceptor = new PropertyAccessingMethodInterceptor(source);
assertThat(interceptor.invoke(invocation)).isEqualTo("Dave");
}
Aggregations