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 * Creates an <code>{@link AssertionError}</code> indicating that an assertion that verifies that two objects are
021 * lenient equal by accepting fields failed.
022 *
023 * @author Nicolas François
024 * @author Joel Costigliola
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 expectedValues fields value not matching
033 * @param acceptedFields fields on which is based the lenient equality
034 * @return the created {@code ErrorMessageFactory}.
035 */
036 public static <E> ErrorMessageFactory shouldBeLenientEqualByAccepting(Object actual, List<String> rejectedFields,
037 List<Object> expectedValues, List<String> acceptedFields) {
038 if (rejectedFields.size() == 1) {
039 return new ShouldBeLenientEqualByAccepting(actual, rejectedFields.get(0), expectedValues.get(0), acceptedFields);
040 } else {
041 return new ShouldBeLenientEqualByAccepting(actual, rejectedFields, expectedValues, acceptedFields);
042 }
043 }
044
045 private ShouldBeLenientEqualByAccepting(Object actual, List<String> rejectedFields, List<Object> expectedValue,
046 List<String> acceptedFields) {
047 super("expected values:\n<%s>\n in fields:\n<%s>\n of <%s>.\nComparison was performed on fields <%s>", expectedValue, rejectedFields,
048 actual, acceptedFields);
049 }
050
051 private ShouldBeLenientEqualByAccepting(Object actual, String rejectedField, Object rejectedValue, List<String> acceptedFields) {
052 super("expected value <%s> in field <%s> of <%s>.\nComparison was performed on fields <%s>", rejectedValue, rejectedField,
053 actual, acceptedFields);
054 }
055
056 }