001 /* 002 * Created on Oct 18, 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.error; 016 017 import static org.fest.util.Dates.parse; 018 019 import java.util.Date; 020 021 import org.fest.util.ComparisonStrategy; 022 import org.fest.util.StandardComparisonStrategy; 023 024 /** 025 * Creates an error message indicating that an assertion that verifies that a {@link Date} is after another one failed. 026 * 027 * @author Joel Costigliola 028 */ 029 public class ShouldBeAfter extends BasicErrorMessageFactory { 030 031 /** 032 * Creates a new </code>{@link ShouldBeAfter}</code>. 033 * @param actual the actual value in the failed assertion. 034 * @param other the value used in the failed assertion to compare the actual value to. 035 * @param comparisonStrategy the {@link ComparisonStrategy} used to evaluate assertion. 036 * @return the created {@code ErrorMessageFactory}. 037 */ 038 public static ErrorMessageFactory shouldBeAfter(Date actual, Date other, ComparisonStrategy comparisonStrategy) { 039 return new ShouldBeAfter(actual, other, comparisonStrategy); 040 } 041 042 /** 043 * Creates a new </code>{@link ShouldBeAfter}</code>. 044 * @param actual the actual value in the failed assertion. 045 * @param other the value used in the failed assertion to compare the actual value to. 046 * @return the created {@code ErrorMessageFactory}. 047 */ 048 public static ErrorMessageFactory shouldBeAfter(Date actual, Date other) { 049 return new ShouldBeAfter(actual, other, StandardComparisonStrategy.instance()); 050 } 051 052 /** 053 * Creates a new </code>{@link ShouldBeAfter}</code>. 054 * @param actual the actual value in the failed assertion. 055 * @param year the year to compare the actual date's year to. 056 * @return the created {@code ErrorMessageFactory}. 057 */ 058 public static ErrorMessageFactory shouldBeAfter(Date actual, int year) { 059 Date januaryTheFirstOfGivenYear = parse(year + "-01-01"); 060 return new ShouldBeAfter(actual, januaryTheFirstOfGivenYear, StandardComparisonStrategy.instance()); 061 } 062 063 private ShouldBeAfter(Date actual, Date other, ComparisonStrategy comparisonStrategy) { 064 super("expected:<%s> to be strictly after :<%s>%s", actual, other, comparisonStrategy); 065 } 066 } 067