All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.googlecode.gwt.test.assertions.BaseValueBoxAssert Maven / Gradle / Ivy

There is a newer version: 0.63
Show newest version
package com.googlecode.gwt.test.assertions;

import com.google.gwt.user.client.ui.ValueBox;

import static org.assertj.core.util.Objects.areEqual;

/**
 * Base class for {@link ValueBox} assertions.
 *
 * @param  used to simulate "self types." For more information please read "Emulating 'self types' using Java Generics to simplify fluent API
 *            implementation."
 * @param  the type of the "actual" value.
 * @param  the type of the ValueBox value.
 * @author Gael Lazzari
 */
public class BaseValueBoxAssert, A extends ValueBox, T>
        extends BaseValueBoxBaseAssert {

    /**
     * Creates a new {@link BaseValueBoxBaseAssert}.
     *
     * @param actual   the actual value to verify.
     * @param selfType the "self type."
     */
    protected BaseValueBoxAssert(A actual, Class selfType) {
        super(actual, selfType);
    }

    /**
     * Verifies that the actual {@link ValueBox} max length is equal to the given one.
     *
     * @param expected the given max length to compare the actual value to.
     * @return this assertion object.
     * @throws AssertionError if the actual max length is not equal to the given one.
     * @see ValueBox#getMaxLength()
     */
    public S maxLengthEquals(int expected) {
        int length = actual.getMaxLength();
        if (areEqual(length, expected))
            return myself;
        throw propertyComparisonFailed("max length", length, expected);
    }

    /**
     * Verifies that the actual {@link ValueBox} visible length is equal to the given one.
     *
     * @param expected the given visible length to compare the actual value to.
     * @return this assertion object.
     * @throws AssertionError if the actual visible length is not equal to the given one.
     * @see ValueBox#getVisibleLength()
     */
    public S visibleLengthEquals(int expected) {
        int length = actual.getVisibleLength();
        if (areEqual(length, expected))
            return myself;
        throw propertyComparisonFailed("visible length", length, expected);
    }

}