001    /*  Copyright (c) 2000-2006 hamcrest.org
002     */
003    package org.hamcrest.core;
004    
005    import org.hamcrest.Description;
006    import org.hamcrest.Matcher;
007    import org.hamcrest.Factory;
008    import org.hamcrest.BaseMatcher;
009    
010    
011    /**
012     * A matcher that always returns <code>true</code>.
013     */
014    public class IsAnything<T> extends BaseMatcher<T> {
015    
016        private final String message;
017    
018        public IsAnything() {
019            this("ANYTHING");
020        }
021    
022        public IsAnything(String message) {
023            this.message = message;
024        }
025    
026        @Override
027        public boolean matches(Object o) {
028            return true;
029        }
030    
031        @Override
032        public void describeTo(Description description) {
033            description.appendText(message);
034        }
035    
036        /**
037         * Creates a matcher that always matches, regardless of the examined object.
038         */
039        @Factory
040        public static Matcher<Object> anything() {
041            return new IsAnything<Object>();
042        }
043    
044        /**
045         * Creates a matcher that always matches, regardless of the examined object, but describes
046         * itself with the specified {@link String}.
047         *
048         * @param description
049         *     a meaningful {@link String} used when describing itself
050         */
051        @Factory
052        public static Matcher<Object> anything(String description) {
053            return new IsAnything<Object>(description);
054        }
055    }