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 * @author Mikhail Mazursky 036 */ 037 public class CharacterAssert extends AbstractComparableAssert<CharacterAssert, Character> { 038 039 @VisibleForTesting Characters characters = Characters.instance(); 040 041 protected CharacterAssert(Character actual) { 042 super(actual, CharacterAssert.class); 043 } 044 045 /** 046 * Verifies that the actual value is equal to the given one. 047 * @param expected the given value to compare the actual value to. 048 * @return {@code this} assertion object. 049 * @throws AssertionError if the actual value is {@code null}. 050 * @throws AssertionError if the actual value is not equal to the given one. 051 */ 052 public CharacterAssert isEqualTo(char expected) { 053 characters.assertEqual(info, actual, expected); 054 return this; 055 } 056 057 /** 058 * Verifies that the actual value is not equal to the given one. 059 * @param other the given value to compare the actual value to. 060 * @return {@code this} assertion object. 061 * @throws AssertionError if the actual value is {@code null}. 062 * @throws AssertionError if the actual value is equal to the given one. 063 */ 064 public CharacterAssert isNotEqualTo(char other) { 065 characters.assertNotEqual(info, actual, other); 066 return this; 067 } 068 069 /** 070 * Verifies that the actual value is less than the given one. 071 * @param other the given value to compare the actual value to. 072 * @return {@code this} assertion object. 073 * @throws AssertionError if the actual value is {@code null}. 074 * @throws AssertionError if the actual value is equal to or greater than the given one. 075 */ 076 public CharacterAssert isLessThan(char other) { 077 characters.assertLessThan(info, actual, other); 078 return this; 079 } 080 081 /** 082 * Verifies that the actual value is less than or equal to the given one. 083 * @param other the given value to compare the actual value to. 084 * @return {@code this} assertion object. 085 * @throws AssertionError if the actual value is {@code null}. 086 * @throws AssertionError if the actual value is greater than the given one. 087 */ 088 public CharacterAssert isLessThanOrEqualTo(char other) { 089 characters.assertLessThanOrEqualTo(info, actual, other); 090 return this; 091 } 092 093 /** 094 * Verifies that the actual value is greater than the given one. 095 * @param other the given value to compare the actual value to. 096 * @return {@code this} assertion object. 097 * @throws AssertionError if the actual value is {@code null}. 098 * @throws AssertionError if the actual value is equal to or less than the given one. 099 */ 100 public CharacterAssert isGreaterThan(char other) { 101 characters.assertGreaterThan(info, actual, other); 102 return this; 103 } 104 105 /** 106 * Verifies that the actual value is greater than or equal to the given one. 107 * @param other the given value to compare the actual value to. 108 * @return {@code this} assertion object. 109 * @throws AssertionError if the actual value is {@code null}. 110 * @throws AssertionError if the actual value is less than the given one. 111 */ 112 public CharacterAssert isGreaterThanOrEqualTo(char other) { 113 characters.assertGreaterThanOrEqualTo(info, actual, other); 114 return this; 115 } 116 117 /** 118 * Verifies that the actual value is a lowercase character. 119 * @return {@code this} assertion object. 120 * @throws AssertionError if the actual value is {@code null}. 121 * @throws AssertionError if the actual value is not a lowercase character. 122 */ 123 public CharacterAssert isLowerCase() { 124 characters.assertLowerCase(info, actual); 125 return this; 126 } 127 128 /** 129 * Verifies that the actual value is a uppercase character. 130 * @return {@code this} assertion object. 131 * @throws AssertionError if the actual value is {@code null}. 132 * @throws AssertionError if the actual value is not a uppercase character. 133 */ 134 public CharacterAssert isUpperCase() { 135 characters.assertUpperCase(info, actual); 136 return this; 137 } 138 139 @Override 140 public CharacterAssert usingComparator(Comparator<? super Character> customComparator) { 141 super.usingComparator(customComparator); 142 this.characters = new Characters(new ComparatorBasedComparisonStrategy(customComparator)); 143 return myself; 144 } 145 146 @Override 147 public CharacterAssert usingDefaultComparator() { 148 super.usingDefaultComparator(); 149 this.characters = Characters.instance(); 150 return myself; 151 } 152 }