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