8000 #111 Further removal of mockito usages · seleniumQuery/seleniumQuery@c79a5ef · GitHub
[go: up one dir, main page]

Skip to content

Commit c79a5ef

Browse files
committed
#111 Further removal of mockito usages
1 parent 59b0556 commit c79a5ef

File tree

Collapse file tree

14 files changed

+230
-123
lines changed

14 files changed

+230
-123
lines changed

src/test/java/io/github/seleniumquery/SeleniumQueryObjectTest.java

Lines changed: 8 additions & 8 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,9 +25,9 @@
2525
import static org.hamcrest.MatcherAssert.assertThat;
2626
import static org.mockito.BDDMockito.given;
2727
import static org.mockito.Mockito.mock;
28-
import static testinfrastructure.testdouble.Dummies.createDummyWebElementPredicate;
29-
import static testinfrastructure.testdouble.SeleniumQueryObjectMother.createDummySeleniumQueryObject;
30-
import static testinfrastructure.testdouble.SeleniumQueryObjectMother.createStubSeleniumQueryObjectWithSeleniumQueryFunctions;
28+
import static testinfrastructure.testdouble.com.google.common.base.PredicateMother.createDummyWebElementPredicate;
29+
import static testinfrastructure.testdouble.io.github.seleniumquery.SeleniumQueryObjectMother.createStubSeleniumQueryObjectWithSeleniumQueryFunctions;
30+
import static testinfrastructure.testdouble.io.github.seleniumquery.SeleniumQueryObjectDummy.createSeleniumQueryObjectDummy;
3131

3232
public class SeleniumQueryObjectTest {
3333

@@ -58,7 +58,7 @@ public void propWrite() {
5858

5959
String propertyName = "propertyName";
6060
String propertyValue = "propertyValue";
61-
SeleniumQueryObject configuredReturningObject = createDummySeleniumQueryObject();
61+
SeleniumQueryObject configuredReturningObject = createSeleniumQueryObjectDummy();
6262
given(seleniumQueryFunctions.propertyWrite(seleniumQueryObject, propertyName, propertyValue)).willReturn(configuredReturningObject);
6363
// when
6464
SeleniumQueryObject returnedObject = seleniumQueryObject.prop(propertyName, propertyValue);
@@ -87,7 +87,7 @@ public void valWriteString() {
8787
SeleniumQueryObject seleniumQueryObject = createStubSeleniumQueryObjectWithSeleniumQueryFunctions(seleniumQueryFunctions);
8888

8989
String propertyValue = "propertyValue";
90-
SeleniumQueryObject configuredReturningObject = createDummySeleniumQueryObject();
90+
SeleniumQueryObject configuredReturningObject = createSeleniumQueryObjectDummy();
9191
given(seleniumQueryFunctions.valueWrite(seleniumQueryObject, propertyValue)).willReturn(configuredReturningObject);
9292
// when
9393
SeleniumQueryObject returnedObject = seleniumQueryObject.val(propertyValue);
@@ -102,7 +102,7 @@ public void valWriteNumber() {
102102
SeleniumQueryObject seleniumQueryObject = createStubSeleniumQueryObjectWithSeleniumQueryFunctions(seleniumQueryFunctions);
103103

104104
Number propertyValue = 1.0;
105-
SeleniumQueryObject configuredReturningObject = createDummySeleniumQueryObject();
105+
SeleniumQueryObject configuredReturningObject = createSeleniumQueryObjectDummy();
106106
given(seleniumQueryFunctions.valueWrite(seleniumQueryObject, propertyValue)).willReturn(configuredReturningObject);
107107
// when
108108
SeleniumQueryObject returnedObject = seleniumQueryObject.val(propertyValue);
@@ -115,7 +115,7 @@ public void filterPredicateFunction() {
115115
// given
116116
SeleniumQueryFunctions seleniumQueryFunctions = createMockSeleniumQueryFunctions();
117117
SeleniumQueryObject seleniumQueryObject = createStubSeleniumQueryObjectWithSeleniumQueryFunctions(seleniumQueryFunctions);
118-
SeleniumQueryObject configuredReturningObject = createDummySeleniumQueryObject();
118+
SeleniumQueryObject configuredReturningObject = createSeleniumQueryObjectDummy();
119119

120120
Predicate<WebElement> filterFunction = createDummyWebElementPredicate();
121121
given(seleniumQueryFunctions.filterPredicate(seleniumQueryObject, filterFunction)).willReturn(configuredReturningObject);

src/test/java/io/github/seleniumquery/by/secondgen/csstree/selector/SQCssTagNameSelectorTest.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.
@@ -22,7 +22,7 @@
2222
import static org.hamcrest.CoreMatchers.is;
2323
import static org.hamcrest.collection.IsEmptyCollection.empty;
2424
import static org.junit.Assert.assertThat;
25-
import static testinfrastructure.testdouble.Dummies.createDummyWebDriver;
25+
import static testinfrastructure.testdouble.org.openqa.selenium.WebDriverDummy.createWebDriverDummy;
2626

2727
public class SQCssTagNameSelectorTest {
2828

@@ -31,7 +31,7 @@ public void toElementFinder() {
3131
// given
3232
SQCssTagNameSelector tagNameSelector = new SQCssTagNameSelector("myTag");
3333
// when
34-
ElementFinder elementFinder = tagNameSelector.toElementFinder(createDummyWebDriver());
34+
ElementFinder elementFinder = tagNameSelector.toElementFinder(createWebDriverDummy());
3535
// then
3636
assertThat(elementFinder.getCssFinder().toString(), is("myTag"));
3737
assertThat(elementFinder.canFetchThroughCssAlone(), is(true));
@@ -44,7 +44,7 @@ public void toElementFinder__should_return_true_for_XPath_if_tag_is_universalSel
4444
// given
4545
SQCssTagNameSelector tagNameSelector = new SQCssTagNameSelector("*");
4646
// when
47-
ElementFinder elementFinder = tagNameSelector.toElementFinder(createDummyWebDriver());
47+
ElementFinder elementFinder = tagNameSelector.toElementFinder(createWebDriverDummy());
4848
// then
4949
assertThat(elementFinder.getXPathExpression(), is(".//*[true()]"));
5050
}
@@ -54,7 +54,7 @@ public void toElementFinder__should_return_ONLY_true_as_raw_XPathexpression() {
5454
// given
5555
SQCssTagNameSelector tagNameSelector = new SQCssTagNameSelector("*");
5656
// when
57-
ElementFinder elementFinder = tagNameSelector.toElementFinder(createDummyWebDriver());
57+
ElementFinder elementFinder = tagNameSelector.toElementFinder(createWebDriverDummy());
5858
// then
5959
assertThat(elementFinder.getXPathAndFilterFinder().getRawXPathExpression(), is("true()"));
6060
}

src/test/java/io/github/seleniumquery/functions/jquery/events/ClickFunctionTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
import static org.hamcrest.core.Is.is;
2929
import static org.junit.Assert.assertThat;
3030
import static org.mockito.Mockito.*;
31-
import static testinfrastructure.testdouble.SeleniumQueryObjectMother.createStubSeleniumQueryObjectWithElements;
31+
import static testinfrastructure.testdouble.io.github.seleniumquery.SeleniumQueryObjectMother.createStubSeleniumQueryObjectWithElements;
3232
import static testinfrastructure.testdouble.org.openqa.selenium.WebElementClickSpy.createWebElementClickSpy;
3333
import static testinfrastructure.testdouble.org.openqa.selenium.WebElementMother.createClickableWebElement;
3434
import static testinfrastructure.testdouble.org.openqa.selenium.WebElementMother.createUnclickableHiddenWebElement;

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@
2626
import static org.hamcrest.collection.IsEmptyCollection.empty;
2727
import static org.hamcrest.collection.IsIterableContainingInOrder.contains;
2828
import static org.junit.Assert.assertThat;
29-
import static testinfrastructure.testdouble.SeleniumQueryObjectMother.createStubSeleniumQueryObjectWithAtLeastOneElement;
30-
import static testinfrastructure.testdouble.SeleniumQueryObjectMother.createStubSeleniumQueryObjectWithElements;
31-
import static testinfrastructure.testdouble.Stubs.createStubWebElementWithTag;
29+
import static testinfrastructure.testdouble.io.github.seleniumquery.SeleniumQueryObjectMother.createStubSeleniumQueryObjectWithAtLeastOneElement;
30+
import static testinfrastructure.testdouble.io.github.seleniumquery.SeleniumQueryObjectMother.createStubSeleniumQueryObjectWithElements;
31+
import static testinfrastructure.testdouble.org.openqa.selenium.WebElementMother.createWebElementWithTag;
3232

3333
public class FilterPredicateFunctionTest {
3434

@@ -60,9 +60,9 @@ public SeleniumQueryObject apply(SeleniumQueryObject targetSQO) {
6060
@Test
6161
public void resultSQO_should_onlyKeepElementsThatPassThePredicateFunction() {
6262
// given
63-
WebElement spanOne = createStubWebElementWithTag("span");
64-
WebElement notSpan = createStubWebElementWithTag("div");
65-
WebElement spanTwo = createStubWebElementWithTag("span");
63+
WebElement spanOne = createWebElementWithTag("span");
64+
WebElement notSpan = createWebElementWithTag("div");
65+
WebElement spanTwo = createWebElementWithTag("span");
6666

6767
SeleniumQueryObject targetSQO = createStubSeleniumQueryObjectWithElements(spanOne, notSpan, spanTwo);
6868
// when

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
import static org.hamcrest.collection.IsEmptyCollection.empty;
2525
import static org.junit.Assert.*;
26-
import static testinfrastructure.testdouble.SeleniumQueryObjectMother.createStubSeleniumQueryObjectWithAtLeastOneElement;
26+
import static testinfrastructure.testdouble.io.github.seleniumquery.SeleniumQueryObjectMother.createStubSeleniumQueryObjectWithAtLeastOneElement;
2727

2828
public class FilterSelectorFunctionTest {
2929

src/test/java/testinfrastructure/testdouble/Dummies.java

Lines changed: 0 additions & 69 deletions
This file was deleted.

src/test/java/testinfrastructure/testdouble/Stubs.java

Lines changed: 0 additions & 16 deletions
This file was deleted.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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.com.google.common.base;
18+
19+
import com.google.common.base.Predicate;
20+
import org.openqa.selenium.WebElement;
21+
import testinfrastructure.testdouble.PseudoTestDoubleException;
22+
23+
public class PredicateMother {
24+
25+
public static Predicate<WebElement> createDummyWebElementPredicate() {
26+
return new Predicate<WebElement>() {
27+
@Override
28+
public boolean apply(WebElement input) {
29+
throw new PseudoTestDoubleException();
30+
}
31+
};
32+
}
33+
34+
}
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
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;
18+
19+
import com.google.common.base.Predicate;
20+
import io.github.seleniumquery.SeleniumQueryObject;
21+
import io.github.seleniumquery.functions.SeleniumQueryFunctions;
22+
import io.github.seleniumquery.functions.as.SeleniumQueryPlugin;
23+
import io.github.seleniumquery.functions.as.StandardPlugins;
24+
import org.openqa.selenium.By;
25+
import org.openqa.selenium.WebDriver;
26+
import org.openqa.selenium.WebElement;
27+
import testinfrastructure.testdouble.PseudoTestDoubleException;
28+
29+
import java.util.Collections;
30+
import java.util.Iterator;
31+
import java.util.List;
32+
33+
/**
34+
* Creates a "smart" dummy {@link SeleniumQueryObject}. It's goal is to be a mere placeholder in a test
35+
* fixture. It is "smart" because any method call to it will throw an exception (which indicates the dummy
36+
* is actually not a simple placeholder - since it is being used by the SUT when it shouldn't).
37+
*/
38+
public class SeleniumQueryObjectDummy extends SeleniumQueryObject {
39+
40+
public static SeleniumQueryObject createSeleniumQueryObjectDummy() {
41+
return new SeleniumQueryObjectDummy();
42+
}
43+
44+
private SeleniumQueryObjectDummy() {
45+
super(null, null, null, Collections.<WebElement>emptyList(), null);
46+
}
47+
48+
@Override public StandardPlugins as() { throw new PseudoTestDoubleException(); }
49+
@Override public <PLUGIN> PLUGIN as(SeleniumQueryPlugin<PLUGIN> pluginFunction) { throw new PseudoTestDoubleException(); }
50+
@Override public Iterator<WebElement> iterator() { throw new PseudoTestDoubleException(); }
51+
@Override public WebDriver getWebDriver() { throw new PseudoTestDoubleException(); }
52+
@Override public By getBy() { throw new PseudoTestDoubleException(); }
53+
@Override public SeleniumQueryFunctions getSeleniumQueryFunctions() { throw new PseudoTestDoubleException(); }
54+
@Override public int size() { throw new PseudoTestDoubleException(); }
55+
@Override public SeleniumQueryObject not(String selector) { throw new PseudoTestDoubleException(); }
56+
@Override public SeleniumQueryObject first() { throw new PseudoTestDoubleException(); }
57+
@Override public SeleniumQueryObject last() { throw new PseudoTestDoubleException(); }
58+
@Override public SeleniumQueryObject eq(int index) { throw new PseudoTestDoubleException(); }
59+
@Override public String text() { throw new PseudoTestDoubleException(); }
60+
@Override public SeleniumQueryObject click() { throw new PseudoTestDoubleException(); }
61+
@Override public SeleniumQueryObject val(String value) { throw new PseudoTestDoubleException(); }
62+
@Override public SeleniumQueryObject val(Number value) { throw new PseudoTestDoubleException(); }
63+
@Override public String val() { throw new PseudoTestDoubleException(); }
64+
@Override public SeleniumQueryObject end() { throw new PseudoTestDoubleException(); }
65+
@Override public SeleniumQueryObject find(String selector) { throw new PseudoTestDoubleException(); }
66+
@Override public String attr(String attributeName) { throw new PseudoTestDoubleException(); }
67+
@Override public SeleniumQueryObject attr(String attributeName, Object value) { throw new PseudoTestDoubleException(); }
68+
@Override public <T> T prop(String propertyName) { throw new PseudoTestDoubleException(); }
69+
@Override public SeleniumQueryObject prop(String propertyName, Object value) { throw new PseudoTestDoubleException(); }
70+
@Override public WebElement get(int index) { throw new PseudoTestDoubleException(); }
71+
@Override public List<WebElement> get() { throw new PseudoTestDoubleException(); }
72+
@Override public SeleniumQueryObject removeAttr(String attributeNames) { throw new PseudoTestDoubleException(); }
73+
@Override public String html() { throw new PseudoTestDoubleException(); }
74+
@Override public boolean is(String selector) { throw new PseudoTestDoubleException(); }
75+
@Override public boolean hasClass(String className) { throw new PseudoTestDoubleException(); }
76+
@Override public WebElement[] toArray() { throw new PseudoTestDoubleException(); }
77+
@Override public SeleniumQueryObject closest(String selector) { throw new PseudoTestDoubleException(); }
78+
@Override public SeleniumQueryObject focus() { throw new PseudoTestDoubleException(); }
79+
@Override public SeleniumQueryObject children() { throw new PseudoTestDoubleException(); }
80+
@Override public SeleniumQueryObject children(String selector) { throw new PseudoTestDoubleException(); }
81+
@Override public SeleniumQueryObject parent() { throw new PseudoTestDoubleException(); }
82+
@Override public SeleniumQueryObject parent(String selector) { throw new PseudoTestDoubleException(); }
83+
@Override public SeleniumQueryObject submit() { throw new PseudoTestDoubleException(); }
84+
@SuppressWarnings("deprecation") @Override public SeleniumQueryObject selectOptionByVisibleText(String text) { throw new PseudoTestDoubleException(); }
85+
@SuppressWarnings("deprecation") @Override public SeleniumQueryObject selectOptionByValue(String value) { throw new PseudoTestDoubleException(); }
86+
@Override public String toString() { throw new PseudoTestDoubleException(); }
87+
@Override public SeleniumQueryObject filter(Predicate<WebElement> filterFunction) { throw new PseudoTestDoubleException(); }
88+
89+
}

0 commit comments

Comments
 (0)
0