001    /*
002     * Created on Oct 20, 2010
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 @2010-2011 the original author or authors.
014     */
015    package org.fest.assertions.internal;
016    
017    import org.fest.assertions.core.AssertionInfo;
018    import org.fest.util.ComparisonStrategy;
019    
020    /**
021     * Base class of reusable assertions for numbers.
022     * 
023     * @author Joel Costigliola
024     * @author Nicolas François
025     */
026    public abstract class Numbers<NUMBER extends Comparable<NUMBER>> extends Comparables {
027    
028      public Numbers() {
029        super();
030      }
031    
032      public Numbers(ComparisonStrategy comparisonStrategy) {
033        super(comparisonStrategy);
034      }
035    
036      protected abstract NUMBER zero();
037    
038      /**
039       * Asserts that the actual value is equal to zero.<br>
040       * It does not rely on the custom comparisonStrategy (if one is set).
041       * @param info contains information about the assertion.
042       * @param actual the actual value.
043       * @throws AssertionError if the actual value is {@code null}.
044       * @throws AssertionError if the actual value is not equal to zero.
045       */
046      public void assertIsZero(AssertionInfo info, NUMBER actual) {
047        assertEqualByComparison(info, actual, zero());
048      }
049    
050      /**
051       * Asserts that the actual value is not equal to zero.<br>
052       * It does not rely on the custom comparisonStrategy (if one is set).
053       * @param info contains information about the assertion.
054       * @param actual the actual value.
055       * @throws AssertionError if the actual value is {@code null}.
056       * @throws AssertionError if the actual value is equal to zero.
057       */
058      public void assertIsNotZero(AssertionInfo info, NUMBER actual) {
059        assertNotEqualByComparison(info, actual, zero());
060      }
061    
062      /**
063       * Asserts that the actual value is negative.
064       * @param info contains information about the assertion.
065       * @param actual the actual value.
066       * @throws AssertionError if the actual value is {@code null}.
067       * @throws AssertionError if the actual value is not negative: it is either equal to or greater than zero.
068       */
069      public void assertIsNegative(AssertionInfo info, NUMBER actual) {
070        assertLessThan(info, actual, zero());
071      }
072    
073      /**
074       * Asserts that the actual value is positive.
075       * @param info contains information about the assertion.
076       * @param actual the actual value.
077       * @throws AssertionError if the actual value is {@code null}.
078       * @throws AssertionError if the actual value is not positive: it is either equal to or less than zero.
079       */
080      public void assertIsPositive(AssertionInfo info, NUMBER actual) {
081        assertGreaterThan(info, actual, zero());
082      }
083      
084      /**
085       * Asserts that the actual value is not negative.
086       * @param info contains information about the assertion.
087       * @param actual the actual value.
088       * @throws AssertionError if the actual value is {@code null}.
089       * @throws AssertionError if the actual value is negative.
090       */  
091      public void assertIsNotNegative(AssertionInfo info, NUMBER actual) {
092        assertGreaterThanOrEqualTo(info, actual, zero());
093      }
094      
095      /**
096       * Asserts that the actual value is not positive.
097       * @param info contains information about the assertion.
098       * @param actual the actual value.
099       * @throws AssertionError if the actual value is {@code null}.
100       * @throws AssertionError if the actual value is positive.
101       */  
102      public void assertIsNotPositive(AssertionInfo info, NUMBER actual) {
103        assertLessThanOrEqualTo(info, actual, zero());
104      }
105    
106    }