001/** 002 * Powerunit - A JDK1.8 test framework 003 * Copyright (C) 2014 Mathieu Boretti. 004 * 005 * This file is part of Powerunit 006 * 007 * Powerunit is free software: you can redistribute it and/or modify 008 * it under the terms of the GNU General Public License as published by 009 * the Free Software Foundation, either version 3 of the License, or 010 * (at your option) any later version. 011 * 012 * Powerunit is distributed in the hope that it will be useful, 013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 015 * GNU General Public License for more details. 016 * 017 * You should have received a copy of the GNU General Public License 018 * along with Powerunit. If not, see <http://www.gnu.org/licenses/>. 019 */ 020package ch.powerunit; 021 022import org.hamcrest.Matcher; 023import org.hamcrest.Matchers; 024 025/** 026 * DSL for assertion on object. 027 * <p> 028 * This interface is returned by the various methods 029 * {@link TestSuite#assertThat(Object) assertThat} exposed by {@link TestSuite}. 030 * 031 * @author borettim 032 * @param <T> 033 * the object type. 034 */ 035public interface AssertThatObject<T> { 036 037 /** 038 * Check that the object is matching the passed matcher. 039 * 040 * @param matching 041 * the matcher. 042 */ 043 void is(Matcher<? super T> matching); 044 045 /** 046 * Check that the object is the passed one (shortcut to Matcher.equalTo). 047 * 048 * @param compareTo 049 * the value. 050 */ 051 default void is(T compareTo) { 052 is(Matchers.equalTo(compareTo)); 053 } 054 055 /** 056 * Check that the object is not the passed one. 057 * 058 * @param compareTo 059 * the value 060 */ 061 default void isNot(T compareTo) { 062 isNot(Matchers.equalTo(compareTo)); 063 } 064 065 /** 066 * Check that the object is not matching the passed matcher. 067 * 068 * @param matching 069 * the matcher 070 */ 071 default void isNot(Matcher<T> matching) { 072 is(Matchers.not(matching)); 073 } 074 075 /** 076 * Check that the object is null. 077 */ 078 default void isNull() { 079 is(Matchers.nullValue()); 080 } 081 082 /** 083 * Check that the object is not null. 084 */ 085 default void isNotNull() { 086 is(Matchers.notNullValue()); 087 } 088 089 /** 090 * Check that the object is of a specific class (or subclasses). 091 * 092 * @param clazz 093 * the class 094 */ 095 default void isA(Class<? super T> clazz) { 096 is(Matchers.isA(clazz)); 097 } 098 099}