001 /* 002 * Created on Nov 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.api; 016 017 import java.util.Comparator; 018 019 import org.fest.assertions.core.ComparableAssert; 020 import org.fest.assertions.internal.Comparables; 021 import org.fest.util.*; 022 023 /** 024 * Base class for all implementations of <code>{@link ComparableAssert}</code>. 025 * @param <S> the "self" type of this assertion class. Please read 026 * "<a href="http://bit.ly/anMa4g" target="_blank">Emulating 'self types' using Java Generics to simplify fluent 027 * API implementation</a>" for more details. 028 * @param <A> the type of the "actual" value. 029 * 030 * @author Alex Ruiz 031 */ 032 public abstract class AbstractComparableAssert<S, A extends Comparable<A>> extends AbstractAssert<S, A> implements ComparableAssert<S, A> { 033 034 @VisibleForTesting Comparables comparables = Comparables.instance(); 035 036 protected AbstractComparableAssert(A actual, Class<S> selfType) { 037 super(actual, selfType); 038 } 039 040 /** {@inheritDoc} */ 041 public final S isLessThan(A other) { 042 comparables.assertLessThan(info, actual, other); 043 return myself; 044 } 045 046 /** {@inheritDoc} */ 047 public final S isLessThanOrEqualTo(A other) { 048 comparables.assertLessThanOrEqualTo(info, actual, other); 049 return myself; 050 } 051 052 /** {@inheritDoc} */ 053 public final S isGreaterThan(A other) { 054 comparables.assertGreaterThan(info, actual, other); 055 return myself; 056 } 057 058 /** {@inheritDoc} */ 059 public final S isGreaterThanOrEqualTo(A other) { 060 comparables.assertGreaterThanOrEqualTo(info, actual, other); 061 return myself; 062 } 063 064 @Override 065 public S usingComparator(Comparator<?> customComparator) { 066 super.usingComparator(customComparator); 067 this.comparables = new Comparables(new ComparatorBasedComparisonStrategy(customComparator)); 068 return myself; 069 } 070 071 @Override 072 public S usingDefaultComparator() { 073 super.usingDefaultComparator(); 074 this.comparables = Comparables.instance(); 075 return myself; 076 } 077 }