001    /*
002     * Created on Jul 20, 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.description;
016    
017    import static org.fest.util.Objects.*;
018    
019    import org.fest.util.VisibleForTesting;
020    
021    /**
022     * A text-based description.
023     *
024     * @author Yvonne Wang
025     * @author Alex Ruiz
026     */
027    public class TextDescription extends Description {
028    
029      @VisibleForTesting final String value;
030    
031      /**
032       * Creates a new </code>{@link TextDescription}</code>.
033       * @param value the value of this description.
034       * @throws NullPointerException if the given value is {@code null}.
035       */
036      public TextDescription(String value) {
037        if (value == null) throw new NullPointerException("The value of the description should not be null");
038        this.value = value;
039      }
040    
041      /** {@inheritDoc} */
042      @Override public final String value() {
043        return value;
044      }
045    
046      @Override public int hashCode() {
047        return HASH_CODE_PRIME * 1 + hashCodeFor(value);
048      }
049    
050      @Override public boolean equals(Object obj) {
051        if (this == obj) return true;
052        if (obj == null) return false;
053        if (getClass() != obj.getClass()) return false;
054        TextDescription other = (TextDescription) obj;
055        return areEqual(value, other.value);
056      }
057    }