org.hamcrest.Factory Java Examples
The following examples show how to use
org.hamcrest.Factory.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AdditionalTableViewMatchers.java From chvote-1-0 with GNU Affero General Public License v3.0 | 6 votes |
@Factory public static <T> Matcher<Node> cellWithValue(final Matcher<T> contentsMatcher) { return new TypeSafeMatcher<Node>(Cell.class) { @Override protected boolean matchesSafely(Node item) { return contentsMatcher.matches(((Cell) item).getItem()); } @Override public void describeTo(Description description) { description.appendText(Cell.class.getSimpleName()) .appendText(" ") .appendText("with value") .appendDescriptionOf(contentsMatcher); } }; }
Example #2
Source File: Matchers.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 6 votes |
@Factory @Deprecated /** * Please avoid using as the hamcrest way of reporting error wraps a multi-line * text into a single line and makes hard to understand the problem. * Instead, please try to use the spock/groovy assert and {@link #containsLine(String, String)} */ public static Matcher<String> containsLine(final String line) { return new BaseMatcher<String>() { public boolean matches(Object o) { return containsLine(equalTo(line)).matches(o); } public void describeTo(Description description) { description.appendText("a String that contains line ").appendValue(line); } }; }
Example #3
Source File: Matchers.java From pushfish-android with BSD 2-Clause "Simplified" License | 6 votes |
@Factory @Deprecated /** * Please avoid using as the hamcrest way of reporting error wraps a multi-line * text into a single line and makes hard to understand the problem. * Instead, please try to use the spock/groovy assert and {@link #containsLine(String, String)} */ public static Matcher<String> containsLine(final String line) { return new BaseMatcher<String>() { public boolean matches(Object o) { return containsLine(equalTo(line)).matches(o); } public void describeTo(Description description) { description.appendText("a String that contains line ").appendValue(line); } }; }
Example #4
Source File: Matchers.java From pushfish-android with BSD 2-Clause "Simplified" License | 6 votes |
@Factory public static Matcher<Object> isSerializable() { return new BaseMatcher<Object>() { public boolean matches(Object o) { try { new ObjectOutputStream(new ByteArrayOutputStream()).writeObject(o); } catch (IOException e) { throw new RuntimeException(e); } return true; } public void describeTo(Description description) { description.appendText("is serializable"); } }; }
Example #5
Source File: Matchers.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 5 votes |
@Factory public static Matcher<Map<?, ?>> isEmptyMap() { return new BaseMatcher<Map<?, ?>>() { public boolean matches(Object o) { Map<?, ?> map = (Map<?, ?>) o; return map != null && map.isEmpty(); } public void describeTo(Description description) { description.appendText("an empty map"); } }; }
Example #6
Source File: Matchers.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 5 votes |
@Factory public static Matcher<Iterable<?>> isEmpty() { return new BaseMatcher<Iterable<?>>() { public boolean matches(Object o) { Iterable<?> iterable = (Iterable<?>) o; return iterable != null && !iterable.iterator().hasNext(); } public void describeTo(Description description) { description.appendText("an empty Iterable"); } }; }
Example #7
Source File: Matchers.java From pushfish-android with BSD 2-Clause "Simplified" License | 5 votes |
@Factory public static Matcher<String> normalizedLineSeparators(final Matcher<String> matcher) { return new BaseMatcher<String>() { public boolean matches(Object o) { String string = (String) o; return matcher.matches(string.replace(SystemProperties.getLineSeparator(), "\n")); } public void describeTo(Description description) { matcher.describeTo(description); description.appendText(" (normalize line separators)"); } }; }
Example #8
Source File: Matchers.java From pushfish-android with BSD 2-Clause "Simplified" License | 5 votes |
@Factory public static Matcher<Throwable> hasMessage(final Matcher<String> matcher) { return new BaseMatcher<Throwable>() { public boolean matches(Object o) { Throwable t = (Throwable) o; return matcher.matches(t.getMessage()); } public void describeTo(Description description) { description.appendText("an exception with message that is ").appendDescriptionOf(matcher); } }; }
Example #9
Source File: Matchers.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 5 votes |
@Factory public static Matcher<String> containsLine(final Matcher<? super String> matcher) { return new BaseMatcher<String>() { public boolean matches(Object o) { String str = (String) o; return containsLine(str, matcher); } public void describeTo(Description description) { description.appendText("a String that contains line that is ").appendDescriptionOf(matcher); } }; }
Example #10
Source File: Matchers.java From pushfish-android with BSD 2-Clause "Simplified" License | 5 votes |
@Factory public static Matcher<String> containsLine(final Matcher<? super String> matcher) { return new BaseMatcher<String>() { public boolean matches(Object o) { String str = (String) o; return containsLine(str, matcher); } public void describeTo(Description description) { description.appendText("a String that contains line that is ").appendDescriptionOf(matcher); } }; }
Example #11
Source File: Matchers.java From pushfish-android with BSD 2-Clause "Simplified" License | 5 votes |
@Factory public static <T> Matcher<T> strictlyEqual(final T other) { return new BaseMatcher<T>() { public boolean matches(Object o) { return strictlyEquals(o, other); } public void describeTo(Description description) { description.appendText("an Object that strictly equals ").appendValue(other); } }; }
Example #12
Source File: Matchers.java From pushfish-android with BSD 2-Clause "Simplified" License | 5 votes |
@Factory public static <T extends CharSequence> Matcher<T> containsText(final String pattern) { return new BaseMatcher<T>() { public boolean matches(Object o) { return Pattern.compile(pattern).matcher((CharSequence) o).find(); } public void describeTo(Description description) { description.appendText("a CharSequence that contains text ").appendValue(pattern); } }; }
Example #13
Source File: Matchers.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 5 votes |
@Factory public static Matcher<Throwable> hasMessage(final Matcher<String> matcher) { return new BaseMatcher<Throwable>() { public boolean matches(Object o) { Throwable t = (Throwable) o; return matcher.matches(t.getMessage()); } public void describeTo(Description description) { description.appendText("an exception with message that is ").appendDescriptionOf(matcher); } }; }
Example #14
Source File: Matchers.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 5 votes |
@Factory public static <T extends CharSequence> Matcher<T> containsText(final String pattern) { return new BaseMatcher<T>() { public boolean matches(Object o) { return Pattern.compile(pattern).matcher((CharSequence) o).find(); } public void describeTo(Description description) { description.appendText("a CharSequence that contains text ").appendValue(pattern); } }; }
Example #15
Source File: Matchers.java From pushfish-android with BSD 2-Clause "Simplified" License | 5 votes |
/** * A reimplementation of hamcrest's isA() but without the broken generics. */ @Factory public static Matcher<Object> isA(final Class<?> type) { return new BaseMatcher<Object>() { public boolean matches(Object item) { return type.isInstance(item); } public void describeTo(Description description) { description.appendText("instanceof ").appendValue(type); } }; }
Example #16
Source File: Matchers.java From pushfish-android with BSD 2-Clause "Simplified" License | 5 votes |
@Factory public static <T extends CharSequence> Matcher<T> matchesRegexp(final String pattern) { return new BaseMatcher<T>() { public boolean matches(Object o) { return Pattern.compile(pattern).matcher((CharSequence) o).matches(); } public void describeTo(Description description) { description.appendText("a CharSequence that matches regexp ").appendValue(pattern); } }; }
Example #17
Source File: Matchers.java From pushfish-android with BSD 2-Clause "Simplified" License | 5 votes |
@Factory public static <T extends CharSequence> Matcher<T> matchesRegexp(final Pattern pattern) { return new BaseMatcher<T>() { public boolean matches(Object o) { return pattern.matcher((CharSequence) o).matches(); } public void describeTo(Description description) { description.appendText("a CharSequence that matches regexp ").appendValue(pattern); } }; }
Example #18
Source File: Matchers.java From pushfish-android with BSD 2-Clause "Simplified" License | 5 votes |
@Factory public static <T extends CharSequence> Matcher<T> containsText(final String pattern) { return new BaseMatcher<T>() { public boolean matches(Object o) { return Pattern.compile(pattern).matcher((CharSequence) o).find(); } public void describeTo(Description description) { description.appendText("a CharSequence that contains text ").appendValue(pattern); } }; }
Example #19
Source File: Matchers.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 5 votes |
@Factory public static <T> Matcher<T> strictlyEqual(final T other) { return new BaseMatcher<T>() { public boolean matches(Object o) { return strictlyEquals(o, other); } public void describeTo(Description description) { description.appendText("an Object that strictly equals ").appendValue(other); } }; }
Example #20
Source File: Matchers.java From pushfish-android with BSD 2-Clause "Simplified" License | 5 votes |
@Factory public static Matcher<String> containsLine(final Matcher<? super String> matcher) { return new BaseMatcher<String>() { public boolean matches(Object o) { String str = (String) o; return containsLine(str, matcher); } public void describeTo(Description description) { description.appendText("a String that contains line that is ").appendDescriptionOf(matcher); } }; }
Example #21
Source File: Matchers.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 5 votes |
@Factory public static Matcher<String> normalizedLineSeparators(final Matcher<String> matcher) { return new BaseMatcher<String>() { public boolean matches(Object o) { String string = (String) o; return matcher.matches(string.replace(SystemProperties.getLineSeparator(), "\n")); } public void describeTo(Description description) { matcher.describeTo(description); description.appendText(" (normalize line separators)"); } }; }
Example #22
Source File: Matchers.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 5 votes |
@Factory public static Matcher<Iterable<?>> isEmpty() { return new BaseMatcher<Iterable<?>>() { public boolean matches(Object o) { Iterable<?> iterable = (Iterable<?>) o; return iterable != null && !iterable.iterator().hasNext(); } public void describeTo(Description description) { description.appendText("an empty Iterable"); } }; }
Example #23
Source File: Matchers.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 5 votes |
/** * A reimplementation of hamcrest's isA() but without the broken generics. */ @Factory public static Matcher<Object> isA(final Class<?> type) { return new BaseMatcher<Object>() { public boolean matches(Object item) { return type.isInstance(item); } public void describeTo(Description description) { description.appendText("instanceof ").appendValue(type); } }; }
Example #24
Source File: Matchers.java From pushfish-android with BSD 2-Clause "Simplified" License | 5 votes |
@Factory public static Matcher<Throwable> hasMessage(final Matcher<String> matcher) { return new BaseMatcher<Throwable>() { public boolean matches(Object o) { Throwable t = (Throwable) o; return matcher.matches(t.getMessage()); } public void describeTo(Description description) { description.appendText("an exception with message that is ").appendDescriptionOf(matcher); } }; }
Example #25
Source File: Matchers.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 5 votes |
@Factory public static <T extends CharSequence> Matcher<T> matchesRegexp(final Pattern pattern) { return new BaseMatcher<T>() { public boolean matches(Object o) { return pattern.matcher((CharSequence) o).matches(); } public void describeTo(Description description) { description.appendText("a CharSequence that matches regexp ").appendValue(pattern); } }; }
Example #26
Source File: Matchers.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 5 votes |
@Factory public static Matcher<String> containsLine(final Matcher<? super String> matcher) { return new BaseMatcher<String>() { public boolean matches(Object o) { String str = (String) o; return containsLine(str, matcher); } public void describeTo(Description description) { description.appendText("a String that contains line that is ").appendDescriptionOf(matcher); } }; }
Example #27
Source File: DisplayedMatcher.java From htmlelements with Apache License 2.0 | 4 votes |
/** * Creates matcher that checks if element is currently displayed on page. */ @Factory public static Matcher<WebElement> displayed() { return new DisplayedMatcher(); }
Example #28
Source File: AspectRatioIsCloseTo.java From cameraview with Apache License 2.0 | 4 votes |
@Factory public static Matcher<AspectRatio> closeTo(AspectRatio ratio) { return new AspectRatioIsCloseTo(ratio); }
Example #29
Source File: One.java From flink-spector with Apache License 2.0 | 4 votes |
@Factory public static <T> One<T> one(Iterable<Matcher<? super T>> matchers) { return new One<T>(matchers); }
Example #30
Source File: OnOne.java From flink-spector with Apache License 2.0 | 4 votes |
@Factory public static <T> OnOne<T> one(Matcher<T> matcher) { return new OnOne<T>(matcher); }