ru.d_shap.assertions.asimp.primitive.ShortAssertion Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of assertions Show documentation
Show all versions of assertions Show documentation
Assertions library provides facilities for the unit testing
///////////////////////////////////////////////////////////////////////////////////////////////////
// Assertions library provides facilities for the unit testing.
// Copyright (C) 2017 Dmitry Shapovalov.
//
// This file is part of assertions library.
//
// Assertions library is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Assertions library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see .
///////////////////////////////////////////////////////////////////////////////////////////////////
package ru.d_shap.assertions.asimp.primitive;
import org.hamcrest.Matcher;
import ru.d_shap.assertions.Messages;
import ru.d_shap.assertions.Raw;
import ru.d_shap.assertions.asimp.HexString;
import ru.d_shap.assertions.asimp.ReferenceAssertion;
import ru.d_shap.assertions.asimp.java.lang.CharSequenceAssertion;
/**
* Assertions for the short.
*
* @author Dmitry Shapovalov
*/
public class ShortAssertion extends ReferenceAssertion {
/**
* Create new object.
*/
public ShortAssertion() {
super();
}
@Override
protected final Class getActualValueClass() {
return Short.class;
}
/**
* Check if the actual value is equal to the expected value.
*
* @param expected the expected value.
*/
public final void isEqualTo(final int expected) {
checkActualIsNotNull();
if (getActual() != expected) {
throw getAssertionErrorBuilder().addMessage(Messages.Fail.Actual.IS_SAME).addActual().addExpected(expected).build();
}
}
/**
* Check if the actual value is equal to the expected value.
*
* @param expected the expected value.
*/
public final void isEqualTo(final Short expected) {
if (expected == null) {
isNull();
} else {
isEqualTo(expected.shortValue());
}
}
/**
* Check if the actual value is NOT equal to the expected value.
*
* @param expected the expected value.
*/
public final void isNotEqualTo(final int expected) {
if (getActual() != null && getActual() == expected) {
throw getAssertionErrorBuilder().addMessage(Messages.Fail.Actual.IS_DIFFERENT).addActual().build();
}
}
/**
* Check if the actual value is NOT equal to the expected value.
*
* @param expected the expected value.
*/
public final void isNotEqualTo(final Short expected) {
if (expected == null) {
isNotNull();
} else {
isNotEqualTo(expected.shortValue());
}
}
/**
* Check if the actual value is greater than the expected value.
*
* @param expected the expected value.
*/
public final void isGreaterThan(final int expected) {
checkActualIsNotNull();
if (getActual() <= expected) {
throw getAssertionErrorBuilder().addMessage(Messages.Fail.Actual.IS_GREATER).addActual().addExpected(expected).build();
}
}
/**
* Check if the actual value is greater than the expected value.
*
* @param expected the expected value.
*/
public final void isGreaterThan(final Short expected) {
checkActualIsNotNull();
checkArgumentIsNotNull(expected, "expected");
isGreaterThan(expected.shortValue());
}
/**
* Check if the actual value is greater than or equal to the expected value.
*
* @param expected the expected value.
*/
public final void isGreaterThanOrEqualTo(final int expected) {
checkActualIsNotNull();
if (getActual() < expected) {
throw getAssertionErrorBuilder().addMessage(Messages.Fail.Actual.IS_GREATER_OR_EQUAL).addActual().addExpected(expected).build();
}
}
/**
* Check if the actual value is greater than or equal to the expected value.
*
* @param expected the expected value.
*/
public final void isGreaterThanOrEqualTo(final Short expected) {
checkActualIsNotNull();
checkArgumentIsNotNull(expected, "expected");
isGreaterThanOrEqualTo(expected.shortValue());
}
/**
* Check if the actual value is less than the expected value.
*
* @param expected the expected value.
*/
public final void isLessThan(final int expected) {
checkActualIsNotNull();
if (getActual() >= expected) {
throw getAssertionErrorBuilder().addMessage(Messages.Fail.Actual.IS_LESS).addActual().addExpected(expected).build();
}
}
/**
* Check if the actual value is less than the expected value.
*
* @param expected the expected value.
*/
public final void isLessThan(final Short expected) {
checkActualIsNotNull();
checkArgumentIsNotNull(expected, "expected");
isLessThan(expected.shortValue());
}
/**
* Check if the actual value is less than or equal to the expected value.
*
* @param expected the expected value.
*/
public final void isLessThanOrEqualTo(final int expected) {
checkActualIsNotNull();
if (getActual() > expected) {
throw getAssertionErrorBuilder().addMessage(Messages.Fail.Actual.IS_LESS_OR_EQUAL).addActual().addExpected(expected).build();
}
}
/**
* Check if the actual value is less than or equal to the expected value.
*
* @param expected the expected value.
*/
public final void isLessThanOrEqualTo(final Short expected) {
checkActualIsNotNull();
checkArgumentIsNotNull(expected, "expected");
isLessThanOrEqualTo(expected.shortValue());
}
/**
* Check if the actual value is in the expected range.
*
* @param expectedFrom the expected lower (inclusive) bound of the range.
* @param expectedTo the expected upper (exclusive) bound of the range.
*/
public final void isInRange(final int expectedFrom, final int expectedTo) {
checkActualIsNotNull();
if (getActual() < expectedFrom || getActual() >= expectedTo) {
throw getAssertionErrorBuilder().addMessage(Messages.Fail.Actual.IS_IN_RANGE).addActual().addExpected(expectedFrom, expectedTo).build();
}
}
/**
* Check if the actual value is in the expected range.
*
* @param expectedFrom the expected lower (inclusive) bound of the range.
* @param expectedTo the expected upper (exclusive) bound of the range.
*/
public final void isInRange(final Short expectedFrom, final Short expectedTo) {
checkActualIsNotNull();
checkArgumentIsNotNull(expectedFrom, "expectedFrom");
checkArgumentIsNotNull(expectedTo, "expectedTo");
isInRange(expectedFrom.shortValue(), expectedTo.shortValue());
}
/**
* Check if the actual value is NOT in the expected range.
*
* @param expectedFrom the expected lower (inclusive) bound of the range.
* @param expectedTo the expected upper (exclusive) bound of the range.
*/
public final void isNotInRange(final int expectedFrom, final int expectedTo) {
checkActualIsNotNull();
if (getActual() >= expectedFrom && getActual() < expectedTo) {
throw getAssertionErrorBuilder().addMessage(Messages.Fail.Actual.IS_NOT_IN_RANGE).addActual().addExpected(expectedFrom, expectedTo).build();
}
}
/**
* Check if the actual value is NOT in the expected range.
*
* @param expectedFrom the expected lower (inclusive) bound of the range.
* @param expectedTo the expected upper (exclusive) bound of the range.
*/
public final void isNotInRange(final Short expectedFrom, final Short expectedTo) {
checkActualIsNotNull();
checkArgumentIsNotNull(expectedFrom, "expectedFrom");
checkArgumentIsNotNull(expectedTo, "expectedTo");
isNotInRange(expectedFrom.shortValue(), expectedTo.shortValue());
}
/**
* Make assertion about the actual value's hex representation.
*
* @return the assertion.
*/
public final CharSequenceAssertion toHexString() {
checkActualIsNotNull();
HexString hexString = convertValue(getActual(), null, HexString.class);
return initializeAssertion(Raw.charSequenceAssertion(), hexString.toString(), Messages.Check.HEX_REPRESENTATION);
}
/**
* Make assertion about the actual value's hex representation.
*
* @param matcher the hamcrest matcher.
*/
public final void toHexString(final Matcher super String> matcher) {
checkActualIsNotNull();
checkArgumentIsNotNull(matcher, "matcher");
HexString hexString = convertValue(getActual(), null, HexString.class);
matcherAssertion(hexString.toString(), matcher, Messages.Check.HEX_REPRESENTATION);
}
/**
* Check if the actual value's hex representation is equal to the expected value.
*
* @param expected the expected value.
*/
public final void hasHexString(final String expected) {
checkActualIsNotNull();
checkArgumentIsNotNull(expected, "expected");
toHexString().isEqualTo(expected);
}
}