8000 #97 $().filter("") should return previous, webdriver and sQFunctions … · seleniumQuery/seleniumQuery@b121185 · GitHub
[go: up one dir, main page]

Skip to content

Commit b121185

Browse files
committed
#97 $().filter("") should return previous, webdriver and sQFunctions correctly
1 parent 3075cb7 commit b121185

File tree

3 files changed

+87
-30
lines changed

3 files changed

+87
-30
lines changed

src/test/java/io/github/seleniumquery/functions/jquery/traversing/filtering/filterfunction/FilterPredicateFunctionTest.java

Lines changed: 13 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015 seleniumQuery authors
2+
* Copyright (c) 2016 seleniumQuery authors
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,21 +16,24 @@
1616

1717
package io.github.seleniumquery.functions.jquery.traversing.filtering.filterfunction;
1818

19+
import com.google.common.base.Function;
1920
import com.google.common.base.Predicate;
2021
import io.github.seleniumquery.SeleniumQueryObject;
2122
import org.junit.Test;
2223
import org.openqa.selenium.WebElement;
24+
import testinfrastructure.testutils.FunctionsTestUtils;
2325

24-
import static org.hamcrest.CoreMatchers.is;
2526
import static org.hamcrest.collection.IsEmptyCollection.empty;
2627
import static org.hamcrest.collection.IsIterableContainingInOrder.contains;
2728
import static org.junit.Assert.assertThat;
28-
import static testinfrastructure.testdouble.SeleniumQueryObjectMother.*;
29+
import static testinfrastructure.testdouble.SeleniumQueryObjectMother.createStubSeleniumQueryObjectWithAtLeastOneElement;
30+
import static testinfrastructure.testdouble.SeleniumQueryObjectMother.createStubSeleniumQueryObjectWithElements;
2931
import static testinfrastructure.testdouble.Stubs.createStubWebElementWithTag;
3032

3133
public class FilterPredicateFunctionTest {
3234

3335
private static final Predicate<WebElement> NULL_PREDICATE = null;
36+
private static final Predicate<WebElement> PREDICATE_DOES_NOT_MATTER_IN_THIS_TEST = null;
3437

3538
FilterPredicateFunction filterPredicateFunction = new FilterPredicateFunction();
3639

@@ -45,33 +48,13 @@ public void null_predicate__should_return_EMPTY_element_set() {
4548
}
4649

4750
@Test
48-
public void resultSQO_should_have_targetSQO_as_previous_object() {
49-
// given
50-
SeleniumQueryObject targetSQO = createStubSeleniumQueryObject();
51-
// when
52-
SeleniumQueryObject resultSQO = filterPredicateFunction.filter(targetSQO, NULL_PREDICATE);
53-
// then
54-
assertThat(resultSQO.end(), is(targetSQO));
55-
}
56-
57-
@Test
58-
public void resultSQO_should_have_same_SQFunctions_as_targetSQO() {
59-
// given
60-
SeleniumQueryObject targetSQO = createStubSeleniumQueryObject();
61-
// when
62-
SeleniumQueryObject resultSQO = filterPredicateFunction.filter(targetSQO, NULL_PREDICATE);
63-
// then
64-
assertThat(resultSQO.getSeleniumQueryFunctions(), is(targetSQO.getSeleniumQueryFunctions()));
65-
}
66-
67-
@Test
68-
public void resultSQO_should_have_same_WebDriver_as_targetSQO() {
69-
// given
70-
SeleniumQueryObject targetSQO = createStubSeleniumQueryObject();
71-
// when
72-
SeleniumQueryObject resultSQO = filterPredicateFunction.filter(targetSQO, NULL_PREDICATE);
73-
// then
74-
assertThat(resultSQO.getWebDriver(), is(targetSQO.getWebDriver()));
51+
public void resultSQO_should_have_targetSQO_as_previous_object__and_same_SQFunctions_as_targetSQO__and_same_WebDriver_as_targetSQO() {
52+
FunctionsTestUtils.verifyFunctionReturnsSQOWithCorrectWebDriverAndFunctionsAndPrevious(new Function<SeleniumQueryObject, SeleniumQueryObject>() {
53+
@Override
54+
public SeleniumQueryObject apply(SeleniumQueryObject targetSQO) {
55+
return filterPredicateFunction.filter(targetSQO, PREDICATE_DOES_NOT_MATTER_IN_THIS_TEST);
56+
}
57+
});
7558
}
7659

7760
@Test

src/test/java/io/github/seleniumquery/functions/jquery/traversing/filtering/filterfunction/FilterSelectorFunctionTest.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,25 @@
1+
/*
2+
* Copyright (c) 2016 seleniumQuery authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
117
package io.github.seleniumquery.functions.jquery.traversing.filtering.filterfunction;
218

19+
import com.google.common.base.Function;
320
import io.github.seleniumquery.SeleniumQueryObject;
421
import org.junit.Test;
22+
import testinfrastructure.testutils.FunctionsTestUtils;
523

624
import static org.hamcrest.collection.IsEmptyCollection.empty;
725
import static org.junit.Assert.*;
@@ -10,6 +28,7 @@
1028
public class FilterSelectorFunctionTest {
1129

1230
private static final String NULL_SELECTOR = null;
31+
private static final String SELECTOR_DOES_NOT_MATTER_IN_THIS_TEST = null;
1332

1433
FilterSelectorFunction filterSelectorFunction = new FilterSelectorFunction();
1534

@@ -33,6 +52,16 @@ public void emptyString_selector__should_return_EMPTY_element_set() {
3352
assertThat(resultSQO.get(), empty());
3453
}
3554

55+
@Test
56+
public void resultSQO_should_have_targetSQO_as_previous_object__and_same_SQFunctions_as_targetSQO__and_same_WebDriver_as_targetSQO() {
57+
FunctionsTestUtils.verifyFunctionReturnsSQOWithCorrectWebDriverAndFunctionsAndPrevious(new Function<SeleniumQueryObject, SeleniumQueryObject>() {
58+
@Override
59+
public SeleniumQueryObject apply(SeleniumQueryObject targetSQO) {
60+
return filterSelectorFunction.filter(targetSQO, SELECTOR_DOES_NOT_MATTER_IN_THIS_TEST);
61+
}
62+
});
63+
}
64+
3665
// TODO filter(this, "selector") --> should keep everyone that matches the isFunction("selector")
3766

3867
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Copyright (c) 2016 seleniumQuery authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package testinfrastructure.testutils;
18+
19+
import com.google.common.base.Function;
20+
import io.github.seleniumquery.SeleniumQueryObject;
21+
22+
import static org.hamcrest.CoreMatchers.is;
23+
import static org.hamcrest.CoreMatchers.notNullValue;
24+
import static org.junit.Assert.assertThat;
25+
import static testinfrastructure.testdouble.SeleniumQueryObjectMother.createStubSeleniumQueryObject;
26+
27+
public class FunctionsTestUtils {
28+
29+
public static void verifyFunctionReturnsSQOWithCorrectWebDriverAndFunctionsAndPrevious(Function<SeleniumQueryObject, SeleniumQueryObject> function) {
30+
// given
31+
SeleniumQueryObject targetSQO = createStubSeleniumQueryObject();
32+
// when
33+
SeleniumQueryObject resultSQO = function.apply(targetSQO);
34+
// then
35+
//noinspection ConstantConditions
36+
assertThat(targetSQO.end(), is(notNullValue()));
37+
assertThat(targetSQO.getSeleniumQueryFunctions(), is(notNullValue()));
38+
assertThat(targetSQO.getWebDriver(), is(notNullValue()));
39+
//noinspection ConstantConditions
40+
assertThat(resultSQO.end(), is(targetSQO));
41+
assertThat(resultSQO.getSeleniumQueryFunctions(), is(targetSQO.getSeleniumQueryFunctions()));
42+
assertThat(resultSQO.getWebDriver(), is(targetSQO.getWebDriver()));
43+
}
44+
45+
}

0 commit comments

Comments
 (0)
0