diff --git a/spring-data-neo4j/src/main/java/org/springframework/data/neo4j/repository/support/SimpleNeo4jRepository.java b/spring-data-neo4j/src/main/java/org/springframework/data/neo4j/repository/support/SimpleNeo4jRepository.java index fa4affefe..e8980aa2e 100644 --- a/spring-data-neo4j/src/main/java/org/springframework/data/neo4j/repository/support/SimpleNeo4jRepository.java +++ b/spring-data-neo4j/src/main/java/org/springframework/data/neo4j/repository/support/SimpleNeo4jRepository.java @@ -43,6 +43,7 @@ import org.springframework.util.Assert; * @author Mark Paluch * @author Jens Schauder * @author Gerrit Meier + * @author Michael J. Simons */ @Repository @Transactional(readOnly = true) @@ -140,6 +141,7 @@ public class SimpleNeo4jRepository implements Neo4jR @Override public Optional findById(ID id, int depth) { + Assert.notNull(id, ID_MUST_NOT_BE_NULL); return Optional.ofNullable(session.load(clazz, id, depth)); } diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/repository/support/SimpleNeo4jRepositoryTests.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/repository/support/SimpleNeo4jRepositoryTests.java index bb7b7d8df..53658f5a5 100644 --- a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/repository/support/SimpleNeo4jRepositoryTests.java +++ b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/repository/support/SimpleNeo4jRepositoryTests.java @@ -28,6 +28,10 @@ import org.neo4j.ogm.session.Session; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; +/** + * @author Gerrit Meier + * @author Michael J. Simons + */ public class SimpleNeo4jRepositoryTests { private final Session sessionMock = mock(Session.class); @@ -136,6 +140,22 @@ public class SimpleNeo4jRepositoryTests { assertThat(page.getTotalElements()).isEqualTo(amountOfElementsInDatabase); } + @Test // DATAGRAPH-1260 + public void idShouldBeAsserted() { + + assertThatIllegalArgumentException() + .isThrownBy(() -> repository.findById(null)) + .withMessage("The given id must not be null!"); + } + + @Test // DATAGRAPH-1260 + public void idShouldBeAssertedWithDepth() { + + assertThatIllegalArgumentException() + .isThrownBy(() -> repository.findById(null, 42)) + .withMessage("The given id must not be null!"); + } + private Page loadPage(PageRequest requestedPage, long amountOfElementsInDatabase) { prepareSessionMock(requestedPage, amountOfElementsInDatabase); return repository.findAll(requestedPage);