001 /*
002 * Created on Oct 21, 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.Bytes;
021 import org.fest.util.ComparatorBasedComparisonStrategy;
022 import org.fest.util.VisibleForTesting;
023
024 /**
025 * Assertion methods for bytes.
026 * <p>
027 * To create an instance of this class, invoke <code>{@link Assertions#assertThat(Byte)}</code> or
028 * <code>{@link Assertions#assertThat(byte)}</code>.
029 * </p>
030 *
031 * @author Yvonne Wang
032 * @author David DIDIER
033 * @author Ansgar Konermann
034 * @author Alex Ruiz
035 * @author Mikhail Mazursky
036 * @author Nicolas François
037 */
038 public class ByteAssert extends AbstractComparableAssert<ByteAssert, Byte> implements NumberAssert<Byte> {
039
040 @VisibleForTesting Bytes bytes = Bytes.instance();
041
042 protected ByteAssert(Byte actual) {
043 super(actual, ByteAssert.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 ByteAssert isEqualTo(byte expected) {
054 bytes.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 ByteAssert isNotEqualTo(byte other) {
066 bytes.assertNotEqual(info, actual, other);
067 return this;
068 }
069
070 /** {@inheritDoc} */
071 public ByteAssert isZero() {
072 bytes.assertIsZero(info, actual);
073 return this;
074 }
075
076 /** {@inheritDoc} */
077 public ByteAssert isNotZero() {
078 bytes.assertIsNotZero(info, actual);
079 return this;
080 }
081
082 /** {@inheritDoc} */
083 public ByteAssert isPositive() {
084 bytes.assertIsPositive(info, actual);
085 return this;
086 }
087
088 /** {@inheritDoc} */
089 public ByteAssert isNegative() {
090 bytes.assertIsNegative(info, actual);
091 return this;
092 }
093
094 /** {@inheritDoc} */
095 public ByteAssert isNotNegative(){
096 bytes.assertIsNotNegative(info, actual);
097 return this;
098 }
099
100 /** {@inheritDoc} */
101 public ByteAssert isNotPositive(){
102 bytes.assertIsNotPositive(info, actual);
103 return this;
104 }
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 ByteAssert isLessThan(byte other) {
115 bytes.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 ByteAssert isLessThanOrEqualTo(byte other) {
127 bytes.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 ByteAssert isGreaterThan(byte other) {
139 bytes.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 ByteAssert isGreaterThanOrEqualTo(byte other) {
151 bytes.assertGreaterThanOrEqualTo(info, actual, other);
152 return this;
153 }
154
155 @Override
156 public ByteAssert usingComparator(Comparator<? super Byte> customComparator) {
157 super.usingComparator(customComparator);
158 this.bytes = new Bytes(new ComparatorBasedComparisonStrategy(customComparator));
159 return myself;
160 }
161
162 @Override
163 public ByteAssert usingDefaultComparator() {
164 super.usingDefaultComparator();
165 this.bytes = Bytes.instance();
166 return myself;
167 }
168 }