/*
 * Copyright (c) 2011 Google, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.google.common.truth;

import com.google.common.annotations.GwtIncompatible;
import com.google.common.base.Optional;

import java.util.Collection;
import java.util.List;
import java.util.Map;

import javax.annotation.CheckReturnValue;


/**
 * Truth - a proposition framework for tests, supporting JUnit style
 * assertion and assumption semantics in a fluent style.
 *
 * Truth is the simplest entry point class. A developer can statically
 * import the assert_() method to get easy access to the library's
 * capabilities. Then, instead of writing:
 *
 * <pre>{@code
 * Assert.assertEquals(a,b);
 * Assert.assertTrue(c);
 * Assert.assertTrue(d.contains(a) && d.contains(e));
 * Assert.assertTrue(d.contains(a) || d.contains(q) || d.contains(z));
 * }</pre>
 * one would write:
 * <pre>{@code
 * assert_().that(aString).equals(bString);
 * assert_().that(aBoolean).isTrue();
 * assert_().that(collection).has().item(aString);
 * assert_().that(collection).containsAllOf(aString, bString);
 * assert_().that(collection).containsAnyOf(aString, qString, zString);
 * }</pre>
 *
 * Tests should be easier to read, and flow more clearly.
 *
 * @author David Saff
 * @author Christian Gruber (cgruber@israfil.net)
 */
public class Truth {

  public static final FailureStrategy THROW_ASSERTION_ERROR =
      new FailureStrategy() {
        @Override public void failComparing(
            String message, CharSequence expected, CharSequence actual) {
          throw Platform.comparisonFailure(message, expected.toString(), actual.toString());
        }
      };

  public static final TestVerb ASSERT = new TestVerb(THROW_ASSERTION_ERROR);

  public static TestVerb assert_() { return ASSERT; }

  private static FailureStrategy getFailureStrategy() {
    return THROW_ASSERTION_ERROR;
  }

  @CheckReturnValue
  public static Subject<DefaultSubject, Object> assertThat(Object target) {
    return new DefaultSubject(getFailureStrategy(), target);
  }

  @CheckReturnValue
  @GwtIncompatible("ClassSubject.java")
  public static ClassSubject assertThat(Class<?> target) {
    return new ClassSubject(getFailureStrategy(), target);
  }

  @CheckReturnValue
  public static IntegerSubject assertThat(Long target) {
    return new IntegerSubject(getFailureStrategy(), target);
  }

  @CheckReturnValue
  public static IntegerSubject assertThat(Integer target) {
    return new IntegerSubject(getFailureStrategy(), target);
  }

  @CheckReturnValue
  public static BooleanSubject assertThat(Boolean target) {
    return new BooleanSubject(getFailureStrategy(), target);
  }

  @CheckReturnValue
  public static StringSubject assertThat(String target) {
    return new StringSubject(getFailureStrategy(), target);
  }

  @CheckReturnValue
  public static <T, C extends Iterable<T>> IterableSubject<? extends IterableSubject<?, T, C>, T, C>
      assertThat(Iterable<T> target) {
    return IterableSubject.create(getFailureStrategy(), target);
  }

  @CheckReturnValue
  public static <T, C extends Collection<T>>
      CollectionSubject<? extends CollectionSubject<?, T, C>, T, C>
      assertThat(Collection<T> target) {
    return CollectionSubject.create(getFailureStrategy(), target);
  }

  @CheckReturnValue
  public static <T, C extends List<T>> ListSubject<? extends ListSubject<?, T, C>, T, C>
      assertThat(List<T> target) {
    return ListSubject.create(getFailureStrategy(), target);
  }

  @CheckReturnValue
  public static <T> ObjectArraySubject<T> assertThat(T[] target) {
    return new ObjectArraySubject<T>(getFailureStrategy(), target);
  }

  @CheckReturnValue
  public static PrimitiveBooleanArraySubject assertThat(boolean[] target) {
    return new PrimitiveBooleanArraySubject(getFailureStrategy(), target);
  }

  @CheckReturnValue
  public static PrimitiveIntArraySubject assertThat(int[] target) {
    return new PrimitiveIntArraySubject(getFailureStrategy(), target);
  }

  @CheckReturnValue
  public static PrimitiveLongArraySubject assertThat(long[] target) {
    return new PrimitiveLongArraySubject(getFailureStrategy(), target);
  }

  @CheckReturnValue
  public static PrimitiveCharArraySubject assertThat(char[] target) {
    return new PrimitiveCharArraySubject(getFailureStrategy(), target);
  }

  @CheckReturnValue
  public static PrimitiveFloatArraySubject assertThat(float[] target) {
    return new PrimitiveFloatArraySubject(getFailureStrategy(), target);
  }

  @CheckReturnValue
  public static PrimitiveDoubleArraySubject assertThat(double[] target) {
    return new PrimitiveDoubleArraySubject(getFailureStrategy(), target);
  }

  @CheckReturnValue
  public static <T> OptionalSubject<T> assertThat(Optional<T> target) {
    return new OptionalSubject<T>(getFailureStrategy(), target);
  }

  @CheckReturnValue
  public static <K, V, M extends Map<K, V>> MapSubject<? extends MapSubject<?, K, V, M>, K, V, M>
      assertThat(Map<K, V> target) {
    return MapSubject.create(getFailureStrategy(), target);
  }

}

@@ -1061,17 +1061,20 @@
 e assert
-_
+That
 () metho
@@ -1197,16 +1197,17 @@
 quals(a,
+ 
 b);%0A * A
@@ -1227,16 +1227,53 @@
 rue(c);%0A
+ * Assert.assertTrue(d.contains(a));%0A
  * Asser
@@ -1313,17 +1313,17 @@
 ontains(
-e
+b
 ));%0A * A
@@ -1367,17 +1367,17 @@
 ontains(
-q
+b
 ) %7C%7C d.c
@@ -1384,17 +1384,17 @@
 ontains(
-z
+c
 ));%0A * %7D
@@ -1448,69 +1448,45 @@
 sert
-_().that(aString).equals(bString);%0A * assert_().that(aBoolean
+That(a).isEqualTo(b);%0A * assertThat(c
 ).is
@@ -1502,35 +1502,22 @@
 * assert
-_().that(collection
+That(d
 ).has().
@@ -1522,22 +1522,16 @@
 ).item(a
-String
 );%0A * as
@@ -1538,59 +1538,32 @@
 sert
-_(
+That(d
 ).
-t
 ha
-t(collection).containsAllOf(aString, bString
+s().allOf(a, b
 );%0A 
@@ -1574,68 +1574,35 @@
 sert
-_(
+That(d
 ).
-t
 ha
-t(collection).containsAnyOf(aString, qString, zString
+s().anyOf(a, b, c
 );%0A 

Update the javadoc to correctly describe collection methods. ------------- Created by MOE: http://code.google.com/p/moe-java MOE_MIGRATED_REVID=71582712