org.assertj.core.internal.Objects.canReadFieldValue()方法的使用及代码示例

x33g5p2x  于2022-01-26 转载在 其他  
字(8.2k)|赞(0)|评价(0)|浏览(112)

本文整理了Java中org.assertj.core.internal.Objects.canReadFieldValue()方法的一些代码示例,展示了Objects.canReadFieldValue()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Objects.canReadFieldValue()方法的具体详情如下:
包路径:org.assertj.core.internal.Objects
类名称:Objects
方法名:canReadFieldValue

Objects.canReadFieldValue介绍

暂无

代码示例

代码示例来源:origin: org.assertj/assertj-core

private <A> ByFieldsComparison isEqualToIgnoringGivenFields(A actual, A other,
                              Map<String, Comparator<?>> comparatorByPropertyOrField,
                              TypeComparators comparatorByType,
                              String[] givenIgnoredFields) {
 Set<Field> declaredFieldsIncludingInherited = getDeclaredFieldsIncludingInherited(actual.getClass());
 List<String> fieldsNames = new LinkedList<>();
 List<Object> expectedValues = new LinkedList<>();
 List<Object> rejectedValues = new LinkedList<>();
 Set<String> ignoredFields = newLinkedHashSet(givenIgnoredFields);
 for (Field field : declaredFieldsIncludingInherited) {
  // ignore private field if user has decided not to use them in comparison
  String fieldName = field.getName();
  if (ignoredFields.contains(fieldName) || !canReadFieldValue(field, actual)) {
   continue;
  }
  Object actualFieldValue = getPropertyOrFieldValue(actual, fieldName);
  Object otherFieldValue = getPropertyOrFieldValue(other, fieldName);
  if (!propertyOrFieldValuesAreEqual(actualFieldValue, otherFieldValue, fieldName,
                    comparatorByPropertyOrField, comparatorByType)) {
   fieldsNames.add(fieldName);
   rejectedValues.add(actualFieldValue);
   expectedValues.add(otherFieldValue);
  }
 }
 return new ByFieldsComparison(fieldsNames, expectedValues, rejectedValues);
}

代码示例来源:origin: org.assertj/assertj-core

List<String> nullFields = new LinkedList<>();
for (Field field : getDeclaredFieldsIncludingInherited(actual.getClass())) {
 if (!canReadFieldValue(field, actual)) continue;
 String fieldName = field.getName();
 Object otherFieldValue = getPropertyOrFieldValue(other, fieldName);

代码示例来源:origin: joel-costigliola/assertj-core

/**
 * Asserts that the given object has null fields except the given ones.
 *
 * @param <A> the actual type.
 * @param info contains information about the assertion.
 * @param actual the given object.
 * @param propertiesOrFieldsToIgnore the fields to ignore in comparison.
 * @throws AssertionError is actual is {@code null}.
 * @throws AssertionError if some of the fields of the actual object are not null.
 */
public <A> void assertHasAllNullFieldsOrPropertiesExcept(AssertionInfo info, A actual,
                             String... propertiesOrFieldsToIgnore) {
 assertNotNull(info, actual);
 Set<Field> declaredFields = getDeclaredFieldsIncludingInherited(actual.getClass());
 Set<String> ignoredFields = newLinkedHashSet(propertiesOrFieldsToIgnore);
 List<String> nonNullFieldNames = declaredFields.stream()
                         .filter(field -> !ignoredFields.contains(field.getName()))
                         .filter(field -> canReadFieldValue(field, actual))
                         .filter(field -> getPropertyOrFieldValue(actual, field.getName()) != null)
                         .map(Field::getName)
                         .collect(toList());
 if (!nonNullFieldNames.isEmpty()) {
  throw failures.failure(info, shouldHaveAllNullFields(actual, nonNullFieldNames, list(propertiesOrFieldsToIgnore)));
 }
}

代码示例来源:origin: joel-costigliola/assertj-core

private <A> ByFieldsComparison isEqualToIgnoringGivenFields(A actual, A other,
                              Map<String, Comparator<?>> comparatorByPropertyOrField,
                              TypeComparators comparatorByType,
                              String[] givenIgnoredFields) {
 Set<Field> declaredFieldsIncludingInherited = getDeclaredFieldsIncludingInherited(actual.getClass());
 List<String> fieldsNames = new LinkedList<>();
 List<Object> expectedValues = new LinkedList<>();
 List<Object> rejectedValues = new LinkedList<>();
 Set<String> ignoredFields = newLinkedHashSet(givenIgnoredFields);
 for (Field field : declaredFieldsIncludingInherited) {
  // ignore private field if user has decided not to use them in comparison
  String fieldName = field.getName();
  if (ignoredFields.contains(fieldName) || !canReadFieldValue(field, actual)) {
   continue;
  }
  Object actualFieldValue = getPropertyOrFieldValue(actual, fieldName);
  Object otherFieldValue = getPropertyOrFieldValue(other, fieldName);
  if (!propertyOrFieldValuesAreEqual(actualFieldValue, otherFieldValue, fieldName,
                    comparatorByPropertyOrField, comparatorByType)) {
   fieldsNames.add(fieldName);
   rejectedValues.add(actualFieldValue);
   expectedValues.add(otherFieldValue);
  }
 }
 return new ByFieldsComparison(fieldsNames, expectedValues, rejectedValues);
}

代码示例来源:origin: org.assertj/assertj-core

/**
 * Assert that the given object has no null fields except the given ones.
 *
 * @param <A> the actual type
 * @param info contains information about the assertion.
 * @param actual the given object.
 * @param propertiesOrFieldsToIgnore the fields to ignore in comparison
 * @throws AssertionError if actual is {@code null}.
 * @throws AssertionError if some of the fields of the actual object are null.
 */
public <A> void assertHasNoNullFieldsOrPropertiesExcept(AssertionInfo info, A actual,
                            String... propertiesOrFieldsToIgnore) {
 assertNotNull(info, actual);
 Set<Field> declaredFieldsIncludingInherited = getDeclaredFieldsIncludingInherited(actual.getClass());
 List<String> nullFieldNames = new LinkedList<>();
 Set<String> ignoredFields = newLinkedHashSet(propertiesOrFieldsToIgnore);
 for (Field field : declaredFieldsIncludingInherited) {
  // ignore private field if user has decided not to use them in comparison
  String fieldName = field.getName();
  if (ignoredFields.contains(fieldName) || !canReadFieldValue(field, actual)) continue;
  Object actualFieldValue = getPropertyOrFieldValue(actual, fieldName);
  if (actualFieldValue == null) nullFieldNames.add(fieldName);
 }
 if (!nullFieldNames.isEmpty())
  throw failures.failure(info, shouldHaveNoNullFieldsExcept(actual, nullFieldNames,
                               newArrayList(propertiesOrFieldsToIgnore)));
}

代码示例来源:origin: joel-costigliola/assertj-core

List<String> nullFields = new LinkedList<>();
for (Field field : getDeclaredFieldsIncludingInherited(actual.getClass())) {
 if (!canReadFieldValue(field, actual)) continue;
 String fieldName = field.getName();
 Object otherFieldValue = getPropertyOrFieldValue(other, fieldName);

代码示例来源:origin: joel-costigliola/assertj-core

/**
 * Assert that the given object has no null fields except the given ones.
 *
 * @param <A> the actual type.
 * @param info contains information about the assertion.
 * @param actual the given object.
 * @param propertiesOrFieldsToIgnore the fields to ignore in comparison.
 * @throws AssertionError if actual is {@code null}.
 * @throws AssertionError if some of the fields of the actual object are null.
 */
public <A> void assertHasNoNullFieldsOrPropertiesExcept(AssertionInfo info, A actual,
                            String... propertiesOrFieldsToIgnore) {
 assertNotNull(info, actual);
 Set<Field> declaredFieldsIncludingInherited = getDeclaredFieldsIncludingInherited(actual.getClass());
 List<String> nullFieldNames = new LinkedList<>();
 Set<String> ignoredFields = newLinkedHashSet(propertiesOrFieldsToIgnore);
 for (Field field : declaredFieldsIncludingInherited) {
  // ignore private field if user has decided not to use them in comparison
  String fieldName = field.getName();
  if (ignoredFields.contains(fieldName) || !canReadFieldValue(field, actual)) continue;
  Object actualFieldValue = getPropertyOrFieldValue(actual, fieldName);
  if (actualFieldValue == null) nullFieldNames.add(fieldName);
 }
 if (!nullFieldNames.isEmpty())
  throw failures.failure(info, shouldHaveNoNullFieldsExcept(actual, nullFieldNames,
                               newArrayList(propertiesOrFieldsToIgnore)));
}

代码示例来源:origin: org.assertj/assertj-core-java8

private <A> ByFieldsComparison isEqualToIgnoringGivenFields(A actual, A other, String[] givenIgnoredFields) {
 Set<Field> declaredFieldsIncludingInherited = getDeclaredFieldsIncludingInherited(actual.getClass());
 verifyIgnoredFieldsExist(actual, declaredFieldsIncludingInherited, givenIgnoredFields);
 List<String> fieldsNames = new LinkedList<String>();
 List<Object> expectedValues = new LinkedList<Object>();
 List<Object> rejectedValues = new LinkedList<Object>();
 Set<String> ignoredFields = newLinkedHashSet(givenIgnoredFields);
 for (Field field : declaredFieldsIncludingInherited) {
  // ignore private field if user has decided not to use them in comparison
  if (ignoredFields.contains(field.getName()) || !canReadFieldValue(field, actual)) {
   continue;
  }
  Object actualFieldValue = getFieldOrPropertyValue(actual, field.getName());
  Object otherFieldValue = getFieldOrPropertyValue(other, field.getName());
  if (!org.assertj.core.util.Objects.areEqual(actualFieldValue, otherFieldValue)) {
   fieldsNames.add(field.getName());
   rejectedValues.add(actualFieldValue);
   expectedValues.add(otherFieldValue);
  }
 }
 return new ByFieldsComparison(fieldsNames, expectedValues, rejectedValues);
}

相关文章

微信公众号

最新文章

更多