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

org.hamcrest.text.CharSequenceLength Maven / Gradle / Ivy

The newest version!
package org.hamcrest.text;

import org.hamcrest.FeatureMatcher;
import org.hamcrest.Matcher;

import static org.hamcrest.CoreMatchers.equalTo;

/**
 * @author Marco Leichsenring
 * @author Steve Freeman
 */
public class CharSequenceLength extends FeatureMatcher {

    /**
     * @param lengthMatcher         The matcher to apply to the feature
     */
    @SuppressWarnings("WeakerAccess")
    public CharSequenceLength(Matcher lengthMatcher) {
        super(lengthMatcher, "a CharSequence with length", "length");
    }

    @Override
    protected Integer featureValueOf(CharSequence actual) {
        return actual.length();
    }

    /**
     * Creates a matcher of {@link CharSequence} that matches when a char sequence has the given length
     * For example:
     *
     * 
     * assertThat("text", hasLength(4))
     * 
* * @param length the expected length of the string * @return The matcher. */ public static Matcher hasLength(int length) { return new CharSequenceLength(equalTo(length)); } /** * Creates a matcher of {@link CharSequence} that matches when a char sequence has the given length * For example: * *
      * assertThat("text", hasLength(lessThan(4)))
      * 
* * @param lengthMatcher the expected length of the string * @return The matcher. */ @SuppressWarnings("WeakerAccess") public static Matcher hasLength(Matcher lengthMatcher) { return new CharSequenceLength(lengthMatcher); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy