10000 #111 Test doubles should not have constructor called outside package · seleniumQuery/seleniumQuery@59b0556 · GitHub
[go: up one dir, main page]

Skip to content

Commit 59b0556

Browse files
committed
#111 Test doubles should not have constructor called outside package
1 parent ca96181 commit 59b0556

File tree

6 files changed

+22
-35
lines changed

6 files changed

+22
-35
lines changed

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

Lines changed: 4 additions & 4 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.
@@ -26,7 +26,7 @@
2626
import static org.junit.Assert.assertThat;
2727
import static org.mockito.Mockito.mock;
2828
import static org.mockito.Mockito.when;
29-
import static testinfrastructure.testdouble.Mocks.mockWebDriver;
29+
import static testinfrastructure.testdouble.org.openqa.selenium.WebDriverDummy.createWebDriverDummy;
3030

3131
public class ElementFinderUtilsTest {
3232

@@ -36,7 +36,7 @@ public static ElementFinder universalSelectorFinder(WebDriver driver) {
3636
}
3737

3838
public static WebDriver mockWebDriverWithNativeSupportFor(String pseudoClass) {
39-
WebDriver mockDriver = mockWebDriver();
39+
WebDriver mockDriver = createWebDriverDummy();
4040
DriverVersionUtils driverVersionUtilsMock = overrideDriverVersionUtilsWithMock();
4141
when(driverVersionUtilsMock.hasNativeSupportForPseudo(mockDriver, pseudoClass)).thenReturn(true);
4242
return mockDriver;
@@ -48,7 +48,7 @@ private static DriverVersionUtils overrideDriverVersionUtilsWithMock() {
4848
}
4949
public static WebDriver mockWebDriverWithNativeSupportForNoPseudoClass() {
5050
overrideDriverVersionUtilsWithMock();
51-
return mockWebDriver();
51+
return createWebDriverDummy();
5252
}
5353

5454
public static WebDriver createMockDriverWithNativeSupporForSelectorAndEmulatingPhantomJS(String checkedPseudo) {

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import static org.junit.Assert.assertThat;
3030
import static org.mockito.Mockito.*;
3131
import static testinfrastructure.testdouble.SeleniumQueryObjectMother.createStubSeleniumQueryObjectWithElements;
32+
import static testinfrastructure.testdouble.org.openqa.selenium.WebElementClickSpy.createWebElementClickSpy;
3233
import static testinfrastructure.testdouble.org.openqa.selenium.WebElementMother.createClickableWebElement;
3334
import static testinfrastructure.testdouble.org.openqa.selenium.WebElementMother.createUnclickableHiddenWebElement;
3435

@@ -47,8 +48,8 @@ public void click__shouldReturnPassedSeleniumQueryObject() {
4748
@Test
4849
public void click__shouldCallClickOnEveryElementIfNoneThrowsException() {
4950
// given
50-
WebElementClickSpy webElementClickSpyOne = new WebElementClickSpy();
51-
WebElementClickSpy webElementClickSpyTwo = new WebElementClickSpy();
51+
WebElementClickSpy webElementClickSpyOne = createWebElementClickSpy();
52+
WebElementClickSpy webElementClickSpyTwo = createWebElementClickSpy();
5253
SeleniumQueryObject sqo = createStubSeleniumQueryObjectWithElements(webElementClickSpyOne, webElementClickSpyTwo);
5354
// when
5455
ClickFunction.click(sqo);
@@ -61,7 +62,7 @@ public void click__shouldCallClickOnEveryElementIfNoneThrowsException() {
6162
public void click__shouldCallClickOnEveryElementEvenIfSomeThrowExceptions() {
6263
// given
6364
WebElement unclickableHiddenWebElement = createUnclickableHiddenWebElement();
64-
WebElementClickSpy webElementClickSpy = new WebElementClickSpy();
65+
WebElementClickSpy webElementClickSpy = createWebElementClickSpy();
6566
SeleniumQueryObject sqo = createStubSeleniumQueryObjectWithElements(unclickableHiddenWebElement, webElementClickSpy);
6667
// when
6768
ClickFunction.click(sqo);

src/test/java/testinfrastructure/testdouble/Mocks.java

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

src/test/java/testinfrastructure/testdouble/org/openqa/selenium/WebDriverDummy.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@
2626

2727
public class WebDriverDummy implements WebDriver {
2828

29+
public static WebDriver createWebDriverDummy() {
30+
return new WebDriverDummy();
31+
}
32+
33+
WebDriverDummy() { /* package visibility to contain widespread inheritance */ }
34+
2935
@Override public void get(String s) { throw new PseudoTestDoubleException(); }
3036
@Override public String getCurrentUrl() { throw new PseudoTestDoubleException(); }
3137
@Override public String getTitle() { throw new PseudoTestDoubleException(); }

src/test/java/testinfrastructure/testdouble/org/openqa/selenium/WebElementClickSpy.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@
2121

2222
public class WebElementClickSpy extends WebElementDummy {
2323

24+
public static WebElementClickSpy createWebElementClickSpy() {
25+
return new WebElementClickSpy();
26+
}
27+
28+
WebElementClickSpy() { /* package visibility to contain widespread inheritance */ }
29+
2430
private int clickCount = 0;
2531

2632
@Override

src/test/java/testinfrastructure/testdouble/org/openqa/selenium/WebElementDummy.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323

2424
public class WebElementDummy implements WebElement {
2525

26+
WebElementDummy() { /* package visibility to contain widespread inheritance */ }
27+
2628
@Override public void click() { throw new PseudoTestDoubleException(); }
2729
@Override public void submit() { throw new PseudoTestDoubleException(); }
2830
@Override public void sendKeys(CharSequence... charSequences) { throw new PseudoTestDoubleException(); }

0 commit comments

Comments
 (0)
0