001    /*
002     * Created on Mar 19, 2012
003     * 
004     * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
005     * the License. You may obtain a copy of the License at
006     * 
007     * http://www.apache.org/licenses/LICENSE-2.0
008     * 
009     * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
010     * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
011     * specific language governing permissions and limitations under the License.
012     * 
013     * Copyright @2012 the original author or authors.
014     */
015    package org.fest.assertions.error;
016    
017    import java.util.List;
018    
019    
020    /**
021     * Creates an <code>{@link AssertionError}</code> indicating that an assertion that verifies that two objects are lenient equal by ignoring fields
022     * failed.
023     * 
024     * @author Nicolas François
025     */
026    public class ShouldBeLenientEqualByIgnoring extends BasicErrorMessageFactory {
027    
028              /**
029               * Creates a new </code>{@link ShouldBeLenientEqualByIgnoring}</code>.
030               * @param actual the actual value in the failed assertion.
031               * @param rejectedFields fields name not matching
032               * @param rejectedValues fields value not matching
033               * @param ignoredFields fields which are not base the lenient equality
034               * @return the created {@code ErrorMessageFactory}.
035               */
036              public static <E> ErrorMessageFactory shouldBeLenientEqualByIgnoring(Object actual, List<String> rejectedFields, List<Object> rejectedValues, List<String> ignoredFields) {
037                    if(rejectedFields.size() == 1){
038                            if(ignoredFields.isEmpty()){
039                                    return new ShouldBeLenientEqualByIgnoring(actual, rejectedFields.get(0), rejectedValues.get(0));
040                            } else {
041                                    return new ShouldBeLenientEqualByIgnoring(actual, rejectedFields.get(0), rejectedValues.get(0), ignoredFields);
042                            }
043                    } else {
044                            if(ignoredFields.isEmpty()){
045                                    return new ShouldBeLenientEqualByIgnoring(actual, rejectedFields, rejectedValues);
046                            } else {
047                                    return new ShouldBeLenientEqualByIgnoring(actual, rejectedFields, rejectedValues, ignoredFields);
048                            }
049                    }
050              }
051    
052      
053              private ShouldBeLenientEqualByIgnoring(Object actual, List<String> rejectedFields, List<Object> rejectedValue, List<String> ignoredFields) {
054                      super("expected values <%s> in fields <%s> of <%s>, comparison was performed on all fields but <%s>", rejectedValue, rejectedFields, actual, ignoredFields);
055              }
056              
057              private ShouldBeLenientEqualByIgnoring(Object actual, String rejectedField, Object rejectedValue, List<String> ignoredFields) {
058                      super("expected value <%s> in field <%s> of <%s>, comparison was performed on all fields but <%s>", rejectedValue, rejectedField, actual, ignoredFields);
059              }
060              
061              private ShouldBeLenientEqualByIgnoring(Object actual, List<String> rejectedFields, List<Object> rejectedValue) {
062                      super("expected values <%s> in fields <%s> of <%s>, comparison was performed on all fields", rejectedValue, rejectedFields, actual);
063              }
064              
065              private ShouldBeLenientEqualByIgnoring(Object actual, String rejectedField, Object rejectedValue) {
066                      super("expected value <%s> in field <%s> of <%s>, comparison was performed on all fields", rejectedValue, rejectedField, actual);
067              }
068              
069    }