/*
 * Copyright (c) 2017-present, Facebook, Inc.
 * All rights reserved.
 *
 * This source code is licensed under the BSD-style license found in the
 * LICENSE file in the root directory of this source tree. An additional grant
 * of patent rights can be found in the PATENTS file in the same directory.
 */

package com.facebook.litho.testing.assertj;

import static org.hamcrest.core.Is.is;

import com.facebook.litho.testing.InspectableComponent;
import org.assertj.core.api.Condition;
import org.assertj.core.description.TextDescription;
import org.hamcrest.Matcher;

/** Provides various helpers to match against {@link InspectableComponent}s. */
// TODO(T21048805): Provide examples in the javadoc.
public final class ComponentConditions {
  private ComponentConditions() {}

  /**
   * Matcher that succeeds if a {@link InspectableComponent} has a text content that exactly matches
   * the provided string.
   */
  public static Condition<InspectableComponent> textEquals(final CharSequence text) {
    return text(is(text.toString()));
  }

  /** @see #textEquals(CharSequence) */
  public static Condition<InspectableComponent> textEquals(final String text) {
    return text(is(text));
  }

  /**
   * Matcher that succeeds if a {@link InspectableComponent} has text content that matches the
   * provided condition.
   *
   * <p>N.B. We are implicitly casting the {@link CharSequence} to a {@link String} when matching so
   * that more powerful matchers can be applied like sub-string matching.
   */
  public static Condition<InspectableComponent> text(final Condition<String> condition) {
    return new Condition<InspectableComponent>(new TextDescription("text = <%s>", condition)) {
      @Override
      public boolean matches(InspectableComponent value) {
        as("expected = <%s>, actual text = <%s>", condition, value.getTextContent());
        return condition.matches(value.getTextContent());
      }
    };
  }

  /**
   * Matcher that succeeds if a {@link InspectableComponent} has text content that matches the
   * provided hamcrest matcher.
   *
   * @return Wrapper around {@link #text(Condition)}
   */
  public static Condition<InspectableComponent> text(final Matcher<String> matcher) {
    return text(new HamcrestCondition<>(matcher));
  }
}

@@ -387,16 +387,62 @@
 Is.is;%0A%0A
+import com.facebook.litho.ComponentLifecycle;%0A
 import c
@@ -821,16 +821,494 @@
 s() %7B%7D%0A%0A
+  /** Matcher that succeeds if a %7B@link InspectableComponent%7D type exactly matches provided one */%0A  public static Condition%3CInspectableComponent%3E typeIs(%0A      final Class%3C? extends ComponentLifecycle%3E clazz) %7B%0A    return new Condition%3CInspectableComponent%3E() %7B%0A      @Override%0A      public boolean matches(InspectableComponent value) %7B%0A        final Class component = value.getComponentClass();%0A        return component != null && component.equals(clazz);%0A      %7D%0A    %7D;%0A  %7D%0A%0A
   /**%0A  

Introduce typeIs Condition which checks for specific subcomponent type