8000 #111 Removed mockito altogether - closes · seleniumQuery/seleniumQuery@f3e5355 · GitHub
[go: up one dir, main page]

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit f3e5355

Browse files
committed
#111 Removed mockito altogether - closes
1 parent 10595f0 commit f3e5355

File tree

8 files changed

+210
-53
lines changed

8 files changed

+210
-53
lines changed

pom.xml

Lines changed: 1 addition & 13 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.
@@ -104,18 +104,6 @@
104104
<version>2.0.0.0</version>
105105
<scope>test</scope>
106106
</dependency>
107-
<dependency>
108-
<groupId>org.mockito</groupId>
109-
<artifactId>mockito-core</artifactId>
110-
<version>1.10.19</version>
111-
<scope>test</scope>
112-
<exclusions>
113-
<exclusion>
114-
<artifactId>hamcrest-core</artifactId>
115-
<groupId>org.hamcrest</groupId>
116-
</exclusion>
117-
</exclusions>
118-
</dependency>
119107
</dependencies>
120108

121109
<build>

src/test/java/integration/io/github/seleniumquery/by/DriverVersionUtilsTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626

2727
import static org.hamcrest.Matchers.is;
2828
import static org.junit.Assert.assertThat;
29-
import static org.mockito.Mockito.mock;
3029
import static testinfrastructure.testdouble.org.openqa.selenium.WebDriverDummy.createWebDriverDummy;
3130

3231
public class DriverVersionUtilsTest {

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

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,33 +17,32 @@
1717
package io.github.seleniumquery;
1818

1919
import com.google.common.base.Predicate;
20-
import io.github.seleniumquery.functions.SeleniumQueryFunctions;
2120
import org.junit.Test;
2221
import org.openqa.selenium.WebElement;
22+
import testinfrastructure.testdouble.io.github.seleniumquery.functions.SeleniumQueryFunctionsMock;
2323

2424
import static org.hamcrest.CoreMatchers.is;
2525
import static org.hamcrest.MatcherAssert.assertThat;
26-
import static org.mockito.BDDMockito.given;
27-
import static org.mockito.Mockito.mock;
2826
import static testinfrastructure.testdouble.com.google.common.base.PredicateMother.createDummyWebElementPredicate;
29-
import static testinfrastructure.testdouble.io.github.seleniumquery.SeleniumQueryObjectMother.createStubSeleniumQueryObjectWithSeleniumQueryFunctions;
3027
import static testinfrastructure.testdouble.io.github.seleniumquery.SeleniumQueryObjectDummy.createSeleniumQueryObjectDummy;
28+
import static testinfrastructure.testdouble.io.github.seleniumquery.SeleniumQueryObjectMother.createStubSeleniumQueryObjectWithSeleniumQueryFunctions;
29+
import static testinfrastructure.testdouble.io.github.seleniumquery.functions.MethodMockConfiguration.configureReturnValue;
3130

3231
public class SeleniumQueryObjectTest {
3332

34-
public static SeleniumQueryFunctions createMockSeleniumQueryFunctions() {
35-
return mock(SeleniumQueryFunctions.class);
33+
public static SeleniumQueryFunctionsMock createMockSeleniumQueryFunctions() {
34+
return new SeleniumQueryFunctionsMock();
3635
}
3736

3837
@Test
3938
public void propRead() {
4039
// given
41-
SeleniumQueryFunctions seleniumQueryFunctions = createMockSeleniumQueryFunctions();
40+
SeleniumQueryFunctionsMock seleniumQueryFunctions = new SeleniumQueryFunctionsMock();
4241
SeleniumQueryObject seleniumQueryObject = createStubSeleniumQueryObjectWithSeleniumQueryFunctions(seleniumQueryFunctions);
4342

4443
String propertyName = "propertyName";
4544
String configuredPropertyValue = "propertyValue";
46-
given(seleniumQueryFunctions.propertyRead(seleniumQueryObject, propertyName)).willReturn(configuredPropertyValue);
45+
seleniumQueryFunctions.propertyReadMethod = configureReturnValue(configuredPropertyValue).forArgs(seleniumQueryObject, propertyName);
4746
// when
4847
Object returnedPropertyValue = seleniumQueryObject.prop(propertyName);
4948
// then
@@ -53,13 +52,13 @@ public void propRead() {
5352
@Test
5453
public void propWrite() {
5554
// given
56-
SeleniumQueryFunctions seleniumQueryFunctions = createMockSeleniumQueryFunctions();
55+
SeleniumQueryFunctionsMock seleniumQueryFunctions = new SeleniumQueryFunctionsMock();
5756
SeleniumQueryObject seleniumQueryObject = createStubSeleniumQueryObjectWithSeleniumQueryFunctions(seleniumQueryFunctions);
5857

5958
String propertyName = "propertyName";
6059
String propertyValue = "propertyValue";
6160
SeleniumQueryObject configuredReturningObject = createSeleniumQueryObjectDummy();
62-
given(seleniumQueryFunctions.propertyWrite(seleniumQueryObject, propertyName, propertyValue)).willReturn(configuredReturningObject);
61+
seleniumQueryFunctions.propertyWriteMethod = configureReturnValue(configuredReturningObject).forArgs(seleniumQueryObject, propertyName, propertyValue);
6362
// when
6463
SeleniumQueryObject returnedObject = seleniumQueryObject.prop(propertyName, propertyValue);
6564
// then
@@ -69,11 +68,11 @@ public void propWrite() {
6968
@Test
7069
public void valRead() {
7170
// given
72-
SeleniumQueryFunctions seleniumQueryFunctions = createMockSeleniumQueryFunctions();
71+
SeleniumQueryFunctionsMock seleniumQueryFunctions = new SeleniumQueryFunctionsMock();
7372
SeleniumQueryObject seleniumQueryObject = createStubSeleniumQueryObjectWithSeleniumQueryFunctions(seleniumQueryFunctions);
7473

7574
String configuredValue = "configuredValue";
76-
given(seleniumQueryFunctions.valueRead(seleniumQueryObject)).willReturn(configuredValue);
75+
seleniumQueryFunctions.valueReadMethod = configureReturnValue(configuredValue).forArgs(seleniumQueryObject);
7776
// when
7877
String returnedValue = seleniumQueryObject.val();
7978
// then
@@ -83,12 +82,12 @@ public void valRead() {
8382
@Test
8483
public void valWriteString() {
8584
// given
86-
SeleniumQueryFunctions seleniumQueryFunctions = createMockSeleniumQueryFunctions();
85+
SeleniumQueryFunctionsMock seleniumQueryFunctions = createMockSeleniumQueryFunctions();
8786
SeleniumQueryObject seleniumQueryObject = createStubSeleniumQueryObjectWithSeleniumQueryFunctions(seleniumQueryFunctions);
8887

8988
String propertyValue = "propertyValue";
9089
SeleniumQueryObject configuredReturningObject = createSeleniumQueryObjectDummy();
91-
given(seleniumQueryFunctions.valueWrite(seleniumQueryObject, propertyValue)).willReturn(configuredReturningObject);
90+
seleniumQueryFunctions.valueWriteStringMethod = configureReturnValue(configuredReturningObject).forArgs(seleniumQueryObject, propertyValue);
9291
// when
9392
SeleniumQueryObject returnedObject = seleniumQueryObject.val(propertyValue);
9493
// then
@@ -98,12 +97,12 @@ public void valWriteString() {
9897
@Test
9998
public void valWriteNumber() {
10099
// given
101-
SeleniumQueryFunctions seleniumQueryFunctions = createMockSeleniumQueryFunctions();
100+
SeleniumQueryFunctionsMock seleniumQueryFunctions = createMockSeleniumQueryFunctions();
102101
SeleniumQueryObject seleniumQueryObject = createStubSeleniumQueryObjectWithSeleniumQueryFunctions(seleniumQueryFunctions);
103102

104103
Number propertyValue = 1.0;
105104
SeleniumQueryObject configuredReturningObject = createSeleniumQueryObjectDummy();
106-
given(seleniumQueryFunctions.valueWrite(seleniumQueryObject, propertyValue)).willReturn(configuredReturningObject);
105+
seleniumQueryFunctions.valueWriteNumberMethod = configureReturnValue(configuredReturningObject).forArgs(seleniumQueryObject, propertyValue);
107106
// when
108107
SeleniumQueryObject returnedObject = seleniumQueryObject.val(propertyValue);
109108
// then
@@ -113,12 +112,12 @@ public void valWriteNumber() {
113112
@Test
114113
public void filterPredicateFunction() {
115114
// given
116-
SeleniumQueryFunctions seleniumQueryFunctions = createMockSeleniumQueryFunctions();
115+
SeleniumQueryFunctionsMock seleniumQueryFunctions = createMockSeleniumQueryFunctions();
117116
SeleniumQueryObject seleniumQueryObject = createStubSeleniumQueryObjectWithSeleniumQueryFunctions(seleniumQueryFunctions);
118117
SeleniumQueryObject configuredReturningObject = createSeleniumQueryObjectDummy();
119118

120119
Predicate<WebElement> filterFunction = createDummyWebElementPredicate();
121-
given(seleniumQueryFunctions.filterPredicate(seleniumQueryObject, filterFunction)).willReturn(configuredReturningObject);
120+
seleniumQueryFunctions.filterPredicateMethod = configureReturnValue(configuredReturningObject).forArgs(seleniumQueryObject, filterFunction);
122121
// when
123122
SeleniumQueryObject returnedObject = seleniumQueryObject.filter(filterFunction);
124123
// then
@@ -129,12 +128,12 @@ public void filterPredicateFunction() {
129128
@SuppressWarnings("ConstantConditions")
130129
public void isSelectorFunction() {
131130
// given
132-
SeleniumQueryFunctions seleniumQueryFunctions = createMockSeleniumQueryFunctions();
131+
SeleniumQueryFunctionsMock seleniumQueryFunctions = createMockSeleniumQueryFunctions();
133132
SeleniumQueryObject seleniumQueryObject = createStubSeleniumQueryObjectWithSeleniumQueryFunctions(seleniumQueryFunctions);
134133
boolean configuredReturningValue = true;
135134

136135
String configuredSelector = "selector";
137-
given(seleniumQueryFunctions.isSelector(seleniumQueryObject, configuredSelector)).willReturn(configuredReturningValue);
136+
seleniumQueryFunctions.isSelectorMethod = configureReturnValue(configuredReturningValue).forArgs(seleniumQueryObject, configuredSelector);
138137
// when
139138
boolean returnedValue = seleniumQueryObject.is(configuredSelector);
140139
// then
Lines changed: 14 additions & 17 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.
@@ -20,61 +20,58 @@
2020
import io.github.seleniumquery.by.firstgen.xpath.XPathComponentCompilerService;
2121
import org.junit.Test;
2222
import org.openqa.selenium.SearchContext;
23-
import org.openqa.selenium.WebDriver;
2423
import org.openqa.selenium.WebElement;
25-
import org.openqa.selenium.internal.FindsById;
26-
import org.openqa.selenium.internal.FindsByXPath;
2724

2825
import java.util.Arrays;
2926
import java.util.List;
3027

3128
import static org.hamcrest.CoreMatchers.is;
3229
import static org.hamcrest.Matchers.contains;
3330
import static org.junit.Assert.assertThat;
34-
import static org.mockito.Mockito.*;
31+
import static testinfrastructure.testdouble.org.openqa.selenium.SearchContextMother.createSearchContextThatReturnsWebElementForId;
32+
import static testinfrastructure.testdouble.org.openqa.selenium.SearchContextMother.createSearchContextThatReturnsWebElementsForXPath;
33+
import static testinfrastructure.testdouble.org.openqa.selenium.WebElementDummy.createWebElementDummy;
3534

3635
public class TagComponentTest {
3736

38-
final WebElement firstWebElementMock = mock(WebElement.class);
39-
final List<WebElement> fakeElements = Arrays.asList(firstWebElementMock, mock(WebElement.class), mock(WebElement.class));
37+
final WebElement firstDummyWebElement = createWebElementDummy();
38+
final List<WebElement> dummyWebElements = Arrays.asList(firstDummyWebElement, createWebElementDummy(), createWebElementDummy());
4039

4140
@Test
4241
public void f F438 indWebElements_should_call_findElementsByXPath() {
4342
// given
4443
TagComponentList tagComponentList = XPathComponentCompilerService.compileSelectorList("span");
4544

46-
SearchContext searchContext = mock(SearchContext.class, withSettings().extraInterfaces(FindsByXPath.class, WebDriver.class));
47-
when(((FindsByXPath)searchContext).findElementsByXPath("(.//*[self::span])")).thenReturn(fakeElements);
45+
SearchContext searchContext = createSearchContextThatReturnsWebElementsForXPath("(.//*[self::span])", dummyWebElements);
4846
// when
4947
List<WebElement> webElements = tagComponentList.findWebElements(searchContext);
5048
// then
51-
assertThat(webElements, is(fakeElements));
49+
assertThat(webElements, is(dummyWebElements));
5250
}
5351

5452
@Test
5553
public void findWebElements_should_call_findElementsByXPath__testing_directly() {
5654
// given
5755
TagComponent tagComponent = new TagComponent("span");
5856

59-
SearchContext searchContext = mock(SearchContext.class, withSettings().extraInterfaces(FindsByXPath.class, WebDriver.class));
60-
when(((FindsByXPath)searchContext).findElementsByXPath("(.//*[self::span])")).thenReturn(fakeElements);
57+
SearchContext searchContext = createSearchContextThatReturnsWebElementsForXPath("(.//*[self::span])", dummyWebElements);
6158
// when
6259
List<WebElement> webElements = tagComponent.findWebElements(searchContext);
6360
// then
64-
assertThat(webElements, is(fakeElements));
61+
assertThat(webElements, is(dummyWebElements));
6562
}
6663

6764
@Test
6865
public void findWebElements_if_selector_is_just_an_id_it_should_call_findElementById() {
6966
// given
7067
TagComponentList tagComponentList = XPathComponentCompilerService.compileSelectorList("#idz");
7168

72-
SearchContext searchContext = mock(SearchContext.class, withSettings().extraInterfaces(FindsById.class, WebDriver.class));
73-
when(((FindsById)searchContext).findElementById("idz")).thenReturn(firstWebElementMock);
69+
SearchContext searchContext = createSearchContextThatReturnsWebElementForId("idz", firstDummyWebElement);
7470
// when
7571
List<WebElement> webElements = tagComponentList.findWebElements(searchContext);
7672
// then
77-
assertThat(webElements, contains(firstWebElementMock));
73+
assertThat(webElements, contains(firstDummyWebElement));
7874
}
7975

80-
}
76+
}
77+
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.testdouble.io.github.seleniumquery.functions;
18+
19+
import static org.hamcrest.collection.IsArrayContainingInOrder.arrayContaining;
20+
import static org.hamcrest.junit.MatcherAssert.assertThat;
21+
22+
public class MethodMockConfiguration<T> {
23+
24+
public static <T> MethodMockConfiguration<T> configureReturnValue(T returnValue) {
25+
return new MethodMockConfiguration<>(returnValue);
26+
}
27+
28+
private Object[] expectedArguments;
29+
private T returnValue;
30+
31+
public MethodMockConfiguration(T returnValue) {
32+
this.returnValue = returnValue;
33+
}
34+
35+
public MethodMockConfiguration<T> forArgs(Object... expectedArguments) {
36+
this.expectedArguments = expectedArguments;
37+
return this;
38+
}
39+
40+
public T executeMethodMock(Object... actualArguments) {
41+
assertThat(actualArguments, arrayContaining(this.expectedArguments));
42+
return this.returnValue;
43+
}
44+
45+
}

0 commit comments

Comments
 (0)
0