/*
 * Copyright (C) 2008 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.testing.junit3;

import static com.google.common.testing.junit3.JUnitAsserts.assertContentsInOrder;
import static com.google.common.testing.junit3.JUnitAsserts.assertNotEqual;

import junit.framework.AssertionFailedError;
import junit.framework.TestCase;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

/**
 * Unit test for {@link JUnitAsserts}.
 *
 * @author kevinb
 */
public class JUnitAssertsTest extends TestCase {

  public void testNotEqualSuccess() {
    assertNotEqual(1, 2);
  }

  public void testNotEqualNullSuccess1() {
    assertNotEqual(null, 2);
  }

  public void testNotEqualNullSuccess2() {
    assertNotEqual(1, null);
  }

  public void testNotEqualFailure() {
    try {
      assertNotEqual(1, 1);
      fail("no exception thrown");
    } catch (AssertionFailedError e) {
      assertEquals("expected not to be:<1>", e.getMessage());
    }
  }

  public void testNotEqualNullFailure() {
    try {
      assertNotEqual(null, null);
      fail("no exception thrown");
    } catch (AssertionFailedError e) {
      assertEquals("failure message generated by MoreAsserts",
          "expected not to be:<null>", e.getMessage());
    }
  }

  public void testMessageReturnedByNotEqualFailure() {
    try {
      assertNotEqual("foo", 1, 1);
      fail("no exception thrown");
    } catch (AssertionFailedError e) {
      assertEquals("failure message generated by MoreAsserts",
          "foo expected not to be:<1>", e.getMessage());
    }
  }

  public void testContentsInOrderSuccess() {
    List<Integer> actual = Arrays.asList(1, 2, 3);
    assertContentsInOrder(actual, 1, 2, 3);
  }

  public void testContentsInOrderEmptySuccess() {
    List<Integer> actual = Collections.emptyList();
    assertContentsInOrder(actual);
  }

  public void testContentsInOrderEmptyFailureEmptyActual() {
    List<Integer> actual = Collections.emptyList();
    try {
      assertContentsInOrder("foo", actual, 1);
      fail("no exception thrown");
    } catch (AssertionFailedError e) {
      assertEquals("failure message generated by MoreAsserts",
          "foo expected:<[1]> but was:<[]>", e.getMessage());
    }
  }

  public void testContentsInOrderEmptyFailureEmptyExpected() {
    List<Integer> actual = Collections.singletonList(1);
    try {
      assertContentsInOrder("foo", actual);
      fail("no exception thrown");
    } catch (AssertionFailedError e) {
      assertEquals("failure message generated by MoreAsserts",
          "foo expected:<[]> but was:<[1]>", e.getMessage());
    }
  }

  public void testContentsInOrderFailureDueToOrder() {
    List<Integer> actual = Arrays.asList(1, 2);
    try {
      assertContentsInOrder("foo", actual, 2, 1);
      fail("no exception thrown");
    } catch (AssertionFailedError e) {
      assertEquals("failure message generated by MoreAsserts",
          "foo expected:<[2, 1]> but was:<[1, 2]>", e.getMessage());
    }
  }
}

@@ -2721,36 +2721,8 @@
 %22foo
- expected:%3C%5B1%5D%3E but was:%3C%5B%5D%3E
 %22, e
@@ -2729,32 +2729,32 @@
 .getMessage());%0A
+
     %7D%0A  %7D%0A%0A  pub
@@ -3077,36 +3077,8 @@
 %22foo
- expected:%3C%5B%5D%3E but was:%3C%5B1%5D%3E
 %22, e
@@ -3433,14 +3433,9 @@
 ed:%3C
-%5B2, 1%5D
+2
 %3E bu
@@ -3445,14 +3445,9 @@
 as:%3C
-%5B1, 2%5D
+1
 %3E%22, 

Fix test assertions to comply with new exception messages