001    /*
002     * Created on Feb 8, 2011
003     * 
004     * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
005     * 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 is distributed on
010     * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
011     * specific language governing permissions and limitations under the License.
012     * 
013     * Copyright @2011 the original author or authors.
014     */
015    package org.fest.assertions.api;
016    
017    import java.math.BigDecimal;
018    import java.util.Comparator;
019    
020    import org.fest.assertions.core.NumberAssert;
021    import org.fest.assertions.internal.BigDecimals;
022    import org.fest.util.ComparatorBasedComparisonStrategy;
023    import org.fest.util.VisibleForTesting;
024    
025    /**
026     * Assertion methods for <code>{@link BigDecimal}</code>s.
027     * <p>
028     * To create an instance of this class, invoke <code>{@link Assertions#assertThat(BigDecimal)}</code>.
029     * </p>
030     * 
031     * @author David DIDIER
032     * @author Ted M. Young
033     * @author Yvonne Wang
034     * @author Alex Ruiz
035     * @author Joel Costigliola
036     * @author Mikhail Mazursky
037     */
038    public class BigDecimalAssert extends AbstractUnevenComparableAssert<BigDecimalAssert, BigDecimal> implements
039        NumberAssert<BigDecimal> {
040    
041      @VisibleForTesting
042      BigDecimals bigDecimals = BigDecimals.instance();
043    
044      protected BigDecimalAssert(BigDecimal actual) {
045        super(actual, BigDecimalAssert.class);
046      }
047    
048      /** {@inheritDoc} */
049      public BigDecimalAssert isZero() {
050        bigDecimals.assertIsZero(info, actual);
051        return myself;
052      }
053    
054      /** {@inheritDoc} */
055      public BigDecimalAssert isNotZero() {
056        bigDecimals.assertIsNotZero(info, actual);
057        return myself;
058      }
059    
060      /** {@inheritDoc} */
061      public BigDecimalAssert isPositive() {
062        bigDecimals.assertIsPositive(info, actual);
063        return myself;
064      }
065    
066      /** {@inheritDoc} */
067      public BigDecimalAssert isNegative() {
068        bigDecimals.assertIsNegative(info, actual);
069        return myself;
070      }
071    
072      /**
073       * Same as {@link AbstractAssert#isEqualTo(Object) isEqualTo(BigDecimal)} but takes care of converting given String to
074       * {@link BigDecimal} for you.
075       */
076      public BigDecimalAssert isEqualTo(String expected) {
077        return super.isEqualTo(new BigDecimal(expected));
078      }
079    
080      /**
081       * Same as {@link AbstractUnevenComparableAssert#isEqualByComparingTo(Comparable) isEqualByComparingTo(BigDecimal)}
082       * but takes care of converting given String to {@link BigDecimal} for you.
083       */
084      public BigDecimalAssert isEqualByComparingTo(String expected) {
085        return super.isEqualByComparingTo(new BigDecimal(expected));
086      }
087    
088      @Override
089      public BigDecimalAssert usingComparator(Comparator<? super BigDecimal> customComparator) {
090        super.usingComparator(customComparator);
091        this.bigDecimals = new BigDecimals(new ComparatorBasedComparisonStrategy(customComparator));
092        return myself;
093      }
094    
095      @Override
096      public BigDecimalAssert usingDefaultComparator() {
097        super.usingDefaultComparator();
098        this.bigDecimals = BigDecimals.instance();
099        return myself;
100      }
101    }