DATACMNS-655 - Invoking default methods on projection proxies now works.
Extracted DefaultMethodInvokingMethodInterceptor from RepositoryFactorySupport and register it within ProxyProjectionFactory if the code is running on Java 8. Original pull request: #117.
This commit is contained in:
@@ -18,12 +18,16 @@ package org.springframework.data.projection;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.lang.reflect.Proxy;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.aop.Advisor;
|
||||
import org.springframework.aop.TargetClassAware;
|
||||
import org.springframework.aop.framework.Advised;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link ProxyProjectionFactory}.
|
||||
@@ -157,6 +161,21 @@ public class ProxyProjectionFactoryUnitTests {
|
||||
assertThat(result, hasItems("firstname", "address"));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATACMNS-655
|
||||
*/
|
||||
@Test
|
||||
public void invokesDefaultMethodOnProxy() {
|
||||
|
||||
CustomerExcerpt excerpt = factory.createProjection(CustomerExcerpt.class);
|
||||
|
||||
Advised advised = (Advised) ReflectionTestUtils.getField(Proxy.getInvocationHandler(excerpt), "advised");
|
||||
Advisor[] advisors = advised.getAdvisors();
|
||||
|
||||
assertThat(advisors.length, is(greaterThan(0)));
|
||||
assertThat(advisors[0].getAdvice(), is(instanceOf(DefaultMethodInvokingMethodInterceptor.class)));
|
||||
}
|
||||
|
||||
static class Customer {
|
||||
|
||||
public String firstname, lastname;
|
||||
|
||||
Reference in New Issue
Block a user