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.api; 016 017 import java.util.Comparator; 018 019 import org.fest.assertions.core.NumberAssert; 020 import org.fest.assertions.internal.Longs; 021 import org.fest.util.ComparatorBasedComparisonStrategy; 022 import org.fest.util.VisibleForTesting; 023 024 /** 025 * Assertion methods for longs. 026 * <p> 027 * To create an instance of this class, invoke <code>{@link Assertions#assertThat(Long)}</code> or 028 * <code>{@link Assertions#assertThat(long)}</code>. 029 * </p> 030 * 031 * @author Yvonne Wang 032 * @author David DIDIER 033 * @author Ansgar Konermann 034 * @author Alex Ruiz 035 * @author Joel Costigliola 036 * @author Mikhail Mazursky 037 */ 038 public class LongAssert extends AbstractComparableAssert<LongAssert, Long> implements NumberAssert<Long> { 039 040 @VisibleForTesting Longs longs = Longs.instance(); 041 042 protected LongAssert(Long actual) { 043 super(actual, LongAssert.class); 044 } 045 046 /** 047 * Verifies that the actual value is equal to the given one. 048 * @param expected the given value to compare the actual value to. 049 * @return {@code this} assertion object. 050 * @throws AssertionError if the actual value is {@code null}. 051 * @throws AssertionError if the actual value is not equal to the given one. 052 */ 053 public LongAssert isEqualTo(long expected) { 054 longs.assertEqual(info, actual, expected); 055 return this; 056 } 057 058 /** 059 * Verifies that the actual value is not equal to the given one. 060 * @param other the given value to compare the actual value to. 061 * @return {@code this} assertion object. 062 * @throws AssertionError if the actual value is {@code null}. 063 * @throws AssertionError if the actual value is equal to the given one. 064 */ 065 public LongAssert isNotEqualTo(long other) { 066 longs.assertNotEqual(info, actual, other); 067 return this; 068 } 069 070 /** {@inheritDoc} */ 071 public LongAssert isZero() { 072 longs.assertIsZero(info, actual); 073 return this; 074 } 075 076 /** {@inheritDoc} */ 077 public LongAssert isNotZero() { 078 longs.assertIsNotZero(info, actual); 079 return this; 080 } 081 082 /** {@inheritDoc} */ 083 public LongAssert isPositive() { 084 longs.assertIsPositive(info, actual); 085 return this; 086 } 087 088 /** {@inheritDoc} */ 089 public LongAssert isNegative() { 090 longs.assertIsNegative(info, actual); 091 return this; 092 } 093 094 /** 095 * Verifies that the actual value is less than the given one. 096 * @param other the given value to compare the actual value to. 097 * @return {@code this} assertion object. 098 * @throws AssertionError if the actual value is {@code null}. 099 * @throws AssertionError if the actual value is equal to or greater than the given one. 100 */ 101 public LongAssert isLessThan(long other) { 102 longs.assertLessThan(info, actual, other); 103 return this; 104 } 105 106 /** 107 * Verifies that the actual value is less than or equal to the given one. 108 * @param other the given value to compare the actual value to. 109 * @return {@code this} assertion object. 110 * @throws AssertionError if the actual value is {@code null}. 111 * @throws AssertionError if the actual value is greater than the given one. 112 */ 113 public LongAssert isLessThanOrEqualTo(long other) { 114 longs.assertLessThanOrEqualTo(info, actual, other); 115 return this; 116 } 117 118 /** 119 * Verifies that the actual value is greater than the given one. 120 * @param other the given value to compare the actual value to. 121 * @return {@code this} assertion object. 122 * @throws AssertionError if the actual value is {@code null}. 123 * @throws AssertionError if the actual value is equal to or less than the given one. 124 */ 125 public LongAssert isGreaterThan(long other) { 126 longs.assertGreaterThan(info, actual, other); 127 return this; 128 } 129 130 /** 131 * Verifies that the actual value is greater than or equal to the given one. 132 * @param other the given value to compare the actual value to. 133 * @return {@code this} assertion object. 134 * @throws AssertionError if the actual value is {@code null}. 135 * @throws AssertionError if the actual value is less than the given one. 136 */ 137 public LongAssert isGreaterThanOrEqualTo(long other) { 138 longs.assertGreaterThanOrEqualTo(info, actual, other); 139 return this; 140 } 141 142 @Override 143 public LongAssert usingComparator(Comparator<? super Long> customComparator) { 144 super.usingComparator(customComparator); 145 this.longs = new Longs(new ComparatorBasedComparisonStrategy(customComparator)); 146 return myself; 147 } 148 149 @Override 150 public LongAssert usingDefaultComparator() { 151 super.usingDefaultComparator(); 152 this.longs = Longs.instance(); 153 return myself; 154 } 155 }