-
Notifications
You must be signed in to change notification settings - Fork 562
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
replaced useless unit-tests by analogous integration test
- Loading branch information
Showing
3 changed files
with
87 additions
and
143 deletions.
There are no files selected for viewing
120 changes: 0 additions & 120 deletions
120
src/test/java/com/codeborne/selenide/collections/ExactTextsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,135 +1,15 @@ | ||
package com.codeborne.selenide.collections; | ||
|
||
import com.codeborne.selenide.ex.ElementNotFound; | ||
import com.codeborne.selenide.ex.TextsMismatch; | ||
import com.codeborne.selenide.ex.TextsSizeMismatch; | ||
import org.junit.jupiter.api.Test; | ||
import org.openqa.selenium.WebElement; | ||
|
||
import java.util.List; | ||
|
||
import static com.codeborne.selenide.Mocks.mockCollection; | ||
import static com.codeborne.selenide.Mocks.mockElement; | ||
import static java.util.Arrays.asList; | ||
import static java.util.Collections.emptyList; | ||
import static java.util.Collections.singletonList; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
final class ExactTextsTest { | ||
@Test | ||
void varArgsConstructor() { | ||
ExactTexts exactTexts = new ExactTexts("One", "Two", "Three"); | ||
assertThat(exactTexts.expectedTexts) | ||
.as("Expected texts list") | ||
.isEqualTo(asList("One", "Two", "Three")); | ||
} | ||
|
||
@Test | ||
void applyOnWrongSizeList() { | ||
ExactTexts exactTexts = new ExactTexts("One", "Two", "Three"); | ||
|
||
assertThat(exactTexts.test(singletonList(mock()))) | ||
.isFalse(); | ||
} | ||
|
||
@Test | ||
void applyOnCorrectSizeAndCorrectElementsText() { | ||
ExactTexts exactTexts = new ExactTexts("One", "Two"); | ||
WebElement webElement1 = mockElement("One"); | ||
WebElement webElement2 = mockElement("Two"); | ||
|
||
assertThat(exactTexts.test(asList(webElement1, webElement2))) | ||
.isTrue(); | ||
} | ||
|
||
@Test | ||
void applyOnCorrectListSizeButWrongElementsText() { | ||
ExactTexts exactTexts = new ExactTexts("One", "Two"); | ||
WebElement webElement1 = mockElement("One"); | ||
WebElement webElement2 = mockElement("One"); | ||
|
||
assertThat(exactTexts.test(asList(webElement1, webElement2))) | ||
.isFalse(); | ||
} | ||
|
||
@Test | ||
void failWithNullElementsList() { | ||
failOnEmptyOrNullElementsList(null); | ||
} | ||
|
||
private void failOnEmptyOrNullElementsList(List<WebElement> elements) { | ||
ExactTexts exactTexts = new ExactTexts("One"); | ||
RuntimeException cause = new IllegalArgumentException("bad thing happened"); | ||
|
||
assertThatThrownBy(() -> exactTexts.fail(mockCollection("Collection description"), elements, cause, 10000)) | ||
.isInstanceOf(ElementNotFound.class) | ||
.hasMessage(String.format("Element not found {Collection description}%nExpected: Exact texts [One]%n" + | ||
"Timeout: 10 s.%n" + | ||
"Caused by: java.lang.IllegalArgumentException: bad thing happened")); | ||
} | ||
|
||
@Test | ||
void failWithEmptyElementsList() { | ||
failOnEmptyOrNullElementsList(emptyList()); | ||
} | ||
|
||
@Test | ||
void failOnTextMismatch() { | ||
ExactTexts exactTexts = new ExactTexts("One"); | ||
Exception cause = new Exception("Exception method"); | ||
|
||
WebElement mockedWebElement = mock(); | ||
when(mockedWebElement.getText()).thenReturn("Hello"); | ||
|
||
assertThatThrownBy(() -> | ||
exactTexts.fail(mockCollection("Collection description"), singletonList(mockedWebElement), cause, 10000)) | ||
.isInstanceOf(TextsMismatch.class) | ||
.hasMessage(String.format("Texts mismatch%n" + | ||
"Actual: [Hello]%n" + | ||
"Expected: [One]%n" + | ||
"Collection: Collection description%n" + | ||
"Timeout: 10 s.%n" + | ||
"Caused by: java.lang.Exception: Exception method")); | ||
} | ||
|
||
@Test | ||
void failOnTextSizeMismatch() { | ||
ExactTexts exactTexts = new ExactTexts("One", "Two"); | ||
Exception cause = new Exception("Exception method"); | ||
WebElement webElement = mockElement("One"); | ||
|
||
assertThatThrownBy(() -> exactTexts.fail(mockCollection("Collection description"), | ||
singletonList(webElement), cause, 10000) | ||
) | ||
.isInstanceOf(TextsSizeMismatch.class) | ||
.hasMessageContaining("Actual: [One], List size: 1") | ||
.hasMessageContaining("Expected: [One, Two], List size: 2") | ||
.hasMessageContaining("Collection: Collection description") | ||
.hasMessageContaining("Timeout: 10 s.") | ||
.hasMessageEndingWith("Caused by: java.lang.Exception: Exception method"); | ||
} | ||
|
||
@Test | ||
void testToString() { | ||
ExactTexts exactTexts = new ExactTexts("One", "Two", "Three"); | ||
assertThat(exactTexts) | ||
.hasToString("Exact texts [One, Two, Three]"); | ||
} | ||
|
||
@Test | ||
void emptyArrayIsNotAllowed() { | ||
assertThatThrownBy(ExactTexts::new) | ||
.isInstanceOf(IllegalArgumentException.class) | ||
.hasMessage("No expected texts given"); | ||
} | ||
|
||
@Test | ||
void emptyListIsNotAllowed() { | ||
assertThatThrownBy(() -> new ExactTexts(emptyList())) | ||
.isInstanceOf(IllegalArgumentException.class) | ||
.hasMessage("No expected texts given"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package integration.collections; | ||
|
||
import com.codeborne.selenide.ElementsCollection; | ||
import com.codeborne.selenide.ex.ElementNotFound; | ||
import com.codeborne.selenide.ex.TextsMismatch; | ||
import com.codeborne.selenide.ex.TextsSizeMismatch; | ||
import integration.ITest; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.openqa.selenium.NoSuchElementException; | ||
|
||
import static com.codeborne.selenide.CollectionCondition.exactTexts; | ||
import static java.util.Arrays.asList; | ||
import static java.util.Collections.emptyList; | ||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | ||
|
||
public class ExactTextsTest extends ITest { | ||
@BeforeEach | ||
void openPage() { | ||
openFile("page_with_list_of_elements.html"); | ||
} | ||
|
||
@Test | ||
void checksTexts() { | ||
$$(".element").shouldHave(exactTexts("One", "Two", "Three")); | ||
$$(".element").shouldHave(exactTexts(asList("One", "Two", "Three"))); | ||
} | ||
|
||
@Test | ||
void doesNotAcceptSubstrings() { | ||
assertThatThrownBy(() -> $$(".element").shouldHave(exactTexts("On", "Tw", "Thre"))) | ||
.isInstanceOf(TextsMismatch.class) | ||
.hasMessageStartingWith("Texts mismatch") | ||
.hasMessageContaining("Actual: [One, Two, Three]") | ||
.hasMessageContaining("Expected: [On, Tw, Thre]") | ||
.hasMessageContaining("Collection: .element"); | ||
} | ||
|
||
@Test | ||
void checksElementsCount() { | ||
assertThatThrownBy(() -> $$(".element").shouldHave(exactTexts("One", "Two", "Three", "Four"))) | ||
.isInstanceOf(TextsSizeMismatch.class) | ||
.hasMessageStartingWith("Texts size mismatch") | ||
.hasMessageContaining("Actual: [One, Two, Three], List size: 3") | ||
.hasMessageContaining("Expected: [One, Two, Three, Four], List size: 4") | ||
.hasMessageContaining("Collection: .element"); | ||
} | ||
|
||
@Test | ||
void throwsElementNotFound() { | ||
assertThatThrownBy(() -> $$(".non-existing-elements").shouldHave(exactTexts("content1", "content2"))) | ||
.isInstanceOf(ElementNotFound.class) | ||
.hasMessageStartingWith("Element not found {.non-existing-elements}"); | ||
} | ||
|
||
@Test | ||
void throwsElementNotFound_causedBy_NoSuchElementException() { | ||
ElementsCollection collection = $$("not-existing-locator").first().$$("h1"); | ||
|
||
assertThatThrownBy(() -> collection.shouldHave(exactTexts("One", "Two"))) | ||
.isInstanceOf(ElementNotFound.class) | ||
.hasCauseExactlyInstanceOf(NoSuchElementException.class); | ||
} | ||
|
||
@Test | ||
void shouldThrow_ElementNotFound_causedBy_IndexOutOfBoundsException() { | ||
ElementsCollection collection = $$("not-existing-locator").get(1).$$("h1"); | ||
|
||
assertThatThrownBy(() -> collection.shouldHave(exactTexts("One", "Two"))) | ||
.isInstanceOf(ElementNotFound.class) | ||
.hasCauseExactlyInstanceOf(IndexOutOfBoundsException.class); | ||
} | ||
|
||
@Test | ||
void emptyArrayIsNotAllowed() { | ||
assertThatThrownBy(() -> $$(".element").shouldHave(exactTexts())) | ||
.isInstanceOf(IllegalArgumentException.class) | ||
.hasMessage("No expected texts given"); | ||
} | ||
|
||
@Test | ||
void emptyListIsNotAllowed() { | ||
assertThatThrownBy(() -> $$(".element").shouldHave(exactTexts(emptyList()))) | ||
.isInstanceOf(IllegalArgumentException.class) | ||
.hasMessage("No expected texts given"); | ||
} | ||
} |