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     */
025    public abstract class Numbers<NUMBER extends Comparable<NUMBER>> extends Comparables {
026    
027      public Numbers() {
028        super();
029      }
030    
031      public Numbers(ComparisonStrategy comparisonStrategy) {
032        super(comparisonStrategy);
033      }
034    
035      protected abstract NUMBER zero();
036    
037      /**
038       * Asserts that the actual value is equal to zero.<br>
039       * It does not rely on the custom comparisonStrategy (if one is set).
040       * @param info contains information about the assertion.
041       * @param actual the actual value.
042       * @throws AssertionError if the actual value is {@code null}.
043       * @throws AssertionError if the actual value is not equal to zero.
044       */
045      public void assertIsZero(AssertionInfo info, NUMBER actual) {
046        assertEqualByComparison(info, actual, zero());
047      }
048    
049      /**
050       * Asserts that the actual value is not equal to zero.<br>
051       * It does not rely on the custom comparisonStrategy (if one is set).
052       * @param info contains information about the assertion.
053       * @param actual the actual value.
054       * @throws AssertionError if the actual value is {@code null}.
055       * @throws AssertionError if the actual value is equal to zero.
056       */
057      public void assertIsNotZero(AssertionInfo info, NUMBER actual) {
058        assertNotEqualByComparison(info, actual, zero());
059      }
060    
061      /**
062       * Asserts that the actual value is negative.
063       * @param info contains information about the assertion.
064       * @param actual the actual value.
065       * @throws AssertionError if the actual value is {@code null}.
066       * @throws AssertionError if the actual value is not negative: it is either equal to or greater than zero.
067       */
068      public void assertIsNegative(AssertionInfo info, NUMBER actual) {
069        assertLessThan(info, actual, zero());
070      }
071    
072      /**
073       * Asserts that the actual value is positive.
074       * @param info contains information about the assertion.
075       * @param actual the actual value.
076       * @throws AssertionError if the actual value is {@code null}.
077       * @throws AssertionError if the actual value is not positive: it is either equal to or less than zero.
078       */
079      public void assertIsPositive(AssertionInfo info, NUMBER actual) {
080        assertGreaterThan(info, actual, zero());
081      }
082    
083    }