Skip to content

Commit

Permalink
Merge 59f4989 into ab64b3b
Browse files Browse the repository at this point in the history
  • Loading branch information
sidelnikovmike committed May 28, 2018
2 parents ab64b3b + 59f4989 commit c2b8849
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 6 deletions.
48 changes: 42 additions & 6 deletions src/main/java/com/codeborne/selenide/CollectionCondition.java
Expand Up @@ -49,7 +49,7 @@ public static CollectionCondition sizeNotEqual(int expectedSize) {

/**
* Checks that given collection has given texts (each collection element CONTAINS corresponding text)
*
* <p>
* <p>NB! Ignores multiple whitespaces between words</p>
*/
public static CollectionCondition texts(String... expectedTexts) {
Expand All @@ -58,7 +58,7 @@ public static CollectionCondition texts(String... expectedTexts) {

/**
* Checks that given collection has given texts (each collection element CONTAINS corresponding text)
*
* <p>
* <p>NB! Ignores multiple whitespaces between words</p>
*/
public static CollectionCondition texts(List<String> expectedTexts) {
Expand All @@ -67,7 +67,7 @@ public static CollectionCondition texts(List<String> expectedTexts) {

/**
* Checks that given collection has given texts in any order (each collection element CONTAINS corresponding text)
*
* <p>
* <p>NB! Ignores multiple whitespaces between words</p>
*/
public static CollectionCondition textsInAnyOrder(String... expectedTexts) {
Expand All @@ -76,7 +76,7 @@ public static CollectionCondition textsInAnyOrder(String... expectedTexts) {

/**
* Checks that given collection has given texts in any order (each collection element CONTAINS corresponding text)
*
* <p>
* <p>NB! Ignores multiple whitespaces between words</p>
*/
public static CollectionCondition textsInAnyOrder(List<String> expectedTexts) {
Expand All @@ -85,7 +85,7 @@ public static CollectionCondition textsInAnyOrder(List<String> expectedTexts) {

/**
* Checks that given collection has given texts (each collection element EQUALS TO corresponding text)
*
* <p>
* <p>NB! Ignores multiple whitespaces between words</p>
*/
public static CollectionCondition exactTexts(String... expectedTexts) {
Expand All @@ -94,10 +94,46 @@ public static CollectionCondition exactTexts(String... expectedTexts) {

/**
* Checks that given collection has given texts (each collection element EQUALS TO corresponding text)
*
* <p>
* <p>NB! Ignores multiple whitespaces between words</p>
*/
public static CollectionCondition exactTexts(List<String> expectedTexts) {
return new ExactTexts(expectedTexts);
}

/**
* Should be used for explaining the reason of condition
*/
public CollectionCondition because(String message) {
return new ExplainedCollectionCondition(this, message);
}

private static class ExplainedCollectionCondition extends CollectionCondition {
private final CollectionCondition delegate;
private final String message;

private ExplainedCollectionCondition(CollectionCondition delegate, String message) {
this.delegate = delegate;
this.message = message;
}

@Override
public void fail(WebElementsCollection collection, List<WebElement> elements, Exception lastError, long timeoutMs) {
delegate.fail(collection, elements, lastError, timeoutMs);
}

@Override
public boolean apply(List<WebElement> element) {
return delegate.apply(element);
}

@Override
public String toString() {
return delegate.toString() + " (because " + message + ")";
}


}


}
@@ -0,0 +1,21 @@
package com.codeborne.selenide.collections;

import com.codeborne.selenide.CollectionCondition;
import org.junit.Assert;
import org.junit.Test;

public class CollectionConditionReasonTest {

@Test
public void testCollectionConditionWithBecause() {
CollectionCondition condition = CollectionCondition.sizeGreaterThanOrEqual(1).because("size is lower than expected");
Assert.assertEquals("size >= 1 (because size is lower than expected)", condition.toString());
}

@Test
public void testCollectionConditionWithoutBecause() {
CollectionCondition condition = CollectionCondition.sizeGreaterThanOrEqual(1);
Assert.assertEquals("size >= 1", condition.toString());
}

}

0 comments on commit c2b8849

Please sign in to comment.