001 /* 002 * Created on Sep 16, 2007 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 005 * in compliance with 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 010 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 011 * or implied. See the License for the specific language governing permissions and limitations under 012 * the License. 013 * 014 * Copyright @2007-2009 the original author or authors. 015 */ 016 package org.fest.assertions; 017 018 /** 019 * Understands a template for assertion methods for primitive values. 020 * 021 * @author Yvonne Wang 022 */ 023 public abstract class PrimitiveAssert extends Assert { 024 025 /** 026 * Sets the description of the actual value, to be used in as message of any <code>{@link AssertionError}</code> 027 * thrown when an assertion fails. This method should be called before any assertion method, otherwise any assertion 028 * failure will not show the provided description. 029 * <p> 030 * For example: 031 * <pre> 032 * assertThat(value).<strong>as</strong>("Some value").isEqualTo(otherValue); 033 * </pre> 034 * </p> 035 * @param description the description of the actual value. 036 * @return this assertion object. 037 */ 038 protected abstract PrimitiveAssert as(String description); 039 040 /** 041 * Alias for <code>{@link #as(String)}</code>, since "as" is a keyword in 042 * <a href="http://groovy.codehaus.org/" target="_blank">Groovy</a>. This method should be called before any assertion 043 * method, otherwise any assertion failure will not show the provided description. 044 * <p> 045 * For example: 046 * <pre> 047 * assertThat(value).<strong>describedAs</strong>("Some value").isEqualTo(otherValue); 048 * </pre> 049 * </p> 050 * @param description the description of the actual value. 051 * @return this assertion object. 052 */ 053 protected abstract PrimitiveAssert describedAs(String description); 054 055 /** 056 * Sets the description of the actual value, to be used in as message of any <code>{@link AssertionError}</code> 057 * thrown when an assertion fails. This method should be called before any assertion method, otherwise any assertion 058 * failure will not show the provided description. 059 * <p> 060 * For example: 061 * <pre> 062 * assertThat(val).<strong>as</strong>(new BasicDescription("name")).isEqualTo("Frodo"); 063 * </pre> 064 * </p> 065 * @param description the description of the actual value. 066 * @return this assertion object. 067 */ 068 protected abstract PrimitiveAssert as(Description description); 069 070 /** 071 * Alias for <code>{@link #as(Description)}</code>, since "as" is a keyword in 072 * <a href="http://groovy.codehaus.org/" target="_blank">Groovy</a>. This method should be called before any assertion 073 * method, otherwise any assertion failure will not show the provided description. 074 * <p> 075 * For example: 076 * <pre> 077 * assertThat(val).<strong>describedAs</strong>(new BasicDescription("name")).isEqualTo("Frodo"); 078 * </pre> 079 * </p> 080 * @param description the description of the actual value. 081 * @return this assertion object. 082 */ 083 protected abstract PrimitiveAssert describedAs(Description description); 084 085 /** 086 * Replaces the default message displayed in case of a failure with the given one. 087 * <p> 088 * For example, the following assertion: 089 * <pre> 090 * assertThat("Hello").isEqualTo("Bye"); 091 * </pre> 092 * will fail with the default message "<em>expected:<'[Bye]'> but was:<'[Hello]'></em>." 093 * </p> 094 * <p> 095 * We can replace this message with our own: 096 * <pre> 097 * assertThat("Hello").overridingErrorMessage("'Hello' should be equal to 'Bye'").isEqualTo("Bye"); 098 * </pre> 099 * in this case, the assertion will fail showing the message "<em>'Hello' should be equal to 'Bye'</em>". 100 * </p> 101 * @param message the given error message, which will replace the default one. 102 * @return this assertion. 103 * @since 1.2 104 */ 105 protected abstract PrimitiveAssert overridingErrorMessage(String message); 106 }