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.internal;
016    
017    import static java.lang.Character.*;
018    
019    import static org.fest.assertions.error.ShouldBeLowerCase.shouldBeLowerCase;
020    import static org.fest.assertions.error.ShouldBeUpperCase.shouldBeUpperCase;
021    
022    import org.fest.assertions.core.AssertionInfo;
023    import org.fest.util.ComparisonStrategy;
024    import org.fest.util.VisibleForTesting;
025    
026    /**
027     * Reusable assertions for <code>{@link Character}</code>s.
028     * 
029     * @author Alex Ruiz
030     * @author Joel Costigliola
031     */
032    public class Characters extends Comparables {
033    
034      private static final Characters INSTANCE = new Characters();
035    
036      /**
037       * Returns the singleton instance of this class.
038       * @return the singleton instance of this class.
039       */
040      public static Characters instance() {
041        return INSTANCE;
042      }
043    
044      @VisibleForTesting
045      Characters() {
046        super();
047      }
048    
049      public Characters(ComparisonStrategy comparisonStrategy) {
050        super(comparisonStrategy);
051      }
052    
053      /**
054       * Asserts that the actual value is a lowercase character.
055       * @param info contains information about the assertion.
056       * @param actual the actual value.
057       * @throws AssertionError if the actual value is {@code null}.
058       * @throws AssertionError if the actual value is not a lowercase character.
059       */
060      public void assertLowerCase(AssertionInfo info, Character actual) {
061        assertNotNull(info, actual);
062        if (isLowerCase(actual)) return;
063        throw failures.failure(info, shouldBeLowerCase(actual));
064      }
065    
066      /**
067       * Asserts that the actual value is a uppercase character.
068       * @param info contains information about the assertion.
069       * @param actual the actual value.
070       * @throws AssertionError if the actual value is {@code null}.
071       * @throws AssertionError if the actual value is not a uppercase character.
072       */
073      public void assertUpperCase(AssertionInfo info, Character actual) {
074        assertNotNull(info, actual);
075        if (isUpperCase(actual)) return;
076        throw failures.failure(info, shouldBeUpperCase(actual));
077      }
078    }