001    /*
002     * Created on Oct 23, 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.internal.Characters;
020    import org.fest.util.ComparatorBasedComparisonStrategy;
021    import org.fest.util.VisibleForTesting;
022    
023    /**
024     * Assertion methods for characters.
025     * <p>
026     * To create an instance of this class, invoke <code>{@link Assertions#assertThat(Character)}</code> or
027     * <code>{@link Assertions#assertThat(char)}</code>.
028     * </p>
029     *
030     * @author Yvonne Wang
031     * @author David DIDIER
032     * @author Ansgar Konermann
033     * @author Alex Ruiz
034     * @author Joel Costigliola
035     */
036    public class CharacterAssert extends AbstractComparableAssert<CharacterAssert, Character> {
037    
038      @VisibleForTesting Characters characters = Characters.instance();
039    
040      protected CharacterAssert(Character actual) {
041        super(actual, CharacterAssert.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 CharacterAssert isEqualTo(char expected) {
052        characters.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 CharacterAssert isNotEqualTo(char other) {
064        characters.assertNotEqual(info, actual, other);
065        return this;
066      }
067    
068      /**
069       * Verifies that the actual value is less than the given one.
070       * @param other the given value to compare the actual value to.
071       * @return {@code this} assertion object.
072       * @throws AssertionError if the actual value is {@code null}.
073       * @throws AssertionError if the actual value is equal to or greater than the given one.
074       */
075      public CharacterAssert isLessThan(char other) {
076        characters.assertLessThan(info, actual, other);
077        return this;
078      }
079    
080      /**
081       * Verifies that the actual value is less than or equal to the given one.
082       * @param other the given value to compare the actual value to.
083       * @return {@code this} assertion object.
084       * @throws AssertionError if the actual value is {@code null}.
085       * @throws AssertionError if the actual value is greater than the given one.
086       */
087      public CharacterAssert isLessThanOrEqualTo(char other) {
088        characters.assertLessThanOrEqualTo(info, actual, other);
089        return this;
090      }
091    
092      /**
093       * Verifies that the actual value is greater 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 less than the given one.
098       */
099      public CharacterAssert isGreaterThan(char other) {
100        characters.assertGreaterThan(info, actual, other);
101        return this;
102      }
103    
104      /**
105       * Verifies that the actual value is greater 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 less than the given one.
110       */
111      public CharacterAssert isGreaterThanOrEqualTo(char other) {
112        characters.assertGreaterThanOrEqualTo(info, actual, other);
113        return this;
114      }
115    
116      /**
117       * Verifies that the actual value is a lowercase character.
118       * @return {@code this} assertion object.
119       * @throws AssertionError if the actual value is {@code null}.
120       * @throws AssertionError if the actual value is not a lowercase character.
121       */
122      public CharacterAssert isLowerCase() {
123        characters.assertLowerCase(info, actual);
124        return this;
125      }
126    
127      /**
128       * Verifies that the actual value is a uppercase character.
129       * @return {@code this} assertion object.
130       * @throws AssertionError if the actual value is {@code null}.
131       * @throws AssertionError if the actual value is not a uppercase character.
132       */
133      public CharacterAssert isUpperCase() {
134        characters.assertUpperCase(info, actual);
135        return this;
136      }
137    
138      @Override
139      public CharacterAssert usingComparator(Comparator<?> customComparator) {
140        super.usingComparator(customComparator);
141        this.characters = new Characters(new ComparatorBasedComparisonStrategy(customComparator));
142        return myself;
143      }
144      
145      @Override
146      public CharacterAssert usingDefaultComparator() {
147        super.usingDefaultComparator();
148        this.characters = Characters.instance();
149        return myself;
150      }
151    }