Skip to content
This repository has been archived by the owner on Jul 11, 2021. It is now read-only.

Commit

Permalink
Fix bug where no exception thrown when running test cases that don't …
Browse files Browse the repository at this point in the history
…exist
  • Loading branch information
benjaminkostiuk committed May 5, 2021
1 parent 67dd04a commit a07b97d
Showing 1 changed file with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;

import java.util.HashSet;
import java.util.List;
import java.util.Optional;
import java.util.Set;

@Service
public class CaseService {
Expand Down Expand Up @@ -102,9 +104,20 @@ public Page<Case> getCases(Pageable pageable, Integer id, Integer suiteId, Strin
* @param suiteId Suite id that cases should be part of, otherwise null
* @return List of test cases with the given ids, constrained by the given suite id
*/
public List<Case> getCases(List<Integer> ids, Integer suiteId) {
public List<Case> getCases(List<Integer> ids, Integer suiteId) throws ElementNotFoundException {
// Find all cases with ids
List<Case> cases = caseRepository.findAllById(ids);

// Check that all cases have been found, if not throw exception
if(ids.size() != cases.size()) {
Set<Integer> toBeFound = new HashSet<>(ids);
for(Case caze: cases) {
toBeFound.remove(caze.getId());
}
Integer notFound = toBeFound.iterator().next();
throw new ElementNotFoundException(Case.class, "id", String.valueOf(notFound));
}

// If suite id is specified constrain all cases to be part of the suite
if(suiteId != null) {
for(Case caze: cases) {
Expand Down

0 comments on commit a07b97d

Please sign in to comment.