Skip to content

DATACMNS-1201 - Support generated property accessors for types in default packages. #256

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>org.springframework.data</groupId>
<artifactId>spring-data-commons</artifactId>
<version>2.1.0.BUILD-SNAPSHOT</version>
<version>2.1.0.DATACMNS-1201-SNAPSHOT</version>

<name>Spring Data Core</name>

Expand Down Expand Up @@ -163,7 +163,7 @@
<version>1.0.1</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>javax.interceptor</groupId>
<artifactId>javax.interceptor-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,10 @@ private static boolean isClassLoaderDefineClassAvailable(PersistentEntity<?, ?>
}

private static boolean isTypeInjectable(PersistentEntity<?, ?> entity) {
return entity.getType().getClassLoader() != null && !entity.getType().getPackage().getName().startsWith("java");

Class<?> type = entity.getType();
return type.getClassLoader() != null
&& (type.getPackage() == null || !type.getPackage().getName().startsWith("java"));
}

private boolean hasUniquePropertyHashCodes(PersistentEntity<?, ?> entity) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.springframework.data.mapping.model;

import static org.assertj.core.api.Assertions.*;
import static org.junit.Assume.*;

import java.lang.reflect.Constructor;
import java.util.ArrayList;
Expand All @@ -36,6 +36,7 @@
import org.springframework.data.mapping.context.SamplePersistentProperty;
import org.springframework.data.mapping.model.subpackage.TypeInOtherPackage;
import org.springframework.test.util.ReflectionTestUtils;
import org.springframework.util.StringUtils;

/**
* Unit tests for {@link ClassGeneratingPropertyAccessorFactory}
Expand All @@ -61,7 +62,8 @@ public ClassGeneratingPropertyAccessorFactoryTests(Object bean, String propertyN
}

@Parameters(name = "{3}")
public static List<Object[]> parameters() {
@SuppressWarnings("unchecked")
public static List<Object[]> parameters() throws ReflectiveOperationException {

List<Object[]> parameters = new ArrayList<>();
List<String> propertyNames = Arrays.asList("privateField", "packageDefaultField", "protectedField", "publicField",
Expand All @@ -79,6 +81,11 @@ public static List<Object[]> parameters() {
ClassGeneratingPropertyAccessorPublicType.class));
parameters.addAll(parameters(new SubtypeOfTypeInOtherPackage(), propertyNames, SubtypeOfTypeInOtherPackage.class));

Class<Object> defaultPackageClass = (Class) Class.forName("TypeInDefaultPackage");

parameters
.add(new Object[] { defaultPackageClass.newInstance(), "", defaultPackageClass, "Class in default package" });

return parameters;
}

Expand All @@ -94,9 +101,16 @@ private static List<Object[]> parameters(Object bean, List<String> propertyNames
return parameters;
}

@Test // DATACMNS-1201
public void shouldSupportGeneratedPropertyAccessors() {
assertThat(factory.isSupported(mappingContext.getRequiredPersistentEntity(bean.getClass()))).isTrue();
}

@Test // DATACMNS-809
public void shouldSetAndGetProperty() throws Exception {

assumeTrue(StringUtils.hasText(propertyName));

assertThat(getProperty(bean, propertyName)).satisfies(property -> {

PersistentPropertyAccessor persistentPropertyAccessor = getPersistentPropertyAccessor(bean);
Expand Down