/*
 * 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.gwt;

import static com.google.common.truth.Truth.ASSERT;
import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth.assert_;
import static java.util.Arrays.asList;

import com.google.common.truth.Platform;
import com.google.gwt.junit.client.GWTTestCase;

import java.util.AbstractList;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;

/**
 * Test of Truth under GWT - should be enough tests here to force compilation
 * of all Subject implementations.
 *
 * @author Christian Gruber (cgruber@israfil.net)
 */
public class TruthGwtTest extends GWTTestCase {

  @Override public String getModuleName() {
    return "com.google.common.truth.gwt.TruthTest";
  }

  public void testBuildClasses() {
    new Inventory().toString(); // force invocation.
  }

  public void testBoolean() {
    assertThat(true).isTrue();
    assertThat(false).isFalse();
  }

  public void testInteger() {
    assertThat(457923).is(457923);
    try {
      assertThat(457923).is(1);
      assert_().fail("Should have thrown an exception");
    } catch (Throwable t) {
      // succeeds
    }
  }

  public void testString() {
    assertThat("blah").contains("ah");
    assertThat("blah").startsWith("bl");
    assertThat("blah").endsWith("ah");
    try {
      assertThat("blah").contains("foo");
      assert_().fail("Should have thrown an exception");
    } catch (Throwable t) {
      // succeeds
    }
  }

  public void testIterable() {
    assertThat((Iterable<Integer>)asList(1, 2, 3)).containsExactly(1, 2, 3).inOrder();
  }

  public void testCollection() {
    assertThat((Collection<Integer>)asList(1, 2, 3)).containsExactly(1, 2, 3).inOrder();
  }

  public void testList() {
    assertThat(asList(1, 2, 3)).containsExactly(1, 2, 3).inOrder();
  }

  public void testObjectArray() {
    Set[] setOfString = { new HashSet<String>(asList("foo", "bar", "bash")) };
    assertThat(setOfString).asList()
        .contains(new HashSet<String>(asList("foo", "bar", "bash")));
  }

  public void testDefault() {
    assertThat(new Object()).isNotNull();
    assertThat(new ArrayList<String>()).isInstanceOf(AbstractList.class);
  }

  public void testLegacyASSERT() {
    ASSERT.that(new Object()).isNotNull();
    ASSERT.that(new ArrayList<String>()).isInstanceOf(AbstractList.class);
  }

  public void testLegacyAssert_() {
    assert_().that(new Object()).isNotNull();
    assert_().that(new ArrayList<String>()).isInstanceOf(AbstractList.class);
  }

  public void testInvokePlatformMethods() {
    Platform.isInstanceOfType(new Object(), Object.class);
  }
}

@@ -631,60 +631,8 @@
 t;%0A%0A
-import static com.google.common.truth.Truth.ASSERT;%0A
 impo
@@ -1626,24 +1626,77 @@
 .is(1);%0A    
+%7D catch (Throwable expected) %7B%0A      return;%0A    %7D%0A  
   assert_().
@@ -1739,60 +1739,8 @@
 n%22);
-%0A    %7D catch (Throwable t) %7B%0A      // succeeds%0A    %7D
 %0A  %7D
@@ -1941,24 +1941,77 @@
 %22foo%22);%0A    
+%7D catch (Throwable expected) %7B%0A      return;%0A    %7D%0A  
   assert_().
@@ -2054,60 +2054,8 @@
 n%22);
-%0A    %7D catch (Throwable t) %7B%0A      // succeeds%0A    %7D
 %0A  %7D
@@ -2786,166 +2786,8 @@
  %7D%0A%0A
-  public void testLegacyASSERT() %7B%0A    ASSERT.that(new Object()).isNotNull();%0A    ASSERT.that(new ArrayList%3CString%3E()).isInstanceOf(AbstractList.class);%0A  %7D%0A%0A
   pu

Change try, catch Throwable, fail pattern to try, catch, return, fail pattern. Remove legacy ASSERT.that() calls (it won't compile internally anyways). ------------- Created by MOE: http://code.google.com/p/moe-java MOE_MIGRATED_REVID=82353785