Skip to content

Commit

Permalink
SLING-7802 apply jetbrains nullability annotations on public API
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanseifert committed Aug 3, 2018
1 parent cd56f3d commit c766eef
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 15 deletions.
8 changes: 8 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,14 @@
<scope>compile</scope>
</dependency>

<!-- Nullability annotations -->
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
<version>16.0.2</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
Expand Down
30 changes: 18 additions & 12 deletions src/main/java/org/apache/sling/testing/mock/jcr/MockJcr.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
import javax.jcr.query.QueryManager;

import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.osgi.annotation.versioning.ConsumerType;

/**
Expand Down Expand Up @@ -55,7 +57,7 @@ private MockJcr() {
* its own data store.
* @return JCR repository
*/
public static Repository newRepository() {
public static @NotNull Repository newRepository() {
return new MockRepository();
}

Expand All @@ -65,19 +67,20 @@ public static Repository newRepository() {
* collected.
* @return JCR session
*/
public static Session newSession() {
public static @NotNull Session newSession() {
return newSession(null, null);
}

/**
* Create a new mocked in-memory JCR session. It contains only the root
* node. All data of the session is thrown away if it gets garbage
* collected.
* @param userId User id for the mock environment.
* @param workspaceName Workspace name for the mock environment.
* @param userId User id for the mock environment. If null a dummy value is used.
* @param workspaceName Workspace name for the mock environment. If null a dummy value is used.
* @return JCR session
*/
public static Session newSession(String userId, String workspaceName) {
@SuppressWarnings("null")
public static @NotNull Session newSession(@Nullable String userId, @Nullable String workspaceName) {
try {
return newRepository().login(
new SimpleCredentials(StringUtils.defaultString(userId, DEFAULT_USER_ID), new char[0]),
Expand All @@ -93,7 +96,7 @@ public static Session newSession(String userId, String workspaceName) {
* @param session JCR session
* @param resultList Result list
*/
public static void setQueryResult(final Session session, final List<Node> resultList) {
public static void setQueryResult(@NotNull final Session session, @NotNull final List<Node> resultList) {
setQueryResult(getQueryManager(session), resultList);
}

Expand All @@ -102,7 +105,7 @@ public static void setQueryResult(final Session session, final List<Node> result
* @param queryManager Mocked query manager
* @param resultList Result list
*/
public static void setQueryResult(final QueryManager queryManager, final List<Node> resultList) {
public static void setQueryResult(@NotNull final QueryManager queryManager, @NotNull final List<Node> resultList) {
addQueryResultHandler(queryManager, new MockQueryResultHandler() {
@Override
public MockQueryResult executeQuery(MockQuery query) {
Expand All @@ -118,7 +121,8 @@ public MockQueryResult executeQuery(MockQuery query) {
* @param language Query language
* @param resultList Result list
*/
public static void setQueryResult(final Session session, final String statement, final String language, final List<Node> resultList) {
public static void setQueryResult(@NotNull final Session session, @NotNull final String statement,
@NotNull final String language, @NotNull final List<Node> resultList) {
setQueryResult(getQueryManager(session), statement, language, resultList);
}

Expand All @@ -129,7 +133,8 @@ public static void setQueryResult(final Session session, final String statement,
* @param language Query language
* @param resultList Result list
*/
public static void setQueryResult(final QueryManager queryManager, final String statement, final String language, final List<Node> resultList) {
public static void setQueryResult(@NotNull final QueryManager queryManager, @NotNull final String statement,
@NotNull final String language, @NotNull final List<Node> resultList) {
addQueryResultHandler(queryManager, new MockQueryResultHandler() {
@Override
public MockQueryResult executeQuery(MockQuery query) {
Expand All @@ -149,7 +154,7 @@ public MockQueryResult executeQuery(MockQuery query) {
* @param session JCR session
* @param resultHandler Mock query result handler
*/
public static void addQueryResultHandler(final Session session, final MockQueryResultHandler resultHandler) {
public static void addQueryResultHandler(@NotNull final Session session, @NotNull final MockQueryResultHandler resultHandler) {
addQueryResultHandler(getQueryManager(session), resultHandler);
}

Expand All @@ -158,11 +163,12 @@ public static void addQueryResultHandler(final Session session, final MockQueryR
* @param queryManager Mocked query manager
* @param resultHandler Mock query result handler
*/
public static void addQueryResultHandler(final QueryManager queryManager, final MockQueryResultHandler resultHandler) {
public static void addQueryResultHandler(@NotNull final QueryManager queryManager, @NotNull final MockQueryResultHandler resultHandler) {
((MockQueryManager)queryManager).addResultHandler(resultHandler);
}

private static QueryManager getQueryManager(Session session) {
@SuppressWarnings("null")
private static @NotNull QueryManager getQueryManager(@NotNull Session session) {
try {
return session.getWorkspace().getQueryManager();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

import org.apache.jackrabbit.commons.iterator.NodeIteratorAdapter;
import org.apache.jackrabbit.commons.iterator.RowIteratorAdapter;
import org.jetbrains.annotations.Nullable;
import org.osgi.annotation.versioning.ProviderType;

import com.google.common.base.Function;
Expand Down Expand Up @@ -64,7 +65,7 @@ public String[] getColumnNames() throws RepositoryException {
public RowIterator getRows() throws RepositoryException {
return new RowIteratorAdapter(Lists.transform(nodes, new Function<Node, Row>() {
@Override
public Row apply(Node node) {
public Row apply(@Nullable Node node) {
return new MockRow(columnNames, node);
}
}));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@
/**
* Mock implementation of selected JCR APIs.
*/
@org.osgi.annotation.versioning.Version("1.0.1")
@org.osgi.annotation.versioning.Version("1.0.2")
package org.apache.sling.testing.mock.jcr;
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ public class MockNodeTest {
private Node rootNode;
private Node node1;
private Property prop1;
private Property prop2;
private Node node11;

@Before
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@

import com.google.common.collect.ImmutableList;

@SuppressWarnings("null")
public class MockQueryManagerTest {

private Session session;
Expand Down

0 comments on commit c766eef

Please sign in to comment.