Skip to content

Commit 15421a2

Browse files
committed
tiny cleanup in ExpectedConditions.java
1 parent ab42a51 commit 15421a2

File tree

1 file changed

+48
-50
lines changed

1 file changed

+48
-50
lines changed

java/src/org/openqa/selenium/support/ui/ExpectedConditions.java

Lines changed: 48 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ private ExpectedConditions() {
5050
* @return true when the title matches, false otherwise
5151
*/
5252
public static ExpectedCondition<Boolean> titleIs(final String title) {
53-
return new ExpectedCondition<Boolean>() {
53+
return new ExpectedCondition<>() {
5454
private @Nullable String currentTitle = "";
5555

5656
@Override
@@ -73,7 +73,7 @@ public String toString() {
7373
* @return true when the title matches, false otherwise
7474
*/
7575
public static ExpectedCondition<Boolean> titleContains(final String title) {
76-
return new ExpectedCondition<Boolean>() {
76+
return new ExpectedCondition<>() {
7777
private @Nullable String currentTitle = "";
7878

7979
@Override
@@ -96,7 +96,7 @@ public String toString() {
9696
* @return <code>true</code> when the URL is what it should be
9797
*/
9898
public static ExpectedCondition<Boolean> urlToBe(final String url) {
99-
return new ExpectedCondition<Boolean>() {
99+
return new ExpectedCondition<>() {
100100
private @Nullable String currentUrl = "";
101101

102102
@Override
@@ -119,7 +119,7 @@ public String toString() {
119119
* @return <code>true</code> when the URL contains the text
120120
*/
121121
public static ExpectedCondition<Boolean> urlContains(final String fraction) {
122-
return new ExpectedCondition<Boolean>() {
122+
return new ExpectedCondition<>() {
123123
private @Nullable String currentUrl = "";
124124

125125
@Override
@@ -142,7 +142,7 @@ public String toString() {
142142
* @return <code>true</code> if the URL matches the specified regular expression
143143
*/
144144
public static ExpectedCondition<Boolean> urlMatches(final String regex) {
145-
return new ExpectedCondition<Boolean>() {
145+
return new ExpectedCondition<>() {
146146
private final Pattern pattern = Pattern.compile(regex);
147147
private @Nullable String currentUrl;
148148

@@ -168,7 +168,7 @@ public String toString() {
168168
* @return the WebElement once it is located
169169
*/
170170
public static ExpectedCondition<WebElement> presenceOfElementLocated(final By locator) {
171-
return new ExpectedCondition<WebElement>() {
171+
return new ExpectedCondition<>() {
172172
@Override
173173
public WebElement apply(WebDriver driver) {
174174
return driver.findElement(locator);
@@ -189,9 +189,8 @@ public String toString() {
189189
* @param locator used to find the element
190190
* @return the WebElement once it is located and visible
191191
*/
192-
public static ExpectedCondition<@Nullable WebElement> visibilityOfElementLocated(
193-
final By locator) {
194-
return new ExpectedCondition<@Nullable WebElement>() {
192+
public static ExpectedCondition<WebElement> visibilityOfElementLocated(final By locator) {
193+
return new ExpectedCondition<>() {
195194
@Override
196195
public @Nullable WebElement apply(WebDriver driver) {
197196
try {
@@ -340,7 +339,7 @@ public String toString() {
340339
public static ExpectedCondition<Boolean> textToBePresentInElement(
341340
final WebElement element, final String text) {
342341

343-
return new ExpectedCondition<Boolean>() {
342+
return new ExpectedCondition<>() {
344343
@Override
345344
public Boolean apply(WebDriver driver) {
346345
try {
@@ -369,7 +368,7 @@ public String toString() {
369368
public static ExpectedCondition<Boolean> textToBePresentInElementLocated(
370369
final By locator, final String text) {
371370

372-
return new ExpectedCondition<Boolean>() {
371+
return new ExpectedCondition<>() {
373372
@Override
374373
public Boolean apply(WebDriver driver) {
375374
try {
@@ -398,7 +397,7 @@ public String toString() {
398397
public static ExpectedCondition<Boolean> textToBePresentInElementValue(
399398
final WebElement element, final String text) {
400399

401-
return new ExpectedCondition<Boolean>() {
400+
return new ExpectedCondition<>() {
402401
@Override
403402
public Boolean apply(WebDriver driver) {
404403
try {
@@ -431,7 +430,7 @@ public String toString() {
431430
public static ExpectedCondition<Boolean> textToBePresentInElementValue(
432431
final By locator, final String text) {
433432

434-
return new ExpectedCondition<Boolean>() {
433+
return new ExpectedCondition<>() {
435434
@Override
436435
public Boolean apply(WebDriver driver) {
437436
try {
@@ -460,9 +459,9 @@ public String toString() {
460459
* @param frameLocator used to find the frame (id or name)
461460
* @return WebDriver instance after frame has been switched
462461
*/
463-
public static ExpectedCondition<@Nullable WebDriver> frameToBeAvailableAndSwitchToIt(
462+
public static ExpectedCondition<WebDriver> frameToBeAvailableAndSwitchToIt(
464463
final String frameLocator) {
465-
return new ExpectedCondition<@Nullable WebDriver>() {
464+
return new ExpectedCondition<>() {
466465
@Override
467466
public @Nullable WebDriver apply(WebDriver driver) {
468467
try {
@@ -514,9 +513,9 @@ public String toString() {
514513
* @param frameLocator used to find the frame (index)
515514
* @return WebDriver instance after frame has been switched
516515
*/
517-
public static ExpectedCondition<@Nullable WebDriver> frameToBeAvailableAndSwitchToIt(
516+
public static ExpectedCondition<WebDriver> frameToBeAvailableAndSwitchToIt(
518517
final int frameLocator) {
519-
return new ExpectedCondition<@Nullable WebDriver>() {
518+
return new ExpectedCondition<>() {
520519
@Override
521520
public @Nullable WebDriver apply(WebDriver driver) {
522521
try {
@@ -538,7 +537,7 @@ public String toString() {
538537
*
539538
* <p>If the frame is available it switches the given driver to the specified web element.
540539
*
541-
* @param frameLocator used to find the frame (webelement)
540+
* @param frameLocator used to find the frame (web element)
542541
* @return WebDriver instance after frame has been switched
543542
*/
544543
public static ExpectedCondition<@Nullable WebDriver> frameToBeAvailableAndSwitchToIt(
@@ -567,7 +566,7 @@ public String toString() {
567566
* @return true if the element is not displayed or the element doesn't exist or stale element
568567
*/
569568
public static ExpectedCondition<Boolean> invisibilityOfElementLocated(final By locator) {
570-
return new ExpectedCondition<Boolean>() {
569+
return new ExpectedCondition<>() {
571570
@Override
572571
public Boolean apply(WebDriver driver) {
573572
try {
@@ -596,7 +595,7 @@ public String toString() {
596595
*/
597596
public static ExpectedCondition<Boolean> invisibilityOfElementWithText(
598597
final By locator, final String text) {
599-
return new ExpectedCondition<Boolean>() {
598+
return new ExpectedCondition<>() {
600599
@Override
601600
public Boolean apply(WebDriver driver) {
602601
try {
@@ -625,8 +624,8 @@ public String toString() {
625624
* @param locator used to find the element
626625
* @return the WebElement once it is located and clickable (visible and enabled)
627626
*/
628-
public static ExpectedCondition<@Nullable WebElement> elementToBeClickable(final By locator) {
629-
return new ExpectedCondition<@Nullable WebElement>() {
627+
public static ExpectedCondition<WebElement> elementToBeClickable(final By locator) {
628+
return new ExpectedCondition<>() {
630629
@Override
631630
public @Nullable WebElement apply(WebDriver driver) {
632631
WebElement element = visibilityOfElementLocated(locator).apply(driver);
@@ -653,9 +652,8 @@ public String toString() {
653652
* @param element the WebElement
654653
* @return the (same) WebElement once it is clickable (visible and enabled)
655654
*/
656-
public static ExpectedCondition<@Nullable WebElement> elementToBeClickable(
657-
final WebElement element) {
658-
return new ExpectedCondition<@Nullable WebElement>() {
655+
public static ExpectedCondition<WebElement> elementToBeClickable(final WebElement element) {
656+
return new ExpectedCondition<>() {
659657

660658
@Override
661659
public @Nullable WebElement apply(WebDriver driver) {
@@ -684,7 +682,7 @@ public String toString() {
684682
* @return false if the element is still attached to the DOM, true otherwise.
685683
*/
686684
public static ExpectedCondition<Boolean> stalenessOf(final WebElement element) {
687-
return new ExpectedCondition<Boolean>() {
685+
return new ExpectedCondition<>() {
688686
@Override
689687
public Boolean apply(WebDriver ignored) {
690688
try {
@@ -752,7 +750,7 @@ public static ExpectedCondition<Boolean> elementToBeSelected(final WebElement el
752750
*/
753751
public static ExpectedCondition<Boolean> elementSelectionStateToBe(
754752
final WebElement element, final boolean selected) {
755-
return new ExpectedCondition<Boolean>() {
753+
return new ExpectedCondition<>() {
756754
@Override
757755
public Boolean apply(WebDriver driver) {
758756
return element.isSelected() == selected;
@@ -771,7 +769,7 @@ public static ExpectedCondition<Boolean> elementToBeSelected(final By locator) {
771769

772770
public static ExpectedCondition<Boolean> elementSelectionStateToBe(
773771
final By locator, final boolean selected) {
774-
return new ExpectedCondition<Boolean>() {
772+
return new ExpectedCondition<>() {
775773
@Override
776774
public Boolean apply(WebDriver driver) {
777775
try {
@@ -809,7 +807,7 @@ public String toString() {
809807
}
810808

811809
public static ExpectedCondition<Boolean> numberOfWindowsToBe(final int expectedNumberOfWindows) {
812-
return new ExpectedCondition<Boolean>() {
810+
return new ExpectedCondition<>() {
813811
@Override
814812
public Boolean apply(WebDriver driver) {
815813
try {
@@ -836,7 +834,7 @@ public String toString() {
836834
* @return true once the condition is satisfied
837835
*/
838836
public static ExpectedCondition<Boolean> not(final ExpectedCondition<?> condition) {
839-
return new ExpectedCondition<Boolean>() {
837+
return new ExpectedCondition<>() {
840838
@Override
841839
public Boolean apply(WebDriver driver) {
842840
Object result = condition.apply(driver);
@@ -860,7 +858,7 @@ public String toString() {
860858
*/
861859
public static ExpectedCondition<Boolean> attributeToBe(
862860
final By locator, final String attribute, final String value) {
863-
return new ExpectedCondition<Boolean>() {
861+
return new ExpectedCondition<>() {
864862
private @Nullable String currentValue = null;
865863

866864
@Override
@@ -890,7 +888,7 @@ public String toString() {
890888
* @return Boolean true when element has text value equal to @value
891889
*/
892890
public static ExpectedCondition<Boolean> textToBe(final By locator, final String value) {
893-
return new ExpectedCondition<Boolean>() {
891+
return new ExpectedCondition<>() {
894892
private @Nullable String currentValue = null;
895893

896894
@Override
@@ -920,7 +918,7 @@ public String toString() {
920918
* @return Boolean true when element has text value containing @value
921919
*/
922920
public static ExpectedCondition<Boolean> textMatches(final By locator, final Pattern pattern) {
923-
return new ExpectedCondition<Boolean>() {
921+
return new ExpectedCondition<>() {
924922
private @Nullable String currentValue = null;
925923

926924
@Override
@@ -1038,7 +1036,7 @@ public String toString() {
10381036
*/
10391037
public static ExpectedCondition<Boolean> domPropertyToBe(
10401038
final WebElement element, final String property, final String value) {
1041-
return new ExpectedCondition<Boolean>() {
1039+
return new ExpectedCondition<>() {
10421040
private @Nullable String currentValue = null;
10431041

10441042
@Override
@@ -1065,7 +1063,7 @@ public String toString() {
10651063
*/
10661064
public static ExpectedCondition<Boolean> domAttributeToBe(
10671065
final WebElement element, final String attribute, final String value) {
1068-
return new ExpectedCondition<Boolean>() {
1066+
return new ExpectedCondition<>() {
10691067
private @Nullable String currentValue = null;
10701068

10711069
@Override
@@ -1092,7 +1090,7 @@ public String toString() {
10921090
*/
10931091
public static ExpectedCondition<Boolean> attributeToBe(
10941092
final WebElement element, final String attribute, final String value) {
1095-
return new ExpectedCondition<Boolean>() {
1093+
return new ExpectedCondition<>() {
10961094
private @Nullable String currentValue = null;
10971095

10981096
@Override
@@ -1124,7 +1122,7 @@ public String toString() {
11241122
*/
11251123
public static ExpectedCondition<Boolean> attributeContains(
11261124
final WebElement element, final String attribute, final String value) {
1127-
return new ExpectedCondition<Boolean>() {
1125+
return new ExpectedCondition<>() {
11281126
@Override
11291127
public Boolean apply(WebDriver driver) {
11301128
return getAttributeOrCssValue(element, attribute)
@@ -1150,7 +1148,7 @@ public String toString() {
11501148
*/
11511149
public static ExpectedCondition<Boolean> attributeContains(
11521150
final By locator, final String attribute, final String value) {
1153-
return new ExpectedCondition<Boolean>() {
1151+
return new ExpectedCondition<>() {
11541152
@Override
11551153
public Boolean apply(WebDriver driver) {
11561154
return getAttributeOrCssValue(driver.findElement(locator), attribute)
@@ -1166,7 +1164,7 @@ public String toString() {
11661164
}
11671165

11681166
/**
1169-
* An expectation for checking WebElement any non empty value for given attribute
1167+
* An expectation for checking WebElement any non-empty value for given attribute
11701168
*
11711169
* @param element used to check its parameters
11721170
* @param attribute used to define css or html attribute
@@ -1259,7 +1257,7 @@ public String toString() {
12591257
*/
12601258
public static ExpectedCondition<WebElement> presenceOfNestedElementLocatedBy(
12611259
final By locator, final By childLocator) {
1262-
return new ExpectedCondition<WebElement>() {
1260+
return new ExpectedCondition<>() {
12631261

12641262
@Override
12651263
public WebElement apply(WebDriver webDriver) {
@@ -1283,7 +1281,7 @@ public String toString() {
12831281
public static ExpectedCondition<WebElement> presenceOfNestedElementLocatedBy(
12841282
final WebElement element, final By childLocator) {
12851283

1286-
return new ExpectedCondition<WebElement>() {
1284+
return new ExpectedCondition<>() {
12871285

12881286
@Override
12891287
public WebElement apply(WebDriver webDriver) {
@@ -1340,7 +1338,7 @@ public static ExpectedCondition<Boolean> invisibilityOfAllElements(final WebElem
13401338
*/
13411339
public static ExpectedCondition<Boolean> invisibilityOfAllElements(
13421340
final List<WebElement> elements) {
1343-
return new ExpectedCondition<Boolean>() {
1341+
return new ExpectedCondition<>() {
13441342

13451343
@Override
13461344
public Boolean apply(WebDriver webDriver) {
@@ -1361,7 +1359,7 @@ public String toString() {
13611359
* @return Boolean true when element is not visible anymore
13621360
*/
13631361
public static ExpectedCondition<Boolean> invisibilityOf(final WebElement element) {
1364-
return new ExpectedCondition<Boolean>() {
1362+
return new ExpectedCondition<>() {
13651363

13661364
@Override
13671365
public Boolean apply(WebDriver webDriver) {
@@ -1393,7 +1391,7 @@ private static boolean isInvisible(final WebElement element) {
13931391
* @return true once one of conditions is satisfied
13941392
*/
13951393
public static ExpectedCondition<Boolean> or(final ExpectedCondition<?>... conditions) {
1396-
return new ExpectedCondition<Boolean>() {
1394+
return new ExpectedCondition<>() {
13971395
@Override
13981396
public Boolean apply(WebDriver driver) {
13991397
RuntimeException lastException = null;
@@ -1437,7 +1435,7 @@ public String toString() {
14371435
* @return true once all conditions are satisfied
14381436
*/
14391437
public static ExpectedCondition<Boolean> and(final ExpectedCondition<?>... conditions) {
1440-
return new ExpectedCondition<Boolean>() {
1438+
return new ExpectedCondition<>() {
14411439
@Override
14421440
public Boolean apply(WebDriver driver) {
14431441
for (ExpectedCondition<?> condition : conditions) {
@@ -1468,13 +1466,13 @@ public String toString() {
14681466
/**
14691467
* An expectation to check if js executable.
14701468
*
1471-
* <p>Useful when you know that there should be a Javascript value or something at the stage.
1469+
* <p>Useful when you know that there should be a JavaScript value or something at the stage.
14721470
*
14731471
* @param javaScript used as executable script
1474-
* @return true once javaScript executed without errors
1472+
* @return true once JavaScript executed without errors
14751473
*/
14761474
public static ExpectedCondition<Boolean> javaScriptThrowsNoExceptions(final String javaScript) {
1477-
return new ExpectedCondition<Boolean>() {
1475+
return new ExpectedCondition<>() {
14781476
@Override
14791477
public Boolean apply(WebDriver driver) {
14801478
try {
@@ -1493,10 +1491,10 @@ public String toString() {
14931491
}
14941492

14951493
/**
1496-
* An expectation for String value from javascript
1494+
* An expectation for String value from JavaScript
14971495
*
14981496
* @param javaScript as executable js line
1499-
* @return object once javaScript executes without errors
1497+
* @return object once JavaScript executes without errors
15001498
*/
15011499
public static ExpectedCondition<@Nullable Object> jsReturnsValue(final String javaScript) {
15021500
return new ExpectedCondition<@Nullable Object>() {

0 commit comments

Comments
 (0)