001 /* 002 * Created on Apr 23, 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 accepting fields 022 * failed. 023 * 024 * @author Nicolas François 025 */ 026 public class ShouldBeLenientEqualByAccepting extends BasicErrorMessageFactory { 027 028 /** 029 * Creates a new </code>{@link ShouldBeLenientEqualByAccepting}</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 acceptedFields fields which are base the lenient equality 034 * @return the created {@code ErrorMessageFactory}. 035 */ 036 public static <E> ErrorMessageFactory shouldBeLenientEqualByAccepting(Object actual, List<String> rejectedFields, List<Object> rejectedValues, List<String> acceptedFields) { 037 if(rejectedFields.size() == 1){ 038 return new ShouldBeLenientEqualByAccepting(actual, rejectedFields.get(0), rejectedValues.get(0), acceptedFields); 039 } else { 040 return new ShouldBeLenientEqualByAccepting(actual, rejectedFields, rejectedValues, acceptedFields); 041 } 042 } 043 044 045 private ShouldBeLenientEqualByAccepting(Object actual, List<String> rejectedFields, List<Object> rejectedValue, List<String> acceptedFields) { 046 super("expected values <%s> in fields <%s> of <%s>, comparison was performed on fields <%s>", rejectedValue, rejectedFields, actual, acceptedFields); 047 } 048 049 private ShouldBeLenientEqualByAccepting(Object actual, String rejectedField, Object rejectedValue, List<String> acceptedFields) { 050 super("expected value <%s> in field <%s> of <%s>, comparison was performed on fields <%s>", rejectedValue, rejectedField, actual, acceptedFields); 051 } 052 053 }