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 on assertion on iterable. 027 * <p> 028 * This interface is returned by the various methods 029 * {@link TestSuite#assertThatIterable(Iterable) assertThatIterable} exposed by 030 * {@link TestSuite}. 031 * 032 * @author borettim 033 * @param <T> 034 * the Element type of the Iterator 035 * @see AssertThatObject assertion on object are also available on iterable. 036 */ 037public interface AssertThatIterable<T> extends AssertThatObject<Iterable<T>> { 038 /** 039 * Check the size of the iterable. 040 * 041 * @param size 042 * the expected size. 043 */ 044 @SuppressWarnings({ "unchecked", "rawtypes" }) 045 default void hasSize(int size) { 046 is((Matcher) Matchers.hasSize(size)); 047 } 048 049 /** 050 * Check the size is not the one passed. 051 * 052 * @param size 053 * the not expected size. 054 */ 055 @SuppressWarnings({ "unchecked", "rawtypes" }) 056 default void hasNotSize(int size) { 057 isNot((Matcher) Matchers.hasSize(size)); 058 } 059 060 /** 061 * Check that the iterable contains the items. 062 * 063 * @param items 064 * the expected items. 065 */ 066 default void contains(@SuppressWarnings("unchecked") T... items) { 067 is(Matchers.contains(items)); 068 } 069 070 /** 071 * Check that the iterable contains the items. 072 * 073 * @param items 074 * the matcher for each item. 075 */ 076 default void containsMatching( 077 @SuppressWarnings("unchecked") Matcher<? super T>... items) { 078 is(Matchers.contains(items)); 079 } 080 081 /** 082 * Check that the iterable contains the items in any order. 083 * 084 * @param items 085 * the expected items. 086 */ 087 default void containsInAnyOrder(@SuppressWarnings("unchecked") T... items) { 088 is(Matchers.containsInAnyOrder(items)); 089 } 090 091 /** 092 * Check that the iterable contains the items in any order. 093 * 094 * @param items 095 * the matcher for each item. 096 */ 097 default void containsInAnyOrderMatching( 098 @SuppressWarnings("unchecked") Matcher<? super T>... items) { 099 is(Matchers.containsInAnyOrder(items)); 100 } 101}