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 java.util.regex.Pattern; 023 024import org.hamcrest.Matchers; 025 026/** 027 * DSL for assertion on string result. 028 * <p> 029 * This interface is returned by the various methods 030 * {@link TestSuite#assertThat(String) assertThat} exposed by {@link TestSuite}. 031 * 032 * @author borettim 033 * 034 */ 035public interface AssertThatString extends AssertThatObject<String> { 036 /** 037 * Check that a string another string. 038 * 039 * @param substring 040 * the other string. 041 */ 042 default void containsString(String substring) { 043 is(Matchers.containsString(substring)); 044 } 045 046 /** 047 * Check that a string starts with another one. 048 * 049 * @param prefix 050 * the prefix. 051 */ 052 default void startsWith(String prefix) { 053 is(Matchers.startsWith(prefix)); 054 } 055 056 /** 057 * Check that a string ends with another one. 058 * 059 * @param prefix 060 * the prefix. 061 */ 062 default void endsWith(String prefix) { 063 is(Matchers.endsWith(prefix)); 064 } 065 066 /** 067 * Validate a string with a {@link java.util.regex.Pattern}. 068 * 069 * @param pattern 070 * the pattern to be used. 071 */ 072 default void matchesRegex(Pattern pattern) { 073 is(TestSuite.DSL.matchesRegex(pattern)); 074 } 075 076 /** 077 * Validate a string with a regex. 078 * 079 * 080 * @param regex 081 * The regex to be used for the validation. 082 */ 083 default void matchesRegex(String regex) { 084 is(TestSuite.DSL.matchesRegex(regex)); 085 } 086}