001 /*
002 * Created on Jun 18, 2007
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 @2007-2011 the original author or authors.
014 */
015 package org.fest.assertions;
016
017 import static java.lang.Short.valueOf;
018 import static org.fest.assertions.ErrorMessages.*;
019
020 import org.fest.util.VisibleForTesting;
021
022 /**
023 * Assertions for {@code Short}s and {@code short}s.
024 * <p>
025 * To create a new instance of this class invoke either <code>{@link Assertions#assertThat(Short)}</code>
026 * <code>{@link Assertions#assertThat(short)}</code>.
027 * </p>
028 *
029 * @author Yvonne Wang
030 * @author David DIDIER
031 * @author Ansgar Konermann
032 * @author Alex Ruiz
033 */
034 public class ShortAssert extends GenericAssert<ShortAssert, Short> implements NumberAssert {
035
036 private static final short ZERO = (short) 0;
037
038 @VisibleForTesting
039 ShortAssert(int actual) {
040 this((short)actual);
041 }
042
043 /**
044 * Creates a new <code>{@link ShortAssert}</code>.
045 * @param actual the actual value to verify.
046 */
047 protected ShortAssert(short actual) {
048 super(ShortAssert.class, actual);
049 }
050
051 /**
052 * Creates a new <code>{@link ShortAssert}</code>.
053 * @param actual the actual value to verify.
054 */
055 protected ShortAssert(Short actual) {
056 super(ShortAssert.class, actual);
057 }
058
059 /**
060 * Verifies that the actual {@code Short} is equal to the given one.
061 * @param expected the value to compare the actual one to.
062 * @return this assertion object.
063 * @throws AssertionError if the actual {@code Short} is not equal to the given one.
064 */
065 public ShortAssert isEqualTo(short expected) {
066 return isEqualTo(valueOf(expected));
067 }
068
069 /**
070 * Verifies that the actual {@code Short} is not equal to the given one.
071 * @param other the given value.
072 * @return this assertion object.
073 * @throws AssertionError if the actual {@code Short} is equal to the given one.
074 */
075 public ShortAssert isNotEqualTo(short other) {
076 return isNotEqualTo(valueOf(other));
077 }
078
079 /**
080 * Verifies that the actual {@code Short} is greater than the given one.
081 * @param other the given value.
082 * @return this assertion object.
083 * @throws AssertionError if the actual {@code Short} is not greater than the given one.
084 */
085 public ShortAssert isGreaterThan(short other) {
086 if (actual > other) return this;
087 failIfCustomMessageIsSet();
088 throw failure(unexpectedLessThanOrEqualTo(actual, other));
089 }
090
091 /**
092 * Verifies that the actual {@code Short} is less than the given one.
093 * @param other the given value.
094 * @return this assertion object.
095 * @throws AssertionError if the actual {@code Short} is not less than the given one.
096 */
097 public ShortAssert isLessThan(short other) {
098 if (actual < other) return this;
099 failIfCustomMessageIsSet();
100 throw failure(unexpectedGreaterThanOrEqualTo(actual, other));
101 }
102
103 /**
104 * Verifies that the actual {@code Short} is greater or equal to the given one.
105 * @param other the given value.
106 * @return this assertion object.
107 * @throws AssertionError if the actual {@code Short} is not greater than or equal to the given one.
108 */
109 public ShortAssert isGreaterThanOrEqualTo(short other) {
110 if (actual >= other) return this;
111 failIfCustomMessageIsSet();
112 throw failure(unexpectedLessThan(actual, other));
113 }
114
115 /**
116 * Verifies that the actual {@code Short} is less or equal to the given one.
117 * @param other the given value.
118 * @return this assertion object.
119 * @throws AssertionError if the actual {@code Short} is not less than or equal to the given one.
120 */
121 public ShortAssert isLessThanOrEqualTo(short other) {
122 if (actual <= other) return this;
123 failIfCustomMessageIsSet();
124 throw failure(unexpectedGreaterThan(actual, other));
125 }
126
127 /**
128 * Verifies that the actual {@code Short} is equal to zero.
129 * @return this assertion object.
130 * @throws AssertionError if the actual {@code Short} is not equal to zero.
131 */
132 public ShortAssert isZero() {
133 return isEqualTo(ZERO);
134 }
135
136 /**
137 * Verifies that the actual {@code Short} is positive.
138 * @return this assertion object.
139 * @throws AssertionError if the actual {@code Short} is not positive.
140 */
141 public ShortAssert isPositive() {
142 return isGreaterThan(ZERO);
143 }
144
145 /**
146 * Verifies that the actual {@code Short} is negative.
147 * @return this assertion object.
148 * @throws AssertionError if the actual {@code Short} is not negative.
149 */
150 public ShortAssert isNegative() {
151 return isLessThan(ZERO);
152 }
153 }