com.connect_group.thymeleaf.testing.hamcrest.HasComment Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of thymeleaf-tdd Show documentation
Show all versions of thymeleaf-tdd Show documentation
Test-Driven Development framework for Thymeleaf and Thymesheet
The newest version!
package com.connect_group.thymeleaf.testing.hamcrest;
import com.connect_group.thymesheet.query.HtmlElement;
import java.util.List;
import org.hamcrest.Description;
import org.hamcrest.TypeSafeMatcher;
import org.thymeleaf.dom.Comment;
import org.thymeleaf.dom.Element;
import org.thymeleaf.dom.Node;
public class HasComment extends TypeSafeMatcher {
private final String expectedText;
public HasComment() {
this.expectedText = null;
}
public HasComment(String expectedText) {
this.expectedText = expectedText;
}
@Override
public void describeTo(Description description) {
if (expectedText == null) {
description.appendText("has at least one comment");
} else {
description.appendText("has a comment ");
}
}
@Override
protected boolean matchesSafely(HtmlElement item) {
Element element = item.getElement();
if (element != null && element.hasChildren()) {
List children = element.getChildren();
for (Node child : children) {
if (child instanceof Comment) {
if (expectedText == null) {
return true;
} else {
if (expectedText.equals(((Comment) child).getContent())) {
return true;
}
}
}
}
}
return false;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy