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

Commit 6f3224b

Browse files
committed
Added missing tests for conditions packages based on PITest
1 parent b3b1534 commit 6f3224b

30 files changed

+334
-275
lines changed

webtester-core/src/main/java/info/novatec/testit/webtester/browser/operations/JavaScriptExecutor.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ public void execute(String script, PageFragment fragment, Object... parameters)
4949
* @param script the JavaScript code to be executed on the current page
5050
* @param fragment the target {@link PageFragment}
5151
* @param parameters any of Boolean, Long, String, List, WebElement or null.
52+
* @param <T> the type of the return value is cast to before returning
5253
* @return the return value of the JavaScript
5354
* @see JavascriptExecutor#executeScript(String, Object...)
5455
* @since 2.0
@@ -79,6 +80,7 @@ public void execute(String script, Object... parameters) {
7980
*
8081
* @param script the JavaScript code to be executed on the current page
8182
* @param parameters any of Boolean, Long, String, List, WebElement or null.
83+
* @param <T> the type of the return value is cast to before returning
8284
* @return the return value of the JavaScript
8385
* @see JavascriptExecutor#executeScript(String, Object...)
8486
* @since 2.0

webtester-core/src/main/java/info/novatec/testit/webtester/conditions/pagefragments/ReadOnly.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ private boolean isXhtmlReadOnly(String value) {
3333

3434
@Override
3535
public String toString() {
36-
return "read-only";
36+
return "read only";
3737
}
3838

3939
}

webtester-core/src/main/java/info/novatec/testit/webtester/conditions/pagefragments/SelectedTexts.java

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

33
import java.util.Arrays;
44
import java.util.Collection;
5-
import java.util.HashSet;
6-
import java.util.Set;
7-
import java.util.stream.Collectors;
5+
import java.util.LinkedList;
6+
import java.util.List;
87

98
import org.apache.commons.lang.StringUtils;
109

@@ -23,7 +22,7 @@
2322
*/
2423
public class SelectedTexts implements Condition<MultiSelect> {
2524

26-
private final Set<String> expectedTexts = new HashSet<>();
25+
private final List<String> expectedTexts = new LinkedList<>();
2726

2827
public SelectedTexts(String text) {
2928
this.expectedTexts.add(text);
@@ -39,7 +38,8 @@ public SelectedTexts(Collection<String> texts) {
3938

4039
@Override
4140
public boolean test(MultiSelect select) {
42-
return expectedTexts.equals(select.streamSelectionTexts().collect(Collectors.toSet()));
41+
List<String> selectionTexts = select.getSelectionTexts();
42+
return expectedTexts.containsAll(selectionTexts) && selectionTexts.containsAll(expectedTexts);
4343
}
4444

4545
@Override

webtester-core/src/main/java/info/novatec/testit/webtester/conditions/pagefragments/SelectedValues.java

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

33
import java.util.Arrays;
44
import java.util.Collection;
5-
import java.util.HashSet;
6-
import java.util.Set;
7-
import java.util.stream.Collectors;
5+
import java.util.LinkedList;
6+
import java.util.List;
87

98
import org.apache.commons.lang.StringUtils;
109

@@ -23,7 +22,7 @@
2322
*/
2423
public class SelectedValues implements Condition<MultiSelect> {
2524

26-
private final Set<String> expectedValues = new HashSet<>();
25+
private final List<String> expectedValues = new LinkedList<>();
2726

2827
public SelectedValues(String value) {
2928
this.expectedValues.add(value);
@@ -39,7 +38,8 @@ public SelectedValues(Collection<String> values) {
3938

4039
@Override
4140
public boolean test(MultiSelect select) {
42-
return expectedValues.equals(select.streamSelectionValues().collect(Collectors.toSet()));
41+
List<String> selectionValues = select.getSelectionValues();
42+
return expectedValues.containsAll(selectionValues) && selectionValues.containsAll(expectedValues);
4343
}
4444

4545
@Override

webtester-core/src/main/java/info/novatec/testit/webtester/waiting/ConfiguredWait.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public ConfiguredWait(long timeout, TimeUnit timeUnit) {
4444
* {@link PageFragment}.
4545
*
4646
* @param fragment the fragment for the wait until operation
47+
* @param <T> the type of the page fragment subclass
4748
* @return the fluent wait instance
4849
* @see Wait
4950
* @see WaitUntil

webtester-core/src/main/java/info/novatec/testit/webtester/waiting/Wait.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ public static ConfiguredWait withTimeoutOf(long timeout, TimeUnit timeUnit) {
5959
* {@link PageFragment fragment} was created in.
6060
*
6161
* @param fragment the fragment for the wait until operation
62+
* @param <T> the type of the page fragment subclass
6263
* @return the fluent wait instance
6364
* @see Wait
6465
* @see WaitUntil

webtester-core/src/test/java/info/novatec/testit/webtester/conditions/pagefragments/AttributeTest.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,23 @@
1010

1111
public class AttributeTest {
1212

13-
Attribute cut = new Attribute("attribute");
13+
Attribute cut = new Attribute("type");
1414

1515
@Test
1616
public void havingTheAttributeEvaluatesToTrue() {
17-
PageFragment fragment = fragment().withAttribute("attribute").build();
18-
assertThat(hasAttribute(fragment)).isTrue();
17+
PageFragment fragment = fragment().withAttribute("type").build();
18+
assertThat(cut.test(fragment)).isTrue();
1919
}
2020

2121
@Test
2222
public void notHavingTheAttributeEvaluatesToFalse() {
23-
PageFragment fragment = fragment().withoutAttribute("attribute").build();
24-
assertThat(hasAttribute(fragment)).isFalse();
23+
PageFragment fragment = fragment().withoutAttribute("type").build();
24+
assertThat(cut.test(fragment)).isFalse();
2525
}
2626

27-
boolean hasAttribute(PageFragment fragment) {
28-
return cut.test(fragment);
27+
@Test
28+
public void toStringIsGeneratedCorrectly() {
29+
assertThat(cut).hasToString("attribute 'type'");
2930
}
3031

3132
}

webtester-core/src/test/java/info/novatec/testit/webtester/conditions/pagefragments/AttributeWithValueTest.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,28 +10,29 @@
1010

1111
public class AttributeWithValueTest {
1212

13-
AttributeWithValue cut = new AttributeWithValue("attribute", "value");
13+
AttributeWithValue cut = new AttributeWithValue("type", "text");
1414

1515
@Test
1616
public void havingTheAttributeValueMatchEvaluatesToTrue() {
17-
PageFragment fragment = fragment().withAttribute("attribute", "value").build();
18-
assertThat(hasAttributeWithValue(fragment)).isTrue();
17+
PageFragment fragment = fragment().withAttribute("type", "text").build();
18+
assertThat(cut.test(fragment)).isTrue();
1919
}
2020

2121
@Test
2222
public void havingADifferentValueForTheAttributeEvaluatesToFalse() {
23-
PageFragment fragment = fragment().withAttribute("attribute", "otherValue").build();
24-
assertThat(hasAttributeWithValue(fragment)).isFalse();
23+
PageFragment fragment = fragment().withAttribute("type", "password").build();
24+
assertThat(cut.test(fragment)).isFalse();
2525
}
2626

2727
@Test
2828
public void notHavingTheAttributeEvaluatesToFalse() {
29-
PageFragment fragment = fragment().withoutAttribute("attribute").build();
30-
assertThat(hasAttributeWithValue(fragment)).isFalse();
29+
PageFragment fragment = fragment().withoutAttribute("type").build();
30+
assertThat(cut.test(fragment)).isFalse();
3131
}
3232

33-
boolean hasAttributeWithValue(PageFragment fragment) {
34-
return cut.test(fragment);
33+
@Test
34+
public void toStringIsGeneratedCorrectly() {
35+
assertThat(cut).hasToString("attribute 'type' with value 'text'");
3536
}
3637

3738
}

webtester-core/src/test/java/info/novatec/testit/webtester/conditions/pagefragments/DisabledTest.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,18 @@ public class DisabledTest {
1515
@Test
1616
public void disabledPageFragmentEvaluatesToTrue() {
1717
PageFragment fragment = fragment().disabled().build();
18-
assertThat(isDisabled(fragment)).isTrue();
18+
assertThat(cut.test(fragment)).isTrue();
1919
}
2020

2121
@Test
2222
public void enabledPageFragmentEvaluatesToFalse() {
2323
PageFragment fragment = fragment().enabled().build();
24-
assertThat(isDisabled(fragment)).isFalse();
24+
assertThat(cut.test(fragment)).isFalse();
2525
}
2626

27-
boolean isDisabled(PageFragment fragment) {
28-
return cut.test(fragment);
27+
@Test
28+
public void toStringIsGeneratedCorrectly() {
29+
assertThat(cut).hasToString("disabled");
2930
}
3031

3132
}

webtester-core/src/test/java/info/novatec/testit/webtester/conditions/pagefragments/EditableTest.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public void presentVisibleEnabledAndWritablePageFragmentIsEditable() {
2020
.enabled()
2121
.writable()
2222
.build();
23-
assertThat(isEditable(fragment)).isTrue();
23+
assertThat(cut.test(fragment)).isTrue();
2424
}
2525

2626
@Test
@@ -31,7 +31,7 @@ public void notPresentVisibleEnabledAndWritablePageFragmentIsNotEditable() {
3131
.enabled()
3232
.writable()
3333
.build();
34-
assertThat(isEditable(fragment)).isFalse();
34+
assertThat(cut.test(fragment)).isFalse();
3535
}
3636

3737
@Test
@@ -42,7 +42,7 @@ public void presentInvisibleEnabledAndWritablePageFragmentINotEditable() {
4242
.enabled()
4343
.writable()
4444
.build();
45-
assertThat(isEditable(fragment)).isFalse();
45+
assertThat(cut.test(fragment)).isFalse();
4646
}
4747

4848
@Test
@@ -53,7 +53,7 @@ public void presentVisibleDisabledAndWritablePageFragmentIsNotEditable() {
5353
.disabled()
5454
.writable()
5555
.build();
56-
assertThat(isEditable(fragment)).isFalse();
56+
assertThat(cut.test(fragment)).isFalse();
5757
}
5858

5959
@Test
@@ -64,11 +64,12 @@ public void presentVisibleEnabledAndReadOnlyPageFragmentIsNotEditable() {
6464
.enabled()
6565
.readOnly()
6666
.build();
67-
assertThat(isEditable(fragment)).isFalse();
67+
assertThat(cut.test(fragment)).isFalse();
6868
}
6969

70-
boolean isEditable(PageFragment fragment) {
71-
return cut.test(fragment);
70+
@Test
71+
public void toStringIsGeneratedCorrectly() {
72+
assertThat(cut).hasToString("editable");
7273
}
7374

7475
}

0 commit comments

Comments
 (0)