Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public static Object setPropertyValue(Object context, String property, Object va
} else {
final Field field = ReflectionUtils.findField(context.getClass(), property);
if (field != null) {
if (Modifier.isFinal(field.getModifiers())) {
if (Modifier.isFinal(field.getModifiers()) || Modifier.isPrivate(field.getModifiers())) {
field.setAccessible(true);
}
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,14 @@
import com.mmnaseri.utils.spring.data.store.impl.MemoryDataStore;
import org.hamcrest.Matchers;
import org.springframework.data.domain.AuditorAware;
import org.springframework.data.jpa.repository.JpaRepository;
import org.testng.annotations.Test;

import java.util.Arrays;
import java.util.List;

import javax.persistence.Id;

import static com.mmnaseri.utils.spring.data.dsl.factory.RepositoryFactoryBuilder.given;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsInAnyOrder;
Expand Down Expand Up @@ -460,4 +463,26 @@ public void testSaveIterable() {
assertThat(repository.findAll(), hasSize(3));
assertThat(repository.findAll(), containsInAnyOrder(((List) iterable).toArray()));
}

// please move the code where it should be
public class EntityWithAnnotatedIdFieldAndGetter {
@Id
private Long id;
public Long getId() {
return id;
}
}

// please move the code where it should be
public interface RepositoryForIssue extends JpaRepository<EntityWithAnnotatedIdFieldAndGetter, Long> {
}

// please move the code where it should be
@Test
public void privateIdFieldIssue() {
final RepositoryForIssue repository =
RepositoryFactoryBuilder.builder().mock(RepositoryForIssue.class);
repository.save(new EntityWithAnnotatedIdFieldAndGetter());
assertThat(repository.findAll(), hasSize(1));
}
}