@Override public void describeMismatch(Object item, Description description) { if (!containsAll.matches(item)) { containsAll.describeMismatch(item, description); } if (!containsOnly.matches(item)) { containsOnly.describeMismatch(item, description); } }
public void testEvaluatesToTrueIfArgumentIsEqualToADoubleValueWithinSomeError() { Matcher<Double> p = closeTo(1.0, 0.5); assertTrue(p.matches(1.0)); assertTrue(p.matches(0.5d)); assertTrue(p.matches(1.5d)); assertDoesNotMatch("too large", p, 2.0); assertMismatchDescription("<2.0> differed by <0.5>", p, 2.0); assertDoesNotMatch("number too small", p, 0.0); assertMismatchDescription("<0.0> differed by <0.5>", p, 0.0); }
private boolean tryExtractPropertyValueFrom(Object bean) { ExpressionParser parser = new SpelExpressionParser(); Expression exp = parser.parseExpression(propertyName); beanPropertyValue = exp.getValue(bean); return valueMatcher.matches(beanPropertyValue); }
@Override public boolean matches(Object item) { for (Matcher m : matchers) { if (!m.matches(item)) return false; } return true; }
@Override protected void describeMismatchSafely(T[] item, Description mismatchDescription) { Matches<T> matches = new Matches<>(); Iterator<Matcher<T>> elementIterator = elements.iterator(); Iterator<? extends T> itemIterator = asList(item).iterator(); while (elementIterator.hasNext() && itemIterator.hasNext()) { Matcher<T> matcher = elementIterator.next(); T element = itemIterator.next(); if (!matcher.matches(element)) { matches.mismatch(matcher, element); } else { matches.match(); } } if (elementIterator.hasNext()) { int count = count(elementIterator); matches.mismatch("missing " + count + " elements"); } if (itemIterator.hasNext()) { List<T> items = collect(itemIterator); matches.mismatch("found " + items.size() + " elements surplus " + toDescriptionSet(items)); } if (matches.containsMismatches()) { mismatchDescription.appendText("mismatching elements ").appendDescriptionOf(matches); } }
@Test public void should_obtain_instanciated_matcher_from_matcher() { Matcher<Object> matcher = ((BeanFieldMatcher) BeanMatchers.the("firstName", is("Bill"))).getMatcher(); Person person = new Person("Bill", "Oddie"); assertThat(matcher.matches(person)).isTrue(); }
/** * Waits for specified time period for a shell matching specified matcher. * * @param matcher matcher to match shell * @param timePeriod time period to wait for * @return shell matching specified matcher */ public Shell getShell(final Matcher<String> matcher, TimePeriod timePeriod) { if (!timePeriod.equals(TimePeriod.NONE)) { new WaitUntil(new ShellMatchingMatcherIsAvailable(matcher), timePeriod, false); } Shell[] shells = Display.syncExec( new ResultRunnable<Shell[]>() { @Override public Shell[] run() { return Display.getDisplay().getShells(); } }); for (final Shell s : shells) { if (matcher.matches(s)) { Shell visibleShell = Display.syncExec( new ResultRunnable<Shell>() { @Override public Shell run() { if (!s.isDisposed() && s.isVisible()) { return s; } return null; } }); if (visibleShell != null) { return visibleShell; } } } return null; }
@Override protected boolean matchesSafely(File item) { if (directoryMatcher.matches(item)) { return fileMatcher.matches(files(item)); } else { mismatch = directoryMatcher; return false; } }
/** * Returns a current wizard page * * @return current wizard page * @deprecated use getCurrentWizardPage() instead */ public WizardPage getWizardPage() { for (WizardPage wizardPage : wizardPageMap.keySet()) { Matcher<WizardDialog> matcher = wizardPageMap.get(wizardPage); if (matcher.matches(this)) { return wizardPage; } } log.warn("No wizard page found in page index '" + currentPage + "'"); return null; }
/** {@inheritDoc} */ @SuppressWarnings("unchecked") public <T> JsonAsserter assertThat(String path, Matcher<T> matcher, String message) { T obj = JsonPath.<T>read(jsonObject, path); if (!matcher.matches(obj)) { throw new AssertionError( String.format( "JSON Assert Error: %s\nExpected:\n%s\nActual:\n%s", message, matcher.toString(), obj)); } return this; }
@Override public boolean test() { items = table.getItems(); for (TableItem item : items) { if (!item.getSWTWidget().isDisposed() && matcher.matches(item.getText())) { item.select(); return true; } } return false; }
private static <T extends AccessibilityCheckResult> void modifyResultType( List<T> results, Matcher<? super T> matcher, AccessibilityCheckResultType newType) { if (results == null || matcher == null) { return; } for (T result : results) { if (matcher.matches(result)) { result.setType(newType); } } }
public void processItems(Iterable<? extends F> iterable) { for (F item : iterable) { if (nextMatchIx < matchers.size()) { Matcher<? super F> matcher = matchers.get(nextMatchIx); if (matcher.matches(item)) { lastMatchedItem = item; nextMatchIx++; } } } }
@Override protected boolean matches(Object item, Description mismatchDescription) { FileSink fs = (FileSink) item; try { String contents = fs.getContents(); mismatchDescription.appendValue(contents); return matcher.matches(contents); } catch (IOException e) { mismatchDescription.appendText("failed with an IOException: " + e.getMessage()); return false; } }
private static MenuItem show(final Menu menu, final Matcher<?> matcher) { if (menu != null) { menu.notifyListeners(SWT.Show, new Event()); MenuItem[] items = menu.getItems(); for (final MenuItem menuItem : items) { if (matcher.matches(menuItem)) { return menuItem; } } menu.notifyListeners(SWT.Hide, new Event()); } return null; }
@Override public boolean matches(Object item) { try { if (item == null) { return matchingError("Guice injector is null"); } if (!Injector.class.isAssignableFrom(item.getClass())) { return matchingError("Object " + item + " is not a Guice Injector"); } T instance = ((Injector) item).getInstance(typeKey); if (instance == null) { return matchingError("Instance " + typeKey + " is null"); } Class<?> instanceClass = instance.getClass(); if (!expectedType.isAssignableFrom(instanceClass)) { return matchingError( "Instance " + typeKey + " type mismatch: expected " + expectedType + " but was " + "" + instanceClass); } if (!instanceMatcher.matches(instance)) { matcherDescription = new StringDescription(); matcherDescription.appendText( "Instance " + typeKey + " does not match " + "expectations: "); instanceMatcher.describeMismatch(item, matcherDescription); return false; } else { return true; } } catch (ConfigurationException | ProvisionException ex) { return matchingError( "Cannot get instance of " + typeKey + " from Guice Injector\n" + ex.getMessage() + "\n\n" + "Error stack trace: \n" + "-------------------\n" + getStackTrace(ex)); } }
@Override protected boolean matchesSafely(HtmlFragment html) { if (!html.exists()) return false; index = 1; for (HtmlElement e : html.elements()) { if (matcher.matches(e)) { matched = matcher; return false; } index++; } return true; }
@Override protected boolean matchesSafely(T[] item) { if (item.length != elements.size()) { return false; } Iterator<Matcher<T>> elementIterator = elements.iterator(); Iterator<? extends T> itemIterator = Arrays.asList(item).iterator(); while (elementIterator.hasNext() && itemIterator.hasNext()) { Matcher<T> matcher = elementIterator.next(); T element = itemIterator.next(); if (!matcher.matches(element)) { return false; } } return true; }
public List<String> linesThat(Matcher<? super String> matcher) { try { BufferedReader reader = new BufferedReader(new FileReader(this)); try { List<String> lines = new ArrayList<String>(); String line; while ((line = reader.readLine()) != null) { if (matcher.matches(line)) { lines.add(line); } } return lines; } finally { reader.close(); } } catch (IOException e) { throw new RuntimeException(e); } }
@Override public boolean matchesSafely(JsonNode node) { if (!node.isArray()) { return false; } Iterator<JsonNode> nodeIterator = node.getElements(); int nodeCount = 0; while (nodeIterator.hasNext()) { JsonNode currentNode = nodeIterator.next(); if (nodeCount == position) { return matcher.matches(currentNode.getTextValue()); } nodeCount++; } return false; }
@Override protected boolean matchesSafely(File item) { return nameMatcher.matches(item.getName()); }
/** {@inheritDoc} */ @Override public boolean matchesSafely(Message<?> item) { return matcher.matches(item.getHeaders()); }
/* (non-Javadoc) * @see org.jboss.reddeer.core.matcher.AbstractWidgetWithTextMatcher#matches(java.lang.String) */ @Override protected boolean matches(String text) { return matcher.matches(text); }
@Override public boolean isSatisfiedBy(Item<E> item) { return matcher.matches(item.get()); }
@Override public boolean matchesSafely(WebElement item) { return textMatcher.matches(item.getText()); }
/* (non-Javadoc) * @see org.jboss.reddeer.core.matcher.AbstractWidgetWithTextMatcher#matches(java.lang.String) */ @Override protected boolean matches(String extractedText) { String textToMatch = extractedText.replaceAll("&", "").split("\t")[0]; return matcher.matches(textToMatch); }
public boolean matches(Object item) { return fMatcher.matches(item); }
public boolean matches(Object o) { return matcher.matches(o); }
@Override protected boolean matchesSafely(WrapsElement element) { return matcher.matches(element.getWrappedElement()); }
@Override public boolean matches(Object o) { return containsAll.matches(o) && containsOnly.matches(o); }