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

Commit 5d6e21c

Browse files
committed
Optimized Hamcrest matcher tests according to mutation test results
1 parent 27e571d commit 5d6e21c

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,23 +109,23 @@ public static <T extends Button> Matcher<T> label(String label) {
109109
}
110110

111111
public static <T extends MultiSelect> Matcher<T> selectionWithTexts(String... texts) {
112-
return new SelectionTextsMatcher<>(Arrays.asList(texts));
112+
return selectionWithTexts(Arrays.asList(texts));
113113
}
114114

115115
public static <T extends MultiSelect> Matcher<T> selectionWithTexts(List<String> texts) {
116116
return new SelectionTextsMatcher<>(texts);
117117
}
118118

119119
public static <T extends MultiSelect> Matcher<T> selectionWithValues(String... values) {
120-
return new SelectionValuesMatcher<>(Arrays.asList(values));
120+
return selectionWithValues(Arrays.asList(values));
121121
}
122122

123123
public static <T extends MultiSelect> Matcher<T> selectionWithValues(List<String> values) {
124124
return new SelectionValuesMatcher<>(values);
125125
}
126126

127127
public static <T extends MultiSelect> Matcher<T> selectionWithIndices(Integer... indices) {
128-
return new SelectionIndicesMatcher<>(Arrays.asList(indices));
128+
return selectionWithIndices(Arrays.asList(indices));
129129
}
130130

131131
public static <T extends MultiSelect> Matcher<T> selectionWithIndices(List<Integer> indices) {
@@ -169,15 +169,15 @@ public static <T extends GenericSelect> Matcher<T> noOptions() {
169169
}
170170

171171
public static <T extends GenericSelect> Matcher<T> optionsWithTexts(String... texts) {
172-
return new OptionsTextsMatcher<>(Arrays.asList(texts));
172+
return optionsWithTexts(Arrays.asList(texts));
173173
}
174174

175175
public static <T extends GenericSelect> Matcher<T> optionsWithTexts(List<String> texts) {
176176
return new OptionsTextsMatcher<>(texts);
177177
}
178178

179179
public static <T extends GenericSelect> Matcher<T> optionsWithValues(String... values) {
180-
return new OptionsValuesMatcher<>(Arrays.asList(values));
180+
return optionsWithValues(Arrays.asList(values));
181181
}
182182

183183
public static <T extends GenericSelect> Matcher<T> optionsWithValues(List<String> values) {

webtester-support-hamcrest/src/test/java/info/novatec/testit/webtester/support/hamcrest/matchers/pagefragments/AttributeValueMatcherTest.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22

33
import static info.novatec.testit.webtester.support.hamcrest.WebTesterMatchers.attributeValue;
44
import static info.novatec.testit.webtester.support.hamcrest.WebTesterMatchers.has;
5+
import static org.hamcrest.Matchers.containsString;
56
import static org.junit.Assert.assertThat;
67

8+
import org.junit.Rule;
79
import org.junit.Test;
10+
import org.junit.rules.ExpectedException;
811

912
import utils.MockFactory;
1013

@@ -13,22 +16,35 @@
1316

1417
public class AttributeValueMatcherTest {
1518

19+
@Rule
20+
public ExpectedException exception = ExpectedException.none();
21+
1622
@Test
1723
public void attributeWithValueMatches() {
1824
PageFragment fragment = MockFactory.fragment().withAttribute("foo", "value").build();
1925
assertThat(fragment, has(attributeValue("foo", "value")));
2026
}
2127

22-
@Test(expected = AssertionError.class)
28+
@Test
2329
public void nonExistentAttributeDoesNotMatch() {
30+
31+
exception.expect(AssertionError.class);
32+
exception.expectMessage(containsString("attribute was not present"));
33+
2434
PageFragment fragment = MockFactory.fragment().withoutAttribute("foo").build();
2535
assertThat(fragment, has(attributeValue("foo", "value")));
36+
2637
}
2738

28-
@Test(expected = AssertionError.class)
39+
@Test
2940
public void wrongValueDoesNotMatch() {
41+
42+
exception.expect(AssertionError.class);
43+
exception.expectMessage(containsString("value was <other value>"));
44+
3045
PageFragment fragment = MockFactory.fragment().withAttribute("foo", "other value").build();
3146
assertThat(fragment, has(attributeValue("foo", "value")));
47+
3248
}
3349

3450
}

0 commit comments

Comments
 (0)