8000 #111 Removed mockito usage at ElementFinderUtilsTest · seleniumQuery/seleniumQuery@3364606 · GitHub
[go: up one dir, main page]

Skip to content

Commit 3364606

Browse files
committed
#111 Removed mockito usage at ElementFinderUtilsTest
1 parent 9e59db6 commit 3364606

File tree

9 files changed

+114
-47
lines changed

9 files changed

+114
-47
lines changed

src/main/java/io/github/seleniumquery/utils/DriverVersionUtils.java

Lines changed: 3 additions & 3 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.
@@ -45,8 +45,8 @@ public static DriverVersionUtils getInstance() {
4545
return instance;
4646
}
4747

48-
@VisibleForTesting // this method only exists for test purposes (as this class is a singleton)
49-
public static void setInstance(DriverVersionUtils instance) {
48+
@VisibleForTesting // this method only exists for testing purposes (as this class is a singleton)
49+
public static void overrideSingletonInstance(DriverVersionUtils instance) {
5050
DriverVersionUtils.instance = instance;
5151
}
5252

src/test/java/io/github/seleniumquery/by/secondgen/csstree/condition/pseudoclass/PseudoClassAssertFinderUtils.java

Lines changed: 5 additions & 5 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.
@@ -19,11 +19,11 @@
1919
import io.github.seleniumquery.by.common.elementfilter.ElementFilter;
2020
import io.github.seleniumquery.by.secondgen.csstree.condition.SQCssConditionImplementedFinders;
2121
import io.github.seleniumquery.by.secondgen.finder.ElementFinder;
22-
import io.github.seleniumquery.by.secondgen.finder.ElementFinderUtilsTest;
2322
import org.hamcrest.Matcher;
2423

2524
import java.util.List;
2625

26+
import static io.github.seleniumquery.by.secondgen.finder.ElementFinderUtilsTest.*;
2727
import static org.hamcrest.CoreMatchers.is;
2828
import static org.hamcrest.collection.IsEmptyCollection.empty;
2929
import static org.hamcrest.collection.IsIterableContainingInOrder.contains;
@@ -59,8 +59,8 @@ public static void assertPseudoClassHasElementFinderWhenNativelySupported(String
5959
SQCssConditionImplementedFinders pseudoClassObject,
6060
String expectedCss, boolean canPureCss,
6161
String expectedXPath, Matcher<? super List<ElementFilter>> elementFilterMatcher) {
62-
ElementFinder previousFinder = ElementFinderUtilsTest.universalSelectorFinder(
63-
ElementFinderUtilsTest.mockWebDriverWithNativeSupportFor(pseudoExpressionThatShouldPassNativeSupportCheck)
62+
ElementFinder previousFinder = universalSelectorFinder(
63+
createWebDriverWithNativeSupportForPseudo(pseudoExpressionThatShouldPassNativeSupportCheck)
6464
);
6565
assertPseudoClassHasFinder(
6666
pseudoClassObject,
@@ -77,7 +77,7 @@ private static void assertPseudoClassHasFinderWhenNotNativelySupported(SQCssCond
7777
boolean canPureCss,
7878
String expectedXPath,
7979
Matcher<? super List<ElementFilter>> elementFilterMatcher) {
80-
ElementFinder previousFinder = ElementFinderUtilsTest.universalSelectorFinder(ElementFinderUtilsTest.mockWebDriverWithNativeSupportForNoPseudoClass());
80+
ElementFinder previousFinder = universalSelectorFinder(createWebDriverWithNativeSupportForNoPseudoClass());
8181
assertPseudoClassHasFinder(
8282
pseudoClassObject,
8383
previousFinder,

src/test/java/io/github/seleniumquery/by/secondgen/csstree/condition/pseudoclass/PseudoClassTestUtils.java

Lines changed: 4 additions & 3 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.
@@ -23,9 +23,10 @@
2323
import io.github.seleniumquery.by.firstgen.css.pseudoclasses.PseudoClassSelector;
2424
import io.github.seleniumquery.by.secondgen.csstree.condition.SQCssCondition;
2525
import io.github.seleniumquery.by.secondgen.finder.ElementFinder;
26-
import io.github.seleniumquery.by.secondgen.finder.ElementFinderUtilsTest;
2726
import org.w3c.css.sac.Selector;
2827

28+
import static io.github.seleniumquery.by.secondgen.finder.ElementFinderUtilsTest.createWebDriverWithNativeSupportForNoPseudoClass;
29+
import static io.github.seleniumquery.by.secondgen.finder.ElementFinderUtilsTest.universalSelectorFinder;
2930
import static io.github.seleniumquery.by.secondgen.parser.translator.condition.attribute.TranslatorsTestUtils.parseAndAssertFirstCssCondition;
3031
import static org.hamcrest.CoreMatchers.*;
3132
import static org.hamcrest.collection.IsIterableContainingInOrder.contains;
@@ -118,7 +119,7 @@ private static <T extends SQCssFunctionalPseudoClassCondition> void assertSelect
118119
}
119120

120121
public static void assertFilterOnlyPseudoGeneratesFilter(SQCssPseudoClassCondition pseudoClassCondition, ElementFilter pseudoClassFilter) {
121-
ElementFinder previous = ElementFinderUtilsTest.universalSelectorFinder(ElementFinderUtilsTest.mockWebDriverWithNativeSupportForNoPseudoClass());
122+
ElementFinder previous = universalSelectorFinder(createWebDriverWithNativeSupportForNoPseudoClass());
122123
// when
123124
ElementFinder elementFinder = pseudoClassCondition.toElementFinder(previous);
124125
// then

src/test/java/io/github/seleniumquery/by/secondgen/csstree/condition/pseudoclass/childfilter/SQCssNthChildPseudoClassTest.java

Lines changed: 2 additions & 2 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.
@@ -35,7 +35,7 @@ public class SQCssNthChildPseudoClassTest {
3535

3636
private static final String NTH_CHILD_PSEUDO_USED_IN_NATIVE_SUPPORT_CHECK = NTH_CHILD_PSEUDO+"(1)";
3737
private static final ElementFinder UNIVERSAL_SELECTOR_FINDER_SUPPORTING_NTHCHILD_NATIVELY = universalSelectorFinder(
38-
mockWebDriverWithNativeSupportFor(NTH_CHILD_PSEUDO_USED_IN_NATIVE_SUPPORT_CHECK)
38+
createWebDriverWithNativeSupportForPseudo(NTH_CHILD_PSEUDO_USED_IN_NATIVE_SUPPORT_CHECK)
3939
);
4040
private static final ElementFinder UNIVERSAL_SELECTOR_FINDER_NOT_SUPPORTING_NTHCHILD_NATIVELY = UNIVERSAL_SELECTOR_FINDER;
4141

src/test/java/io/github/seleniumquery/by/secondgen/csstree/condition/pseudoclass/form/SQCssCheckedPseudoClassTest.java

Lines changed: 3 additions & 3 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.
@@ -25,7 +25,7 @@
2525
import static io.github.seleniumquery.by.secondgen.csstree.condition.pseudoclass.PseudoClassAssertFinderUtils.*;
2626
import static io.github.seleniumquery.by.secondgen.csstree.condition.pseudoclass.PseudoClassTestUtils.assertQueriesOnSelector;
2727
import static io.github.seleniumquery.by.secondgen.csstree.condition.pseudoclass.form.SQCssInputTypeAttributePseudoClassTest.TYPE_ATTR_LOWER_CASE;
28-
import static io.github.seleniumquery.by.secondgen.finder.ElementFinderUtilsTest.createMockDriverWithNativeSupporForSelectorAndEmulatingPhantomJS;
28+
import static io.github.seleniumquery.by.secondgen.finder.ElementFinderUtilsTest.createWebDriverEmulatingPhantomJSAndWithNativeSupporForPseudo;
2929
import static org.hamcrest.collection.IsIterableContainingInOrder.contains;
3030

3131
public class SQCssCheckedPseudoClassTest {
@@ -66,7 +66,7 @@ public void toElementFinder__when_driver_does_NOT_have_native_support() {
6666
*/
6767
@Test
6868
public void toElementFinder__when_driver_is_PHANTOMJSDRIVER_it_behaves_like_it_does_NOT_have_native_support() {
69-
ElementFinder previousFinder = ElementFinderUtilsTest.universalSelectorFinder(createMockDriverWithNativeSupporForSelectorAndEmulatingPhantomJS(CHECKED_PSEUDO));
69+
ElementFinder previousFinder = ElementFinderUtilsTest.universalSelectorFinder(createWebDriverEmulatingPhantomJSAndWithNativeSupporForPseudo(CHECKED_PSEUDO));
7070
assertPseudoClassHasFinder(
7171
new SQCssCheckedPseudoClass(),
7272
previousFinder,

src/test/java/io/github/seleniumquery/by/secondgen/csstree/condition/pseudoclass/form/SQCssSelectedPseudoClassTest.java

-5Lines changed: 5 additions & 5 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.
@@ -27,7 +27,7 @@
2727
import static io.github.seleniumquery.by.secondgen.csstree.condition.pseudoclass.PseudoClassAssertFinderUtils.*;
2828
import static io.github.seleniumquery.by.secondgen.csstree.condition.pseudoclass.PseudoClassTestUtils.assertQueriesOnSelector;
2929
import static io.github.seleniumquery.by.secondgen.csstree.condition.pseudoclass.form.SQCssInputTypeAttributePseudoClassTest.TYPE_ATTR_LOWER_CASE;
30-
import static io.github.seleniumquery.by.secondgen.finder.ElementFinderUtilsTest.createMockDriverWithNativeSupporForSelectorAndEmulatingPhantomJS;
30+
import static io.github.seleniumquery.by.secondgen.finder.ElementFinderUtilsTest.createWebDriverEmulatingPhantomJSAndWithNativeSupporForPseudo;
3131
import static io.github.seleniumquery.by.secondgen.finder.ElementFinderUtilsTest.universalSelectorFinder;
3232
import static org.hamcrest.collection.IsIterableContainingInOrder.contains;
3333

@@ -50,7 +50,7 @@ public void translate() {
5050
@Test
5151
public void toElementFinder__when_driver_has_native_support() {
5252
// supports pure CSS, but it is a translated one
53-
ElementFinder previousFinder = universalSelectorFinder(ElementFinderUtilsTest.mockWebDriverWithNativeSupportFor(CHECKED_PSEUDO));
53+
ElementFinder previousFinder = universalSelectorFinder(ElementFinderUtilsTest.createWebDriverWithNativeSupportForPseudo(CHECKED_PSEUDO));
5454
assertPseudoClassHasFinder(
5555
new SQCssSelectedPseudoClass(),
5656
previousFinder,
@@ -73,7 +73,7 @@ public void toElementFinder__when_driver_does_NOT_have_native_support() {
7373
@Test
7474
public void toElementFinder__when_driver_has_native_supportx() {
7575
// supports pure CSS, but it is a translated one
76-
WebDriver mockDriverWithNativeSupportForChecked = ElementFinderUtilsTest.mockWebDriverWithNativeSupportFor(CHECKED_PSEUDO);
76+
WebDriver mockDriverWithNativeSupportForChecked = ElementFinderUtilsTest.createWebDriverWithNativeSupportForPseudo(CHECKED_PSEUDO);
7777
ElementFinder finderAfterChecked = new SQCssCheckedPseudoClass().toElementFinder(universalSelectorFinder(mockDriverWithNativeSupportForChecked));
7878

7979
assertPseudoClassHasFinder(
@@ -93,7 +93,7 @@ public void toElementFinder__when_driver_has_native_supportx() {
9393
*/
9494
@Test
9595
public void toElementFinder__when_driver_is_PHANTOMJSDRIVER_i 2851 t_behaves_like_it_does_NOT_have_native_support() {
96-
WebDriver driver = createMockDriverWithNativeSupporForSelectorAndEmulatingPhantomJS(CHECKED_PSEUDO);
96+
WebDriver driver = createWebDriverEmulatingPhantomJSAndWithNativeSupporForPseudo(CHECKED_PSEUDO);
9797
ElementFinder previousFinder = ElementFinderUtilsTest.universalSelectorFinder(driver);
9898
assertPseudoClassHasFinder(
9999
new SQCssSelectedPseudoClass(),

src/test/java/io/github/seleniumquery/by/secondgen/finder/ElementFinderUtilsTest.java

Lines changed: 14 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@
2424
import static io.github.seleniumquery.by.secondgen.finder.XPathAndFilterFinder.pureXPath;
2525
import static org.hamcrest.CoreMatchers.is;
2626
import static org.junit.Assert.assertThat;
27-
import static org.mockito.Mockito.mock;
28-
import static org.mockito.Mockito.when;
27+
import static testinfrastructure.testdouble.io.github.seleniumquery.utils.DriverVersionUtilsTestBuilder.createDriverVersionUtils;
2928
import static testinfrastructure.testdouble.org.openqa.selenium.WebDriverDummy.createWebDriverDummy;
3029

3130
public class ElementFinderUtilsTest {
@@ -35,33 +34,23 @@ public static ElementFinder universalSelectorFinder(WebDriver driver) {
3534
return new ElementFinder(driver, universalSelector(), pureXPath(".//*[true()]"));
3635
}
3736

38-
public static WebDriver mockWebDriverWithNativeSupportFor(String pseudoClass) {
39-
WebDriver mockDriver = createWebDriverDummy();
40-
DriverVersionUtils driverVersionUtilsMock = overrideDriverVersionUtilsWithMock();
41-
when(driverVersionUtilsMock.hasNativeSupportForPseudo(mockDriver, pseudoClass)).thenReturn(true);
42-
return mockDriver;
37+
public static WebDriver createWebDriverWithNativeSupportForPseudo(String pseudoClass) {
38+
WebDriver webDriverDummy = createWebDriverDummy();
39+
DriverVersionUtils driverVersionUtils = createDriverVersionUtils().withNativeSupportForPseudo(webDriverDummy, pseudoClass).build();
40+
DriverVersionUtils.overrideSingletonInstance(driverVersionUtils);
41+
return webDriverDummy;
4342
}
44-
private static DriverVersionUtils overrideDriverVersionUtilsWithMock() {
45-
DriverVersionUtils driverVersionUtilsMock = mock(DriverVersionUtils.class);
46-
DriverVersionUtils.setInstance(driverVersionUtilsMock);
47-
return driverVersionUtilsMock;
48-
}
49-
public static WebDriver mockWebDriverWithNativeSupportForNoPseudoClass() {
50-
overrideDriverVersionUtilsWithMock();
43+
44+
public static WebDriver createWebDriverWithNativeSupportForNoPseudoClass() {
45+
DriverVersionUtils.overrideSingletonInstance(createDriverVersionUtils().build());
5146
return createWebDriverDummy();
5247
}
5348

54-
public static WebDriver createMockDriverWithNativeSupporForSelectorAndEmulatingPhantomJS(String checkedPseudo) {
55-
WebDriver mockDriverWithNativeSupportFor = ElementFinderUtilsTest.mockWebDriverWithNativeSupportFor(checkedPseudo);
56-
DriverVersionUtils driverVersionUtilsMock = DriverVersionUtils.getInstance();
57-
when(driverVersionUtilsMock.isPhantomJSDriver(mockDriverWithNativeSupportFor)).thenReturn(true);
58-
return mockDriverWithNativeSupportFor;
59-
}
60-
public static WebDriver createMockDriverWithNativeSupporForSelectorAndEmulatingHtmlUnit(String checkedPseudo) {
61-
WebDriver mockDriverWithNativeSupportFor = ElementFinderUtilsTest.mockWebDriverWithNativeSupportFor(checkedPseudo);
62-
DriverVersionUtils driverVersionUtilsMock = DriverVersionUtils.getInstance();
63-
when(driverVersionUtilsMock.isHtmlUnitDriver(mockDriverWithNativeSupportFor)).thenReturn(true);
64-
return mockDriverWithNativeSupportFor;
49+
public static WebDriver createWebDriverEmulatingPhantomJSAndWithNativeSupporForPseudo(String checkedPseudo) {
50+
WebDriver webDriverDummy = createWebDriverDummy();
51+
DriverVersionUtils driverVersionUtils = createDriverVersionUtils().withNativeSupportForPseudo(webDriverDummy, checkedPseudo).emulatingPhantomJS().build();
52+
DriverVersionUtils.overrideSingletonInstance(driverVersionUtils);
53+
return webDriverDummy;
6554
}
6655

6756
@Test
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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.testdouble.io.github.seleniumquery.utils;
18+
19+
import io.github.seleniumquery.utils.DriverVersionUtils;
20+
import org.openqa.selenium.WebDriver;
21+
22+
public class DriverVersionUtilsTestBuilder {
23+
24+
private WebDriver webDriver;
25+
private String pseudoWithNativeSupport;
26+
private boolean isPhantomJSDriver = false;
27+
28+
public static DriverVersionUtilsTestBuilder createDriverVersionUtils() {
29+
return new DriverVersionUtilsTestBuilder();
30+
}
31+
32+
public DriverVersionUtilsTestBuilder withNativeSupportForPseudo(WebDriver driver, String pseudoWithNativeSupport) {
33+
this.webDriver = driver;
34+
this.pseudoWithNativeSupport = pseudoWithNativeSupport;
35+
return this;
36+
}
37+
38+
public DriverVersionUtilsTestBuilder emulatingPhantomJS() {
39+
this.isPhantomJSDriver = true;
40+
return this;
41+
}
42+
43+
public DriverVersionUtils build() {
44+
return new DriverVersionUtils() {
45+
@Override
46+
public boolean hasNativeSupportForPseudo(WebDriver d, String p) {
47+
return webDriver != null && webDriver.equals(d) && pseudoWithNativeSupport != null && pseudoWithNativeSupport.equals(p);
48+
}
49+
50+
@Override
51+
public boolean isPhantomJSDriver(WebDriver driver) {
52+
return isPhantomJSDriver;
53+
}
54+
@Override
55+
public boolean isHtmlUnitDriver(WebDriver driver) {
56+
return false;
57+
}
58+
};
59+
}
60+
61+
}

src/test/java/testinfrastructure/testutils/DriverInTest.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
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 testinfrastructure.testutils;
218

319
import io.github.seleniumquery.utils.DriverVersionUtils;
@@ -13,7 +29,7 @@ public class DriverInTest {
1329

1430
public static void restoreDriverVersionUtilsInstance() {
1531
// restore an eventually overridden (during other tests) instance
16-
DriverVersionUtils.setInstance(new DriverVersionUtils());
32+
DriverVersionUtils.overrideSingletonInstance(new DriverVersionUtils());
1733
}
1834

1935
public static boolean isHtmlUnitDriverEmulatingIEBelow11(WebDriver driver) {

0 commit comments

Comments
 (0)
0