| 1 | package edu.ucsb.cs156.frontiers.validators; | |
| 2 | ||
| 3 | import edu.ucsb.cs156.frontiers.entities.Course; | |
| 4 | import jakarta.validation.ConstraintValidator; | |
| 5 | import jakarta.validation.ConstraintValidatorContext; | |
| 6 | ||
| 7 | /** | |
| 8 | * This is a validator, which enforces a property. These are used together with @Validated to in a | |
| 9 | * spring managed bean (for example, a controller or service). | |
| 10 | * | |
| 11 | * <p>With this validator, you would have to put lots of code in your controller to check for linked | |
| 12 | * courses. Instead, we can just put @HasLinkedCanvasCourse on the method parameters that require | |
| 13 | * it, and if the contraint is not satisfied, a ConstraintViolationException will be thrown. | |
| 14 | */ | |
| 15 | public class LinkedCourseValidator implements ConstraintValidator<HasLinkedCanvasCourse, Course> { | |
| 16 | ||
| 17 | @Override | |
| 18 | public boolean isValid(Course course, ConstraintValidatorContext constraintValidatorContext) { | |
| 19 |
2
1. isValid : negated conditional → KILLED 2. isValid : replaced boolean return with true for edu/ucsb/cs156/frontiers/validators/LinkedCourseValidator::isValid → KILLED |
return course != null |
| 20 |
1
1. isValid : negated conditional → KILLED |
&& course.getCanvasApiToken() != null |
| 21 |
1
1. isValid : negated conditional → KILLED |
&& course.getCanvasCourseId() != null; |
| 22 | } | |
| 23 | } | |
Mutations | ||
| 19 |
1.1 2.2 |
|
| 20 |
1.1 |
|
| 21 |
1.1 |