I'm new to programming, I want to make tests for my Specification class, but I can't figure out where I should start...how to approach this test?
public class MySpecification implements Specification<R> {
MyRequest request;
public MySpecification (MyRequest request) {
this.request = request;
}
@Override
public Predicate toPredicate(Root<R> root, CriteriaQuery<?> query, CriteriaBuilder criteriaBuilder) {
List<Predicate> predicates = new ArrayList<>();
if (StringUtils.isNotEmpty(request.getEvent())) {
predicates.add(criteriaBuilder.equal(root.get("event"), request.getEvent()));
}
return criteriaBuilder.and(predicates.toArray(new Predicate[0]));
}
}
I created mock objects that I will most likely have to work with
@Mock
Specification<R> spec;
@Mock
Root<R> root;
@Mock
CriteriaQuery<?> query;
@Mock
CriteriaBuilder builder;
@Mock
Predicate predicate;
@Mock
MyRequest request;
I would like to see one or two examples of test implementation for this case, thank you!