View Javadoc
1   /*
2   BSD License
3   
4   Copyright (c) 2000-2006, www.hamcrest.org
5   All rights reserved.
6   
7   Redistribution and use in source and binary forms, with or without
8   modification, are permitted provided that the following conditions are met:
9   
10  Redistributions of source code must retain the above copyright notice, this list of
11  conditions and the following disclaimer. Redistributions in binary form must reproduce
12  the above copyright notice, this list of conditions and the following disclaimer in
13  the documentation and/or other materials provided with the distribution.
14  
15  Neither the name of Hamcrest nor the names of its contributors may be used to endorse
16  or promote products derived from this software without specific prior written
17  permission.
18  
19  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
20  EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21  OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
22  SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
23  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
24  TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
25  BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
27  WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
28  DAMAGE.
29  */
30  package dev.aherscu.qa.testing.utils.assertions.impl.matcher;
31  
32  import java.util.Collection;
33  
34  import org.hamcrest.BaseMatcher;
35  
36  public abstract class CollectionMatcher<C extends Collection<?>>
37      extends BaseMatcher<C> {
38      @SuppressWarnings("unchecked")
39      public boolean matches(Object item) {
40          if (!(item instanceof Collection)) {
41              return false;
42          }
43          return matchesSafely((C) item);
44      }
45  
46      protected abstract boolean matchesSafely(C collection);
47  }