public class SpecValidationContains extends SpecValidation<SpecContains> {
@Override
public void check(PageValidation pageValidation, String objectName, SpecContains spec) throws ValidationErrorException {
PageElement mainObject = pageValidation.findPageElement(objectName);
checkAvailability(mainObject, objectName);
Rect objectArea = mainObject.getArea();
List<String> childObjects = fetchChildObjets(spec.getChildObjects(), pageValidation.getPageSpec());
List<ErrorArea> errorAreas = new LinkedList<ErrorArea>();
List<String> errorMessages = new LinkedList<String>();
for (String childObjectName : childObjects) {
PageElement childObject = pageValidation.findPageElement(childObjectName);
if (childObject != null) {
if (!childObject.isPresent()) {
throw new ValidationErrorException()
.withMessage(format(OBJECT_S_IS_ABSENT_ON_PAGE, childObjectName));
}
else if (!childObject.isVisible()) {
throw new ValidationErrorException()
.withMessage(format(OBJECT_S_IS_NOT_VISIBLE_ON_PAGE, childObjectName));
}
else {
Rect childObjectArea = childObject.getArea();
if (!childObjectMatches(spec, objectArea, childObjectArea)) {
errorAreas.add(new ErrorArea(childObjectArea, childObjectName));
errorMessages.add(format("\"%s\" is outside \"%s\"", childObjectName, objectName));
}
}