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 */ 036 public class ByteAssert extends AbstractComparableAssert<ByteAssert, Byte> implements NumberAssert<Byte> { 037 038 @VisibleForTesting Bytes bytes = Bytes.instance(); 039 040 protected ByteAssert(Byte actual) { 041 super(actual, ByteAssert.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 ByteAssert isEqualTo(byte expected) { 052 bytes.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 ByteAssert isNotEqualTo(byte other) { 064 bytes.assertNotEqual(info, actual, other); 065 return this; 066 } 067 068 /** {@inheritDoc} */ 069 public ByteAssert isZero() { 070 bytes.assertIsZero(info, actual); 071 return this; 072 } 073 074 /** {@inheritDoc} */ 075 public ByteAssert isNotZero() { 076 bytes.assertIsNotZero(info, actual); 077 return this; 078 } 079 080 /** {@inheritDoc} */ 081 public ByteAssert isPositive() { 082 bytes.assertIsPositive(info, actual); 083 return this; 084 } 085 086 /** {@inheritDoc} */ 087 public ByteAssert isNegative() { 088 bytes.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 ByteAssert isLessThan(byte other) { 100 bytes.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 ByteAssert isLessThanOrEqualTo(byte other) { 112 bytes.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 ByteAssert isGreaterThan(byte other) { 124 bytes.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 ByteAssert isGreaterThanOrEqualTo(byte other) { 136 bytes.assertGreaterThanOrEqualTo(info, actual, other); 137 return this; 138 } 139 140 @Override 141 public ByteAssert usingComparator(Comparator<?> customComparator) { 142 super.usingComparator(customComparator); 143 this.bytes = new Bytes(new ComparatorBasedComparisonStrategy(customComparator)); 144 return myself; 145 } 146 147 @Override 148 public ByteAssert usingDefaultComparator() { 149 super.usingDefaultComparator(); 150 this.bytes = Bytes.instance(); 151 return myself; 152 } 153 }