private SelfDescribing commandDescription(final Command cmd) { return description -> { final String newLine = System.getProperty("line.separator"); final List<String> logContents = logsOfInternalTests(cmd.getErrorLines()).collect(Collectors.toList()); description .appendText("std-error:\n") .appendValueList("", newLine, newLine, cmd.getErrorLines()); if (!logContents.isEmpty()) { description .appendText("Contents of internal test logs:\n") .appendText("*******************************\n") .appendValueList(newLine, newLine, newLine, logContents); } }; }
static <T,V> Matcher<? super Collection<T>> transformedBy(final Function<T, V> function, final Matcher<Collection<V>> underlying) { return new TypeSafeMatcher<Collection<T>>() { @Override protected boolean matchesSafely(final Collection<T> item) { return underlying.matches( Lists.newArrayList(Iterables.transform(item, function))); } @Override public void describeTo(Description description) { description.appendText("transformed by "); if(function instanceof SelfDescribing) { SelfDescribing selfDescribingFunction = (SelfDescribing) function; description.appendDescriptionOf(selfDescribingFunction); } else { description.appendText("function "); } description.appendDescriptionOf(underlying); } }; }
public void describeTo(Description description) { description.appendText("expected "); cardinality.describeExpected(description); description.appendText(", invoked "); cardinality.describeCount(description); description.appendText(": "); description.appendText(invocable.getName()); description.appendList("(", ", ", ")", argMatchers); if (exceptionMatcher != null) { description.appendText(", expected to throw "); exceptionMatcher.describeTo(description); } else if (returnValueMatcher != null) { description.appendText(", expected to return "); returnValueMatcher.describeTo(description); } if (handler instanceof SelfDescribing) { description.appendText(" (will "); ((SelfDescribing) handler).describeTo(description); description.appendText(")"); } else if (handler != null) { description.appendText(" (handled by "); description.appendValue(handler); description.appendText(")"); } }
private Iterable<SelfDescribing> describedWith(List<Expectation> expectations, final Invocation invocation) { final Iterator<Expectation> iterator = expectations.iterator(); return new Iterable<SelfDescribing>() { public Iterator<SelfDescribing> iterator() { return new Iterator<SelfDescribing>() { public boolean hasNext() { return iterator.hasNext(); } public SelfDescribing next() { return new SelfDescribing() { public void describeTo(Description description) { iterator.next().describeMismatch(invocation, description); } }; } public void remove() { iterator.remove(); } }; } }; }
@Override public Description appendList(String start, String separator, String end, Iterable<? extends SelfDescribing> values) { append(start); boolean first = true; for (SelfDescribing selfDescribing : values) { if (!first) { append(separator); } else { first = false; } selfDescribing.describeTo(this); } append(end); return this; }
public SelfDescribing withExtraTypeInfo() { return new SelfDescribing() { @Override public void describeTo(final Description description) { description.appendText("(" + wanted.getClass().getSimpleName() + ") ").appendText(describe(wanted)); } }; }
private Iterable<SelfDescribing> convertErrors(final List<String> errors) { return errors.stream().map((it) -> { return new SelfDescribing() { @Override public void describeTo(final Description description) { description.appendText(it); } }; }).collect(Collectors.toList()); }
private void describe(Description description, Object value) { if (value instanceof SelfDescribing) { description.appendDescriptionOf((SelfDescribing) value); } else { description.appendValue(value); } }
private List<SelfDescribing> describe(List<Method> conflicts) { List<SelfDescribing> descriptions = new ArrayList<SelfDescribing>(conflicts.size()); for (Method conflict : conflicts) { descriptions.add(new Signature(methodSignature(conflict.getName(), conflict.getReturnType(), conflict.getParameterTypes(), conflict.getExceptionTypes()))); } return descriptions; }
private List<SelfDescribing> describe(List<Method> conflicts) { List<SelfDescribing> descriptions = new ArrayList<SelfDescribing>(conflicts.size()); for (Method conflict : conflicts) { StringBuilder buffer = new StringBuilder(); buffer.append(conflict.getReturnType().getSimpleName()); buffer.append(' '); buffer.append(conflict.getName()); buffer.append('('); Class<?>[] parameterTypes = conflict.getParameterTypes(); if (parameterTypes.length > 0) { buffer.append(parameterTypes[0].getSimpleName()); } for (int i = 1; i < parameterTypes.length; i++) { buffer.append(", "); buffer.append(parameterTypes[i].getSimpleName()); } buffer.append(')'); Class<?>[] exceptionTypes = conflict.getExceptionTypes(); if (exceptionTypes.length > 0) { buffer.append(" throws "); buffer.append(exceptionTypes[0].getSimpleName()); for (int i = 1; i < exceptionTypes.length; i++) { buffer.append(", "); buffer.append(exceptionTypes[i].getSimpleName()); } } descriptions.add(new Signature(buffer.toString())); } return descriptions ; }
private List<SelfDescribing> applyPrintSettings(List<Matcher> matchers, PrintSettings printSettings) { List<SelfDescribing> withPrintSettings = new LinkedList<SelfDescribing>(); int i = 0; for (final Matcher matcher : matchers) { if (matcher instanceof ContainsExtraTypeInformation && printSettings.extraTypeInfoFor(i)) { withPrintSettings.add(((ContainsExtraTypeInformation) matcher).withExtraTypeInfo()); } else { withPrintSettings.add(matcher); } i++; } return withPrintSettings; }
public NotFoundNearestMatchersReducedListFilterResult( SelfDescribing baseWithoutMatchers, CollectionOf<E> foundElements, Description mismatchDescription) { super(foundElements, mismatchDescription); this.baseWithoutCurrentMatcher = baseWithoutMatchers; }
public WithinSingleContextChecker(ExpectationChecker<C0> parentChecker, SFinder<E0, C0> contextFinder, SelfDescribing parentContextDescription, String eachString) { super(null); this.contextFinder = contextFinder; this.parentContextDescription = parentContextDescription; this.eachString = eachString; this.parentChecker = parentChecker; }
public WithinEachContextChecker(CollectionOf<C0> parentContexts, MFinder<E0, C0> contextFinder, SelfDescribing parentContextDescription, String eachString) { super(null); this.parentContexts = parentContexts; this.contextFinder = contextFinder; this.parentContextDescription = parentContextDescription; this.eachString = eachString; }
@Override public SelfDescribing describable(final Object thing) { return new SelfDescribing() { @Override public void describeTo(Description description) { description.appendText(thing.toString()); } }; }
@Override public SelfDescribing describable(final SelfDescribing thing) { return new SelfDescribing() { @Override public void describeTo(Description description) { description.appendDescriptionOf(thing); } }; }
public void describeTo(Description description) { description.appendText("consecutively "); for (Iterator<MethodIntercept> it = handlers.iterator(); it.hasNext(); ) { MethodIntercept handler = it.next(); if (handler instanceof SelfDescribing) { ((SelfDescribing) handler).describeTo(description); } else { description.appendValue(handler); } if (it.hasNext()) { description.appendText(", "); } } }
public Description appendList(String start, String separator, String end, Iterable<? extends SelfDescribing> values) { stringBuilder.append(start); boolean first = true; for (SelfDescribing value : values) { if (!first) { stringBuilder.append(separator); } first = false; value.describeTo(this); } stringBuilder.append(end); return this; }
private ExpectationError mismatchDescribing(final ExpectationError e) { ExpectationError filledIn = new ExpectationError(e.getMessage(), new SelfDescribing() { public void describeTo(Description description) { describeMismatch(e.invocation, description); } }, e.invocation); filledIn.setStackTrace(e.getStackTrace()); return filledIn; }
private void describe(Description description, Iterable<? extends SelfDescribing> selfDescribingExpectations) { if (expectations.isEmpty()) { description.appendText("no expectations specified: did you...\n"+ " - forget to start an expectation with a cardinality clause?\n" + " - call a mocked method to specify the parameter of an expectation?"); } else { description.appendList("expectations:\n ", "\n ", "", selfDescribingExpectations); if (!stateMachines.isEmpty()) { description.appendList("\nstates:\n ", "\n ", "", stateMachines); } } }
@Override public Description appendList( final String start, final String separator, final String end, final Iterable<? extends SelfDescribing> values) { enqueue(new Runnable() { @Override public void run() { description.appendList(start, separator, end, values); } }); return this; }
@Override public Description appendList( String start, String separator, String end, Iterable<? extends SelfDescribing> values) { indentIfNecessary(); description.appendList(start, separator, end, values); return this; }
@Override public Description appendDescriptionOf(SelfDescribing value) { value.describeTo(this); return this; }
public SWTBotForm(Form form, SelfDescribing description) throws WidgetNotFoundException { super(form, description); }
public SwtBotButton(final Button button, final SelfDescribing description) { super(button, description); }
private SelfDescribing mismatch(Matcher<?> matcher, Object item) { return d -> matcher.describeMismatch(item, d); }
public static String describe(SelfDescribing selfDescribing) { StringDescription description = new StringDescription(); selfDescribing.describeTo(description); return description.toString(); }
public SelfDescribing next() { return new SelfDescribingValue<T>(values.next()); }
public SelfDescribing withExtraTypeInfo() { return new SelfDescribing() { public void describeTo(Description description) { description.appendText(describe("("+ wanted.getClass().getSimpleName() +") " + wanted)); }}; }
protected static String describe(SelfDescribing m) { return StringDescription.toString(m); }
public NoBaseFilterResult(SelfDescribing baseWithoutMatchers, CollectionOf<E> foundElements) { super(foundElements); this.baseWithoutMatchers = baseWithoutMatchers; }
protected MatcherFilterer<E> createMatcherFiltererFor( SelfDescribing baseWithoutThisMatcher, Matcher<? super E> matcher) { return new SimpleMatcherFilterer<E>(baseWithoutThisMatcher, new MatcherFilter<E>(matcher), optimized); }
@Override protected MatcherFilterer<E> createMatcherFiltererFor( SelfDescribing baseWithoutThisMatcher, Matcher<? super E> matcher) { return new WrappingMatcherFilterer<E>(baseWithoutThisMatcher, new MatcherFilter<E>(matcher), this.optimized); }
public WrappingMatcherFilterer( SelfDescribing baseWithoutMatchers, MatcherFilter<E> matcherFilter, boolean optimized) { super(baseWithoutMatchers, matcherFilter, optimized); }