Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (C) 2008 Ovea <dev@testatoo.org> Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
 
 
 package org.testatoo.core.matcher;
 
 
 import java.util.List;
 
 import static java.lang.Boolean.TRUE;

This class is a matcher (written based on hamcrest possibilites) to test the content of lists.

Author(s):
dev@testatoo.org
 
 public final class ContainsValues extends TypeSafeMatcher<ListModel> {
 
     private List<StringexpectedValues = new ArrayList<String>();
     private Boolean exactly = ;

    
Uses the matcher ContainsValues to compare the content of a given listModel to the expected values of the matcher, using the syntax "containsValues("xxx", "yyyy", "zzz")" or "containsExactlyValues("xxx", "yyyy", "zzz")"

Parameters:
listModel the listModel
Returns:
True if the list contains (contains exactly for second syntax) the values of the matcher ContainsValues
 
     public boolean matchesSafely(ListModel listModel) {
         List<Stringvalues = new ArrayList<String>();
         values.addAll(listModel.values());
 
         if () {
             return values.containsAll() && values.size() == .size();
         }
 
         return values.containsAll();
     }

    
To append the description of the content of the list to the given description

Parameters:
description the description may be part of a a description of a larger object
 
     public void describeTo(Description description) {
         String exactlyString =  ? " exactly" : "";
         description.appendText("contains" + exactlyString + " value(s):").appendText(Arrays.deepToString(.toArray()));
     }

    
Constructor with given values

Parameters:
exactly boolean with True value if we want to know if the list contains exactly the values
values values we want to know if they are (or are exactly) in the list
 
     public ContainsValues(Boolean exactlyString... values) {
         if (exactly != null) {
             this. = exactly;
         }
         .addAll(Arrays.asList(values));
     }

    
Using the syntax "containsValues("xxx", "yyyy", "zzz")", the test creates a ContainsValues matcher

Parameters:
values the list of values to compare to the content of the list
Returns:
a new ContainsValues matcher
 
     @Factory
     public static Matcher<ListModelcontains(String... values) {
         return new ContainsValues(falsevalues);
     }

    
Using the syntax "containsExactlyValues("xxx", "yyyy", "zzz")", the test creates a ContainsValues matcher

Parameters:
values the list of values to compare to the content of the list
Returns:
a new ContainsValues matcher
 
     @Factory
    public static Matcher<ListModelcontainsExaclty(String... values) {
        return new ContainsValues(truevalues);
    }
New to GrepCode? Check out our FAQ X