Skip to content
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

Mock Service: Add empty check before accessing first element of a response list #317

Merged
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 @@ -3,6 +3,7 @@
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import jakarta.ws.rs.core.MultivaluedMap;
import java.util.List;
import org.damap.base.rest.base.ResultList;
import org.damap.base.rest.base.Search;
import org.damap.base.rest.dmp.domain.ContributorDO;
Expand All @@ -21,7 +22,11 @@ public class MockUniversityPersonServiceImpl implements PersonService {
/** {@inheritDoc} */
@Override
public ContributorDO read(String id, MultivaluedMap<String, String> queryParams) {
return mockPersonRestService.getContributorDetails(id).get(0);
List<ContributorDO> response = mockPersonRestService.getContributorDetails(id);
if (response.isEmpty()) {
return null;
}
return response.get(0);
}

/** {@inheritDoc} */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@ public ProjectSupplementDO getProjectSupplement(String projectId) {
/** {@inheritDoc} */
@Override
public ContributorDO getProjectLeader(String projectId) {
return mockPersonRestService.getContributorSearchResult().get(0);
List<ContributorDO> response = mockPersonRestService.getContributorSearchResult();
if (response.isEmpty()) {
return null;
}
return response.get(0);
}

/** {@inheritDoc} */
Expand All @@ -60,7 +64,11 @@ public ResultList<ProjectDO> search(MultivaluedMap<String, String> queryParams)
/** {@inheritDoc} */
@Override
public ProjectDO read(String id, MultivaluedMap<String, String> queryParams) {
return mockProjectRestService.getProjectDetails(id).get(0);
List<ProjectDO> response = mockProjectRestService.getProjectDetails(id);
if (response.isEmpty()) {
return null;
}
return response.get(0);
}

/** {@inheritDoc} */
Expand Down
Loading