001 /*
002 * Created on Dec 27, 2006
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
005 * in compliance with the License. You may obtain a copy of the License at
006 *
007 * http://www.apache.org/licenses/LICENSE-2.0
008 *
009 * Unless required by applicable law or agreed to in writing, software distributed under the License
010 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
011 * or implied. See the License for the specific language governing permissions and limitations under
012 * the License.
013 *
014 * Copyright @2006-2011 the original author or authors.
015 */
016 package org.fest.assertions;
017
018 import static java.math.BigDecimal.ZERO;
019
020 import java.math.BigDecimal;
021
022 /**
023 * Assertions for <code>{@link BigDecimal}</code>s.
024 * <p>
025 * To create a new instance of this class invoke <code>{@link Assertions#assertThat(BigDecimal)}</code>.
026 * </p>
027 *
028 * @author David DIDIER
029 * @author Ted M. Young
030 * @author Yvonne Wang
031 * @author Alex Ruiz
032 */
033 public class BigDecimalAssert extends ComparableAssert<BigDecimalAssert, BigDecimal> implements NumberAssert {
034
035 /**
036 * Creates a new </code>{@link BigDecimalAssert}</code>.
037 * @param actual the target to verify.
038 */
039 protected BigDecimalAssert(BigDecimal actual) {
040 super(BigDecimalAssert.class, actual);
041 }
042
043 /**
044 * Verifies that the actual <code>{@link BigDecimal}</code> is positive.
045 * @return this assertion object.
046 * @throws AssertionError if the actual <code>BigDecimal</code> value is {@code null}.
047 * @throws AssertionError if the actual <code>BigDecimal</code> value is not positive.
048 */
049 public BigDecimalAssert isPositive() {
050 return isGreaterThan(ZERO);
051 }
052
053 /**
054 * Verifies that the actual <code>{@link BigDecimal}</code> is negative.
055 * @return this assertion object.
056 * @throws AssertionError if the actual <code>BigDecimal</code> value is {@code null}.
057 * @throws AssertionError if the actual <code>BigDecimal</code> value is not negative.
058 */
059 public BigDecimalAssert isNegative() {
060 return isLessThan(ZERO);
061 }
062
063 /**
064 * Verifies that the actual <code>{@link BigDecimal}</code> is equal to zero, regardless of precision.
065 * Essentially, this is the same as
066 * <code>{@link #isEqualByComparingTo(BigDecimal) isEqualByComparingTo}</code>(<code>{@link BigDecimal#ZERO BigDecimal.ZERO}</code>).
067 * @return this assertion object.
068 * @throws AssertionError if the actual <code>BigDecimal</code> value is {@code null}.
069 * @throws AssertionError if the actual <code>BigDecimal</code> value is not equal to zero.
070 */
071 public BigDecimalAssert isZero() {
072 return isEqualByComparingTo(ZERO);
073 }
074
075 /**
076 * Verifies that the actual <code>{@link BigDecimal}</code> is not equal to zero, regardless of precision.
077 * Essentially, this is the same as
078 * <code>{@link #isEqualByComparingTo(BigDecimal) isNotEqualByComparingTo}</code>(<code>{@link BigDecimal#ZERO BigDecimal.ZERO}</code>).
079 * @return this assertion object.
080 * @throws AssertionError if the actual <code>BigDecimal</code> is {@code null}.
081 * @throws AssertionError if the actual <code>BigDecimal</code> is equal to zero.
082 */
083 public BigDecimalAssert isNotZero() {
084 return isNotEqualByComparingTo(ZERO);
085 }
086 }