This repository has been archived by the owner on Mar 10, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added GenericTextFieldMatcher and MatcherTest
- Loading branch information
Showing
3 changed files
with
113 additions
and
1 deletion.
There are no files selected for viewing
16 changes: 15 additions & 1 deletion
16
...ertj/src/main/java/info/novatec/testit/webtester/support/assertj/WebTesterAssertions.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
48 changes: 48 additions & 0 deletions
48
...src/main/java/info/novatec/testit/webtester/support/hamcrest/GenericTextFieldMatcher.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 |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package info.novatec.testit.webtester.support.hamcrest; | ||
|
||
import info.novatec.testit.webtester.pageobjects.GenericTextField; | ||
import org.hamcrest.BaseMatcher; | ||
import org.hamcrest.Description; | ||
import org.hamcrest.Matcher; | ||
|
||
/** | ||
* Contains {@link Matcher matcher} for {@link GenericTextField generic text fields}. | ||
* | ||
* @since 1.2 | ||
*/ | ||
public class GenericTextFieldMatcher extends PageObjectMatcher { | ||
|
||
|
||
/** | ||
* returns whether the {@link GenericTextField generic text field} contains a certain text. | ||
* | ||
* @param text contains expected text | ||
* @return true if text on generic text field contains expected text | ||
* @since 1.2. | ||
*/ | ||
public static Matcher<GenericTextField> hasText(final String text) { | ||
return new BaseMatcher<GenericTextField>() { | ||
|
||
@Override | ||
public void describeTo(Description description) { | ||
description.appendText("text to be '" + text + "'"); | ||
} | ||
|
||
@Override | ||
public void describeMismatch(Object genericTextField, Description mismatchDescription){ | ||
mismatchDescription.appendText("was '" + (( GenericTextField ) genericTextField).getText() + "'"); | ||
} | ||
|
||
@Override | ||
public boolean matches(Object genericTextField){ | ||
return ((GenericTextField) genericTextField).getText().equals(text); | ||
} | ||
|
||
}; | ||
|
||
} | ||
|
||
protected GenericTextFieldMatcher() { | ||
/* utility constructor */ | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
...test/java/info/novatec/testit/webtester/support/hamcrest/GenericTextFieldMatcherTest.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 |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package info.novatec.testit.webtester.support.hamcrest; | ||
|
||
import info.novatec.testit.webtester.pageobjects.GenericTextField; | ||
import org.junit.Assert; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.Mock; | ||
import org.mockito.runners.MockitoJUnitRunner; | ||
|
||
import static info.novatec.testit.webtester.support.hamcrest.GenericTextFieldMatcher.hasText; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.not; | ||
import static org.mockito.Mockito.doReturn; | ||
|
||
@RunWith(MockitoJUnitRunner.class) | ||
public class GenericTextFieldMatcherTest { | ||
|
||
static final String TEXT = "foo"; | ||
|
||
static final String ANOTHER_TEXT = "bar"; | ||
|
||
@Mock | ||
GenericTextField genericTextField; | ||
|
||
@Before | ||
public void setUp(){ | ||
doReturn(TEXT).when(genericTextField).getText(); | ||
} | ||
|
||
@Test | ||
public void hasTextTrueTest(){ | ||
assertThat(genericTextField, hasText(TEXT)); | ||
} | ||
|
||
@Test (expected = AssertionError.class) | ||
public void hasTextFalseTest(){ | ||
assertThat(genericTextField, hasText(ANOTHER_TEXT)); | ||
} | ||
|
||
@Test | ||
public void notHasTextTrueTest(){ | ||
assertThat(genericTextField, not(hasText(ANOTHER_TEXT))); | ||
} | ||
|
||
@Test (expected = AssertionError.class) | ||
public void notHasTextFalseTest(){ | ||
assertThat(genericTextField, not(hasText(TEXT))); | ||
} | ||
} |