
package org.fest.assertions.api;

import static org.fest.test.ExpectedException.none;

import java.math.BigDecimal;

import org.fest.assertions.description.Description;
import org.fest.assertions.internal.TestDescription;
import org.fest.test.ExpectedException;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;

/**
 * Tests for {@link BigDecimalAssert#isEqualTo(String)}.
 *
 * @author Yvonne Wang
 */
public class BigDecimalAssert_isEqualTo_Test {
  @Rule
  public ExpectedException thrown = none();

  private BigDecimalAssert assertions;
  private BigDecimal actual = new BigDecimal(8);
  private final Description description = new TestDescription("testing");

  @Before
  public void setUp() {
    assertions = new BigDecimalAssert(actual, description);
  }

  @Test
  public void should_return_this_if_actual_is_equal_to_expected() {
    BigDecimalAssert returned = assertions.isEqualTo(actual);
    Assert.assertSame(returned, assertions);
  }

  @Test
  public void should_pass_if_actual_is_equal_to_expected() {
    assertions.isEqualTo(actual);
  }

  @Test
  public void should_pass_if_actual_is_equal_to_expected_with_different_scale() {
    assertions.isEqualTo(new BigDecimal(8.00));
  }

  @Test
  public void should_fail_if_actual_is_null() {
    thrown.expect(AssertionError.class);
    actual = null;
    assertions = new BigDecimalAssert(actual);
    assertions.isEqualTo(actual);
  }

  @Test
  public void should_fail_if_expected_is_null() {
    thrown.expect(NullPointerException.class);
    BigDecimal expected = null;
    assertions.isEqualTo(expected);
  }

  @Test
  public void should_fail_if_actual_is_not_equal_to_expected() {
    thrown.expect(AssertionError.class);
    assertions.isEqualTo(new BigDecimal(2));
  }
}
