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 * @author Nicolas François 038 */ 039 public class LongAssert extends AbstractComparableAssert<LongAssert, Long> implements NumberAssert<Long> { 040 041 @VisibleForTesting Longs longs = Longs.instance(); 042 043 protected LongAssert(Long actual) { 044 super(actual, LongAssert.class); 045 } 046 047 /** 048 * Verifies that the actual value is equal to the given one. 049 * @param expected the given value to compare the actual value to. 050 * @return {@code this} assertion object. 051 * @throws AssertionError if the actual value is {@code null}. 052 * @throws AssertionError if the actual value is not equal to the given one. 053 */ 054 public LongAssert isEqualTo(long expected) { 055 longs.assertEqual(info, actual, expected); 056 return this; 057 } 058 059 /** 060 * Verifies that the actual value is not equal to the given one. 061 * @param other the given value to compare the actual value to. 062 * @return {@code this} assertion object. 063 * @throws AssertionError if the actual value is {@code null}. 064 * @throws AssertionError if the actual value is equal to the given one. 065 */ 066 public LongAssert isNotEqualTo(long other) { 067 longs.assertNotEqual(info, actual, other); 068 return this; 069 } 070 071 /** {@inheritDoc} */ 072 public LongAssert isZero() { 073 longs.assertIsZero(info, actual); 074 return this; 075 } 076 077 /** {@inheritDoc} */ 078 public LongAssert isNotZero() { 079 longs.assertIsNotZero(info, actual); 080 return this; 081 } 082 083 /** {@inheritDoc} */ 084 public LongAssert isPositive() { 085 longs.assertIsPositive(info, actual); 086 return this; 087 } 088 089 /** {@inheritDoc} */ 090 public LongAssert isNegative() { 091 longs.assertIsNegative(info, actual); 092 return this; 093 } 094 095 /** {@inheritDoc} */ 096 public LongAssert isNotNegative() { 097 longs.assertIsNotNegative(info, actual); 098 return this; 099 } 100 101 /** {@inheritDoc} */ 102 public LongAssert isNotPositive() { 103 longs.assertIsNotPositive(info, actual); 104 return this; 105 } 106 107 /** 108 * Verifies that the actual value is less than the given one. 109 * @param other the given value to compare the actual value to. 110 * @return {@code this} assertion object. 111 * @throws AssertionError if the actual value is {@code null}. 112 * @throws AssertionError if the actual value is equal to or greater than the given one. 113 */ 114 public LongAssert isLessThan(long other) { 115 longs.assertLessThan(info, actual, other); 116 return this; 117 } 118 119 /** 120 * Verifies that the actual value is less than or equal to the given one. 121 * @param other the given value to compare the actual value to. 122 * @return {@code this} assertion object. 123 * @throws AssertionError if the actual value is {@code null}. 124 * @throws AssertionError if the actual value is greater than the given one. 125 */ 126 public LongAssert isLessThanOrEqualTo(long other) { 127 longs.assertLessThanOrEqualTo(info, actual, other); 128 return this; 129 } 130 131 /** 132 * Verifies that the actual value is greater than the given one. 133 * @param other the given value to compare the actual value to. 134 * @return {@code this} assertion object. 135 * @throws AssertionError if the actual value is {@code null}. 136 * @throws AssertionError if the actual value is equal to or less than the given one. 137 */ 138 public LongAssert isGreaterThan(long other) { 139 longs.assertGreaterThan(info, actual, other); 140 return this; 141 } 142 143 /** 144 * Verifies that the actual value is greater than or equal to the given one. 145 * @param other the given value to compare the actual value to. 146 * @return {@code this} assertion object. 147 * @throws AssertionError if the actual value is {@code null}. 148 * @throws AssertionError if the actual value is less than the given one. 149 */ 150 public LongAssert isGreaterThanOrEqualTo(long other) { 151 longs.assertGreaterThanOrEqualTo(info, actual, other); 152 return this; 153 } 154 155 @Override 156 public LongAssert usingComparator(Comparator<? super Long> customComparator) { 157 super.usingComparator(customComparator); 158 this.longs = new Longs(new ComparatorBasedComparisonStrategy(customComparator)); 159 return myself; 160 } 161 162 @Override 163 public LongAssert usingDefaultComparator() { 164 super.usingDefaultComparator(); 165 this.longs = Longs.instance(); 166 return myself; 167 } 168 }