Skip to content
This repository was archived by the owner on Mar 25, 2025. It is now read-only.

Commit a81ae07

Browse files
committed
Added missing Hamcrest matcher documentation
1 parent 41bd842 commit a81ae07

30 files changed

+998
-254
lines changed

webtester-support-hamcrest/src/main/java/info/novatec/testit/webtester/support/hamcrest/WebTesterMatchers.java

Lines changed: 287 additions & 19 deletions
Large diffs are not rendered by default.

webtester-support-hamcrest/src/main/java/info/novatec/testit/webtester/support/hamcrest/matchers/HasMatcher.java

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,33 @@
44
import org.hamcrest.Description;
55
import org.hamcrest.Matcher;
66

7-
7+
import info.novatec.testit.webtester.support.hamcrest.WebTesterMatchers;
8+
9+
10+
/**
11+
* This {@link BaseMatcher} has only syntactical value. Like the {@link org.hamcrest.core.Is} matcher it delegates it's
12+
* evaluation to another matcher. Instances of this matcher should be initialized using the {@link WebTesterMatchers}
13+
* factory class.
14+
* <p>
15+
* <b>Example:</b> assertThat(textField, has(text("foo")));
16+
* <p>
17+
*
18+
* @param <T> the type of the wrapped matcher
19+
* @see WebTesterMatchers
20+
* @since 2.0
21+
*/
822
public class HasMatcher<T> extends BaseMatcher<T> {
923

24+
/** The wrapped matcher instance. */
1025
private final Matcher<T> matcher;
1126

27+
/**
28+
* Creates a new instance with wrapping the given matcher.
29+
*
30+
* @param matcher the matcher to wrap
31+
* @see HasMatcher
32+
* @since 2.0
33+
*/
1234
public HasMatcher(Matcher<T> matcher) {
1335
this.matcher = matcher;
1436
}

webtester-support-hamcrest/src/main/java/info/novatec/testit/webtester/support/hamcrest/matchers/pagefragments/AttributeMatcher.java

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,43 @@
55

66
import info.novatec.testit.webtester.conditions.Conditions;
77
import info.novatec.testit.webtester.pagefragments.PageFragment;
8-
9-
8+
import info.novatec.testit.webtester.support.hamcrest.WebTesterMatchers;
9+
10+
11+
/**
12+
* This {@link TypeSafeMatcher} checks whether or not a specific attribute is present on a {@link PageFragment}.
13+
* Instances of this matcher should be initialized using the {@link WebTesterMatchers} factory class.
14+
* <p>
15+
* <b>Example:</b> assertThat(fragment, has(attribute("type")));
16+
* <p>
17+
*
18+
* @param <T> the type of the checked page fragment
19+
* @see WebTesterMatchers
20+
* @since 2.0
21+
*/
1022
public class AttributeMatcher<T extends PageFragment> extends TypeSafeMatcher<T> {
1123

12-
// TODO: Document
13-
14-
private final String attributeName;
15-
16-
public AttributeMatcher(String attributeName) {
17-
this.attributeName = attributeName;
24+
private final String expected;
25+
26+
/**
27+
* Creates a new instance for the given attribute name.
28+
*
29+
* @param expected the name of the attribute to check
30+
* @see AttributeMatcher
31+
* @since 2.0
32+
*/
33+
public AttributeMatcher(String expected) {
34+
this.expected = expected;
1835
}
1936

2037
@Override
2138
public void describeTo(Description description) {
22-
description.appendText("attribute <" + attributeName + ">");
39+
description.appendText("attribute <" + expected + ">");
2340
}
2441

2542
@Override
2643
protected boolean matchesSafely(T item) {
27-
return Conditions.attribute(attributeName).test(item);
44+
return Conditions.attribute(expected).test(item);
2845
}
2946

3047
@Override

webtester-support-hamcrest/src/main/java/info/novatec/testit/webtester/support/hamcrest/matchers/pagefragments/AttributeValueMatcher.java

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,39 +4,65 @@
44
import org.hamcrest.TypeSafeMatcher;
55

66
import info.novatec.testit.webtester.pagefragments.PageFragment;
7+
import info.novatec.testit.webtester.support.hamcrest.WebTesterMatchers;
78

89

10+
/**
11+
* This {@link TypeSafeMatcher} checks whether or not a specific attribute has a given value on a {@link PageFragment}.
12+
* Instances of this matcher should be initialized using the {@link WebTesterMatchers} factory class.
13+
* <p>
14+
* <b>Example:</b> assertThat(fragment, has(attributeValue("type", "radio")));
15+
* <p>
16+
* <b>Note:</b> This matcher has two possible failure scenarios:
17+
* <ol>
18+
* <li>The attribute does not exist.</li>
19+
* <li>The attribute has a different value.</li>
20+
* </ol>
21+
*
22+
* @param <T> the type of the checked page fragment
23+
* @see WebTesterMatchers
24+
* @since 2.0
25+
*/
926
public class AttributeValueMatcher<T extends PageFragment> extends TypeSafeMatcher<T> {
1027

11-
// TODO: Document
28+
private final String expectedAttributeName;
29+
private final String expectedValue;
1230

13-
private final String attributeName;
14-
private final String value;
31+
/** Boolean to remember if the attribute was present for a possible mismatch description. */
1532
private boolean attributePresent;
33+
/** The actual value for a possible mismatch description. */
1634
private String actualValue;
1735

18-
public AttributeValueMatcher(String attributeName, String value) {
19-
this.attributeName = attributeName;
20-
this.value = value;
36+
/**
37+
* Creates a new instance for the given attribute name and value.
38+
*
39+
* @param expectedAttributeName the name of the attribute to check
40+
* @param expectedValue the expected value of the attribute
41+
* @see AttributeValueMatcher
42+
* @since 2.0
43+
*/
44+
public AttributeValueMatcher(String expectedAttributeName, String expectedValue) {
45+
this.expectedAttributeName = expectedAttributeName;
46+
this.expectedValue = expectedValue;
2147
}
2248

2349
@Override
2450
public void describeTo(Description description) {
25-
description.appendText("attribute <" + attributeName + "> with value <" + value + ">");
51+
description.appendText("attribute <" + expectedAttributeName + "> with value <" + expectedValue + ">");
2652
}
2753

2854
@Override
2955
protected boolean matchesSafely(T item) {
30-
item.getAttribute(attributeName).ifPresent(value -> {
56+
item.getAttribute(expectedAttributeName).ifPresent(value -> {
3157
attributePresent = true;
3258
actualValue = value;
3359
});
34-
return attributePresent && value.equals(actualValue);
60+
return attributePresent && expectedValue.equals(actualValue);
3561
}
3662

3763
@Override
3864
protected void describeMismatchSafely(T item, Description mismatchDescription) {
39-
if(!attributePresent) {
65+
if (!attributePresent) {
4066
mismatchDescription.appendText("attribute was not present");
4167
} else {
4268
mismatchDescription.appendText("value was <" + actualValue + ">");

webtester-support-hamcrest/src/main/java/info/novatec/testit/webtester/support/hamcrest/matchers/pagefragments/ButtonLabelMatcher.java

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,52 @@
44
import org.hamcrest.TypeSafeMatcher;
55

66
import info.novatec.testit.webtester.pagefragments.Button;
7-
8-
7+
import info.novatec.testit.webtester.support.hamcrest.WebTesterMatchers;
8+
9+
10+
/**
11+
* This {@link TypeSafeMatcher} checks whether or not a {@link Button} has a certain label.
12+
* Instances of this matcher should be initialized using the {@link WebTesterMatchers} factory class.
13+
* <p>
14+
* <b>Example:</b> assertThat(button, has(label("type")));
15+
* <p>
16+
*
17+
* @param <T> the type of the checked button
18+
* @see WebTesterMatchers
19+
* @since 2.0
20+
*/
921
public class ButtonLabelMatcher<T extends Button> extends TypeSafeMatcher<T> {
1022

11-
// TODO: Document
23+
private final String expected;
1224

13-
private final String label;
14-
private String actualLabel;
25+
/** The actual label for a possible mismatch description. */
26+
private String actual;
1527

16-
public ButtonLabelMatcher(String label) {
17-
this.label = label;
28+
/**
29+
* Creates a new instance for the given label.
30+
*
31+
* @param expected the label to check
32+
* @see ButtonLabelMatcher
33+
* @since 2.0
34+
*/
35+
public ButtonLabelMatcher(String expected) {
36+
this.expected = expected;
1837
}
1938

2039
@Override
2140
public void describeTo(Description description) {
22-
description.appendText("label <" + label + ">");
41+
description.appendText("label <" + expected + ">");
2342
}
2443

2544
@Override
2645
protected boolean matchesSafely(T item) {
27-
actualLabel = item.getLabel();
28-
return label.equals(actualLabel);
46+
actual = item.getLabel();
47+
return expected.equals(actual);
2948
}
3049

3150
@Override
3251
protected void describeMismatchSafely(T item, Description mismatchDescription) {
33-
mismatchDescription.appendText("was <" + actualLabel + ">");
52+
mismatchDescription.appendText("was <" + actual + ">");
3453
}
3554

3655
}

webtester-support-hamcrest/src/main/java/info/novatec/testit/webtester/support/hamcrest/matchers/pagefragments/DisabledMatcher.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,22 @@
55

66
import info.novatec.testit.webtester.conditions.Conditions;
77
import info.novatec.testit.webtester.pagefragments.PageFragment;
8-
9-
8+
import info.novatec.testit.webtester.support.hamcrest.WebTesterMatchers;
9+
10+
11+
/**
12+
* This {@link TypeSafeMatcher} checks whether or not a {@link PageFragment} is disabled.
13+
* Instances of this matcher should be initialized using the {@link WebTesterMatchers} factory class.
14+
* <p>
15+
* <b>Example:</b> assertThat(fragment, is(disabled()));
16+
* <p>
17+
*
18+
* @param <T> the type of the checked page fragment
19+
* @see WebTesterMatchers
20+
* @since 2.0
21+
*/
1022
public class DisabledMatcher<T extends PageFragment> extends TypeSafeMatcher<T> {
1123

12-
// TODO: Document
13-
1424
@Override
1525
public void describeTo(Description description) {
1626
description.appendText("disabled");

webtester-support-hamcrest/src/main/java/info/novatec/testit/webtester/support/hamcrest/matchers/pagefragments/EnabledMatcher.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,22 @@
55

66
import info.novatec.testit.webtester.conditions.Conditions;
77
import info.novatec.testit.webtester.pagefragments.PageFragment;
8-
9-
8+
import info.novatec.testit.webtester.support.hamcrest.WebTesterMatchers;
9+
10+
11+
/**
12+
* This {@link TypeSafeMatcher} checks whether or not a {@link PageFragment} is enabled.
13+
* Instances of this matcher should be initialized using the {@link WebTesterMatchers} factory class.
14+
* <p>
15+
* <b>Example:</b> assertThat(fragment, is(enabled()));
16+
* <p>
17+
*
18+
* @param <T> the type of the checked page fragment
19+
* @see WebTesterMatchers
20+
* @since 2.0
21+
*/
1022
public class EnabledMatcher<T extends PageFragment> extends TypeSafeMatcher<T> {
1123

12-
// TODO: Document
13-
1424
@Override
1525
public void describeTo(Description description) {
1626
description.appendText("enabled");

webtester-support-hamcrest/src/main/java/info/novatec/testit/webtester/support/hamcrest/matchers/pagefragments/InvisibleMatcher.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,22 @@
55

66
import info.novatec.testit.webtester.conditions.Conditions;
77
import info.novatec.testit.webtester.pagefragments.PageFragment;
8-
9-
8+
import info.novatec.testit.webtester.support.hamcrest.WebTesterMatchers;
9+
10+
11+
/**
12+
* This {@link TypeSafeMatcher} checks whether or not a {@link PageFragment} is invisible.
13+
* Instances of this matcher should be initialized using the {@link WebTesterMatchers} factory class.
14+
* <p>
15+
* <b>Example:</b> assertThat(fragment, is(invisible()));
16+
* <p>
17+
*
18+
* @param <T> the type of the checked page fragment
19+
* @see WebTesterMatchers
20+
* @since 2.0
21+
*/
1022
public class InvisibleMatcher<T extends PageFragment> extends TypeSafeMatcher<T> {
1123

12-
// TODO: Document
13-
1424
@Override
1525
public void describeTo(Description description) {
1626
description.appendText("invisible");

webtester-support-hamcrest/src/main/java/info/novatec/testit/webtester/support/hamcrest/matchers/pagefragments/NoOptionsMatcher.java

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,24 @@
44
import org.hamcrest.TypeSafeMatcher;
55

66
import info.novatec.testit.webtester.pagefragments.GenericSelect;
7-
8-
7+
import info.novatec.testit.webtester.support.hamcrest.WebTesterMatchers;
8+
9+
10+
/**
11+
* This {@link TypeSafeMatcher} checks whether or not a {@link GenericSelect} has no options.
12+
* Instances of this matcher should be initialized using the {@link WebTesterMatchers} factory class.
13+
* <p>
14+
* <b>Example:</b> assertThat(select, has(noOptions()));
15+
* <p>
16+
*
17+
* @param <T> the type of the checked select
18+
* @see WebTesterMatchers
19+
* @since 2.0
20+
*/
921
public class NoOptionsMatcher<T extends GenericSelect<T>> extends TypeSafeMatcher<T> {
1022

11-
// TODO: Document
12-
13-
private int options;
23+
/** The actual number of options for a possible mismatch description. */
24+
private int actual;
1425

1526
@Override
1627
public void describeTo(Description description) {
@@ -19,13 +30,13 @@ public void describeTo(Description description) {
1930

2031
@Override
2132
protected boolean matchesSafely(T item) {
22-
options = item.getOptionCount();
23-
return options == 0;
33+
actual = item.getOptionCount();
34+
return actual == 0;
2435
}
2536

2637
@Override
2738
protected void describeMismatchSafely(T item, Description mismatchDescription) {
28-
mismatchDescription.appendText("has <" + options + "> options");
39+
mismatchDescription.appendText("has <" + actual + "> options");
2940
}
3041

3142
}

0 commit comments

Comments
 (0)