org.assertj.core.api.Java6Assertions Java Examples

The following examples show how to use org.assertj.core.api.Java6Assertions. 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: LithoViewAssert.java    From litho with Apache License 2.0 6 votes vote down vote up
public LithoViewAssert containsTestKey(String testKey, OccurrenceCount count) {
  final Deque<TestItem> testItems = LithoViewTestHelper.findTestItems(actual, testKey);
  Java6Assertions.assertThat(testItems)
      .hasSize(count.times)
      .overridingErrorMessage(
          "Expected to find test key <%s> in LithoView <%s> %s, but %s.",
          testKey,
          actual,
          count,
          testItems.isEmpty()
              ? "couldn't find it"
              : String.format(Locale.ROOT, "saw it %d times instead", testItems.size()))
      .isNotNull();

  return this;
}
 
Example #2
Source File: ViewTreeAssert.java    From litho with Apache License 2.0 6 votes vote down vote up
public <V extends View> ViewTreeAssert hasVisible(
    final Class<V> clazz, final Predicate<V> predicate) {
  final Predicate<View> conjunction =
      Predicates.and(
          Predicates.instanceOf(clazz), ViewPredicates.isVisible(), (Predicate<View>) predicate);

  final ImmutableList<View> path = actual.findChild(conjunction, ViewPredicates.isVisible());

  Java6Assertions.assertThat(path)
      .overridingErrorMessage(
          "Did not find view for which given predicate is true in view hierarchy:%n%s",
          actual.makeString(null))
      .isNotNull();

  return this;
}
 
Example #3
Source File: Applicability_Test.java    From estatio with Apache License 2.0 5 votes vote down vote up
@Test
public void happy_case() throws Exception {

    // when
    final Applicability applicability =
            new Applicability(mockDocumentTemplate,
                    SomeDomainObject.class, SomeRendererModelFactory.class, SomeAttachmentAdvisor.class);

    // then
    Java6Assertions.assertThat(applicability.getDocumentTemplate()).isEqualTo(mockDocumentTemplate);
    Java6Assertions.assertThat(applicability.getDomainClassName()).isEqualTo(SomeDomainObject.class.getName());
    Java6Assertions.assertThat(applicability.getRendererModelFactoryClassName()).isEqualTo(SomeRendererModelFactory.class.getName());
    Java6Assertions.assertThat(applicability.getAttachmentAdvisorClassName()).isEqualTo(SomeAttachmentAdvisor.class.getName());

}
 
Example #4
Source File: CliqueBlockCreatorTest.java    From besu with Apache License 2.0 5 votes vote down vote up
@Test
public void proposerAddressCanBeExtractFromAConstructedBlock() {

  final Bytes extraData =
      CliqueExtraData.createWithoutProposerSeal(Bytes.wrap(new byte[32]), validatorList);

  final Address coinbase = AddressHelpers.ofValue(1);
  final CliqueBlockCreator blockCreator =
      new CliqueBlockCreator(
          coinbase,
          parent -> extraData,
          new PendingTransactions(
              TransactionPoolConfiguration.DEFAULT_TX_RETENTION_HOURS,
              5,
              5,
              TestClock.fixed(),
              metricsSystem,
              blockchain::getChainHeadHeader,
              Optional.empty(),
              TransactionPoolConfiguration.DEFAULT_PRICE_BUMP),
          protocolContext,
          protocolSchedule,
          gasLimit -> gasLimit,
          proposerNodeKey,
          Wei.ZERO,
          0.8,
          blockchain.getChainHeadHeader(),
          epochManager);

  final Block createdBlock = blockCreator.createBlock(5L);

  Java6Assertions.assertThat(CliqueHelpers.getProposerOfBlock(createdBlock.getHeader()))
      .isEqualTo(proposerAddress);
}
 
Example #5
Source File: LithoViewAssert.java    From litho with Apache License 2.0 5 votes vote down vote up
/** Assert that the LithoView under test has the provided measured height. */
public LithoViewAssert hasMeasuredHeightOf(int height) {
  Java6Assertions.assertThat(actual.getMeasuredHeight())
      .overridingErrorMessage(
          "Expected LithoView to have a height of %d, but was %d.",
          height, actual.getMeasuredHeight())
      .isEqualTo(height);

  return this;
}
 
Example #6
Source File: LithoViewAssert.java    From litho with Apache License 2.0 5 votes vote down vote up
/** Assert that the LithoView under test has the provided measured width. */
public LithoViewAssert hasMeasuredWidthOf(int width) {
  Java6Assertions.assertThat(actual.getMeasuredWidth())
      .overridingErrorMessage(
          "Expected LithoView to have a width of %d, but was %d.",
          width, actual.getMeasuredWidth())
      .isEqualTo(width);

  return this;
}
 
Example #7
Source File: LithoViewAssert.java    From litho with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("VisibleForTests")
public LithoViewAssert doesNotContainTestKey(String testKey) {
  final TestItem testItem = LithoViewTestHelper.findTestItem(actual, testKey);
  final Rect bounds = testItem == null ? null : testItem.getBounds();

  Java6Assertions.assertThat(testItem)
      .overridingErrorMessage(
          "Expected not to find test key <%s> in LithoView <%s>, but it was present at "
              + "bounds %s.",
          testKey, actual, bounds)
      .isNull();

  return this;
}
 
Example #8
Source File: StateValueAssert.java    From litho with Apache License 2.0 5 votes vote down vote up
/** Equivalent to calling <code>assertThat(value.get()).isEqualTo(value)</code>. */
public StateValueAssert<T> valueEqualTo(T value) {
  Java6Assertions.assertThat(actual.get())
      .overridingErrorMessage(
          "Expected state value to equal to <%s>, but was <%s>.", value, actual.get())
      .isEqualTo(value);

  return this;
}
 
Example #9
Source File: ComponentAssert.java    From litho with Apache License 2.0 5 votes vote down vote up
/**
 * Assert that a given {@link Component} produces a layout that's not equivalent to {@link
 * ComponentContext#NULL_LAYOUT}.
 */
public ComponentAssert willRender() {
  Java6Assertions.assertThat(Component.willRender(mComponentContext, actual))
      .overridingErrorMessage("Expected Component to not render to null, but it did.")
      .isTrue();

  return this;
}
 
Example #10
Source File: ComponentAssert.java    From litho with Apache License 2.0 5 votes vote down vote up
/**
 * Assert that a given {@link Component} renders to null, i.e. its <code>onCreateLayout
 * </code> method resolves to a {@link ComponentContext#NULL_LAYOUT}.
 */
public ComponentAssert wontRender() {
  Java6Assertions.assertThat(Component.willRender(mComponentContext, actual))
      .overridingErrorMessage("Expected Component to render to null, but it did not.")
      .isFalse();

  return this;
}
 
Example #11
Source File: ComponentAssert.java    From litho with Apache License 2.0 5 votes vote down vote up
/**
 * Verifies that the component contains only the given sub-components and nothing else, in order.
 *
 * @deprecated Use {@link #extractingSubComponents} instead.
 */
@Deprecated
public ComponentAssert containsOnlySubComponents(SubComponent... subComponents) {
  final List<SubComponent> mountedSubComponents =
      ComponentTestHelper.getSubComponents(mComponentContext, actual);

  Java6Assertions.assertThat(mountedSubComponents).containsOnly(subComponents);

  return this;
}
 
Example #12
Source File: ComponentAssert.java    From litho with Apache License 2.0 5 votes vote down vote up
/**
 * Verifies that the component contains the exact list of provided sub-components.
 *
 * @deprecated Use {@link #extractingSubComponents} instead.
 */
@Deprecated
public ComponentAssert hasSubComponents(SubComponent... subComponents) {
  final List<SubComponent> mountedSubComponents =
      ComponentTestHelper.getSubComponents(mComponentContext, actual);

  Java6Assertions.assertThat(mountedSubComponents).containsExactly(subComponents);

  return this;
}
 
Example #13
Source File: ComponentAssert.java    From litho with Apache License 2.0 5 votes vote down vote up
/**
 * Assert that the given component does <strong>not</strong> contain the provided sub-component.
 *
 * @deprecated Use {@link #extractingSubComponents} instead.
 */
@Deprecated
public ComponentAssert doesNotContainSubComponent(SubComponent subComponent) {
  final List<SubComponent> subComponents =
      ComponentTestHelper.getSubComponents(mComponentContext, actual);
  Java6Assertions.assertThat(subComponents)
      .overridingErrorMessage(
          "Did not expect to find <%s> as sub component of <%s>, " + "but it was present.",
          subComponent, actual)
      .doesNotContain(subComponent);

  return this;
}
 
Example #14
Source File: ComponentAssert.java    From litho with Apache License 2.0 5 votes vote down vote up
/**
 * Assert that the given component contains the provided sub-component.
 *
 * @deprecated Use {@link #extractingSubComponents} instead.
 */
@Deprecated
public ComponentAssert containsSubComponent(SubComponent subComponent) {
  final List<SubComponent> subComponents =
      ComponentTestHelper.getSubComponents(mComponentContext, actual);
  Java6Assertions.assertThat(subComponents)
      .overridingErrorMessage(
          "Expected to find <%s> as sub component of <%s>, " + "but couldn't find it in %s.",
          subComponent, actual, subComponents)
      .contains(subComponent);

  return this;
}
 
Example #15
Source File: ComponentAssert.java    From litho with Apache License 2.0 5 votes vote down vote up
/**
 * Assert that the given component has no sub-components.
 *
 * @deprecated Use {@link #extractingSubComponents} instead.
 */
@Deprecated
public ComponentAssert hasNoSubComponents() {
  final List<SubComponent> subComponents =
      ComponentTestHelper.getSubComponents(mComponentContext, actual);
  Java6Assertions.assertThat(subComponents)
      .overridingErrorMessage(
          "Expected Component not to have any sub " + "components, but found %d.",
          subComponents.size())
      .isEmpty();

  return this;
}
 
Example #16
Source File: ViewTreeAssert.java    From litho with Apache License 2.0 5 votes vote down vote up
public <V extends View> ViewTreeAssert doesNotHaveVisible(
    final Class<V> clazz, final Predicate<Object> predicate) {
  final Predicate<View> conjunction =
      Predicates.and(Predicates.instanceOf(clazz), ViewPredicates.isVisible(), predicate);

  final ImmutableList<View> path = actual.findChild(conjunction, ViewPredicates.isVisible());

  Java6Assertions.assertThat(path)
      .overridingErrorMessage(
          "Found a view for which given predicate is true in view hierarchy:%n%s",
          actual.makeString(null))
      .isNull();

  return this;
}
 
Example #17
Source File: ViewTreeAssert.java    From litho with Apache License 2.0 5 votes vote down vote up
/** Whether there is not a visible view in the hierarchy with the given id. */
public ViewTreeAssert doesNotHaveVisibleViewWithId(final int viewId) {
  final ImmutableList<View> path = getPathToVisibleWithId(viewId);

  Java6Assertions.assertThat(path)
      .overridingErrorMessage(
          "Found visible view with id \"%s=%d\":%n%s",
          ViewTreeUtil.getResourceName(viewId),
          viewId,
          actual.makeString(ViewExtractors.GET_VIEW_ID_FUNCTION))
      .isNull();

  return this;
}
 
Example #18
Source File: ViewTreeAssert.java    From litho with Apache License 2.0 5 votes vote down vote up
/** Whether there is a visible view in the hierarchy with the given id. */
public ViewTreeAssert hasVisibleViewWithId(final int viewId) {
  final ImmutableList<View> path = getPathToVisibleWithId(viewId);

  Java6Assertions.assertThat(path)
      .overridingErrorMessage(
          "Did not find visible view with id \"%s=%d\":%n%s",
          ViewTreeUtil.getResourceName(viewId),
          viewId,
          actual.makeString(ViewExtractors.GET_VIEW_ID_FUNCTION))
      .isNotNull();

  return this;
}
 
Example #19
Source File: ViewTreeAssert.java    From litho with Apache License 2.0 5 votes vote down vote up
/**
 * Tests all views in the hierarchy under the root, for which the path is visible, are not
 * displaying the requested drawable
 *
 * @param drawable the drawable to look for
 * @return the assertions object
 */
public ViewTreeAssert doesNotHaveVisibleDrawable(final Drawable drawable) {
  final ImmutableList<View> path = getPathToVisibleWithDrawable(drawable);

  Java6Assertions.assertThat(path)
      .overridingErrorMessage(
          "Found drawable %s in view hierarchy:%n%s",
          drawable, actual.makeString(ViewExtractors.GET_DRAWABLE_FUNCTION))
      .isNull();

  return this;
}
 
Example #20
Source File: ViewTreeAssert.java    From litho with Apache License 2.0 5 votes vote down vote up
/**
 * Tests if any view in the hierarchy under the root, for which the path is visible, is displaying
 * the requested drawable
 *
 * @param drawable the drawable to look for
 * @return the assertions object
 */
public ViewTreeAssert hasVisibleDrawable(final Drawable drawable) {
  final ImmutableList<View> path = getPathToVisibleWithDrawable(drawable);

  Java6Assertions.assertThat(path)
      .overridingErrorMessage(
          "Did not find drawable %s in view hierarchy:%n%s",
          drawable, actual.makeString(ViewExtractors.GET_DRAWABLE_FUNCTION))
      .isNotNull();

  return this;
}
 
Example #21
Source File: ViewTreeAssert.java    From litho with Apache License 2.0 5 votes vote down vote up
/**
 * Tests that all views in the hierarchy under the root, for which the path is visible, do not
 * have any text appearing on them
 *
 * @return the assertions object
 */
public ViewTreeAssert doesNotHaveVisibleText() {
  final ImmutableList<View> path = getPathToVisibleMatchingText(".+");

  Java6Assertions.assertThat(path)
      .overridingErrorMessage(
          "Found text \"%s\" in view hierarchy for path: %s",
          getTextProof(path), makeString(path))
      .isNull();

  return this;
}
 
Example #22
Source File: ViewTreeAssert.java    From litho with Apache License 2.0 5 votes vote down vote up
/**
 * Tests that all views in the hierarchy under the root, for which the path is visible, do not
 * have text that matches against the given regular expression
 *
 * @param pattern the regular expression to match against
 * @return the assertions object(
 */
public ViewTreeAssert doesNotHaveVisibleTextMatching(final String pattern) {
  final ImmutableList<View> path = getPathToVisibleMatchingText(pattern);

  Java6Assertions.assertThat(path)
      .overridingErrorMessage(
          "Found pattern \"%s\" in view hierarchy for path: %s", pattern, makeString(path))
      .isNull();

  return this;
}
 
Example #23
Source File: ViewTreeAssert.java    From litho with Apache License 2.0 5 votes vote down vote up
/**
 * Tests if any view in the hierarchy under the root, for which the path is visible, has text that
 * matches the given regular expression
 *
 * @param pattern the regular expression to match against
 * @return the assertions object
 */
public ViewTreeAssert hasVisibleTextMatching(final String pattern) {
  final ImmutableList<View> path = getPathToVisibleMatchingText(pattern);

  Java6Assertions.assertThat(path)
      .overridingErrorMessage(
          "Cannot find text matching \"%s\" in view hierarchy:%n%s",
          pattern, actual.makeString(GET_TEXT_FUNCTION))
      .isNotNull();

  return this;
}
 
Example #24
Source File: ViewTreeAssert.java    From litho with Apache License 2.0 5 votes vote down vote up
/**
 * Tests if any view hierarchy under the root has the given contentDescription.
 *
 * @param contentDescription the contentDescription to search for
 * @return the assertions object
 */
public ViewTreeAssert hasContentDescription(final String contentDescription) {
  final ImmutableList<View> path = getPathToContentDescription(contentDescription);

  Java6Assertions.assertThat(path)
      .overridingErrorMessage(
          "Cannot find content description \"%s\" in view hierarchy:%n%s",
          contentDescription, actual.makeString(ViewExtractors.GET_CONTENT_DESCRIPTION_FUNCTION))
      .isNotNull();

  return this;
}
 
Example #25
Source File: ViewTreeAssert.java    From litho with Apache License 2.0 5 votes vote down vote up
/**
 * Tests if any view hierarchy under the root has the given view tag and value.
 *
 * @param tagId the id to look for
 * @param tagValue the value that the id should have
 * @return the assertions object
 */
public ViewTreeAssert hasViewTag(final int tagId, final Object tagValue) {
  final ImmutableList<View> path = getPathToViewTag(tagId, tagValue);

  Java6Assertions.assertThat(path)
      .overridingErrorMessage(
          "Cannot find tag id \"%d\" with tag value \"%s\" in view hierarchy:%n%s",
          tagId, tagValue, actual.makeString(ViewExtractors.generateGetViewTagFunction(tagId)))
      .isNotNull();

  return this;
}
 
Example #26
Source File: ViewTreeAssert.java    From litho with Apache License 2.0 5 votes vote down vote up
/**
 * Tests that all views in the hierarchy under the root, for which the path is visible, do not
 * have text equal to the given string
 *
 * @param text the text to search for
 * @return the assertions object
 */
public ViewTreeAssert doesNotHaveVisibleText(final String text) {
  final ImmutableList<View> path = getPathToVisibleText(text);

  Java6Assertions.assertThat(path)
      .overridingErrorMessage(
          "Found text \"%s\" in view hierarchy for path: %s", text, makeString(path))
      .isNull();

  return this;
}
 
Example #27
Source File: ViewTreeAssert.java    From litho with Apache License 2.0 5 votes vote down vote up
/**
 * Tests if any view in the hierarchy under the root, for which the path is visible, has the
 * requested piece of text as its text and has a tag set on that TextView with the given tag id
 * and tag value.
 *
 * @param text the text to search for
 * @param tagId the tag to look for on the TextView containing the searched text
 * @param tagValue the expected value of the tag associated with tagId
 * @return the assertions object
 */
public ViewTreeAssert hasVisibleTextWithTag(
    final String text, final int tagId, final Object tagValue) {
  final ImmutableList<View> path = getPathToVisibleTextWithTag(text, tagId, tagValue);

  Java6Assertions.assertThat(path)
      .overridingErrorMessage(
          "Cannot find text \"%s\" with tagId \"%d\" and value:%s in view hierarchy:%n%s",
          text, tagId, tagValue.toString(), actual.makeString(GET_TEXT_FUNCTION))
      .isNotNull();

  return this;
}
 
Example #28
Source File: ViewTreeAssert.java    From litho with Apache License 2.0 5 votes vote down vote up
/**
 * Tests if any view in the hierarchy under the root, for which the path is visible, has the
 * requested piece of text as its text
 *
 * @param text the text to search for
 * @return the assertions object
 */
public ViewTreeAssert hasVisibleText(final String text) {
  final ImmutableList<View> path = getPathToVisibleText(text);

  Java6Assertions.assertThat(path)
      .overridingErrorMessage(path == null ? getHasVisibleTextErrorMessage(text) : "")
      .isNotNull();

  return this;
}
 
Example #29
Source File: MatchNode.java    From litho with Apache License 2.0 5 votes vote down vote up
/**
 * Asserts the actual object matches the assertions specified by this MatchNode. Subclasses should
 * override this class and call super to provide more assertions.
 */
public final void assertMatches(Object o, DebugTraceContext debugContext) {
  debugContext.mNodes.add(this);

  Java6Assertions.assertThat(o)
      .describedAs(getDescription("Expecting type " + mType))
      .isInstanceOf(mType);

  for (Map.Entry<String, Object> prop : mExpectedProps.entrySet()) {
    Object expected = prop.getValue();
    Object actual = getProp(o, mType, prop.getKey());
    if (expected instanceof MatchNode) {
      ((MatchNode) expected).assertMatches(actual, debugContext);
    } else if (expected instanceof MatchNodeList) {
      final MatchNodeList expectedList = (MatchNodeList) expected;
      Java6Assertions.assertThat(actual)
          .describedAs(getDescription("Field " + prop.getKey() + " is not a List."))
          .isInstanceOf(List.class);
      final List actualList = (List) actual;
      Java6Assertions.assertThat(actualList)
          .describedAs("Size of list on field " + prop.getKey())
          .hasSize(expectedList.getList().size());

      for (int i = 0; i < actualList.size(); i++) {
        expectedList.getList().get(i).assertMatches(actualList.get(i), debugContext);
      }
    } else if (expected instanceof PropAssertion) {
      ((PropAssertion) expected).doAssert(actual);
    } else {
      Java6Assertions.assertThat(actual)
          .describedAs(getDescription("Comparing field '" + prop.getKey() + "' on " + o))
          .isEqualTo(expected);
    }
  }

  assertMatchesImpl(o, debugContext);

  debugContext.mNodes.remove(debugContext.mNodes.lastIndexOf(this));
}
 
Example #30
Source File: ViewMatchNode.java    From litho with Apache License 2.0 5 votes vote down vote up
@Override
public void assertMatchesImpl(Object o, DebugTraceContext debugContext) {
  View view = (View) o;

  if (mBounds != null) {
    Java6Assertions.assertThat(
            new Rect(view.getLeft(), view.getTop(), view.getWidth(), view.getHeight()))
        .describedAs(getDescription("Bounds on " + viewToString(view)))
        .isEqualTo(mBounds);
  }

  if (mPadding != null) {
    Java6Assertions.assertThat(
            new Rect(
                view.getPaddingLeft(),
                view.getPaddingTop(),
                view.getPaddingRight(),
                view.getPaddingBottom()))
        .describedAs(getDescription("Padding on " + viewToString(view)))
        .isEqualTo(mPadding);
  }

  if (!(view instanceof ViewGroup)) {
    Java6Assertions.assertThat(mChildren)
        .describedAs(getDescription("Child count on " + viewToString(view)))
        .isEmpty();
  } else {
    final ViewGroup viewGroup = (ViewGroup) view;
    Java6Assertions.assertThat(viewGroup.getChildCount())
        .describedAs(getDescription("Child count on " + viewToString(view)))
        .isEqualTo(mChildren.size());
    for (int i = 0; i < viewGroup.getChildCount(); i++) {
      mChildren.get(i).assertMatches(viewGroup.getChildAt(i), debugContext);
    }
  }
}