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

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

本文整理了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

  1. private <A> ByFieldsComparison isEqualToIgnoringGivenFields(A actual, A other,
  2. Map<String, Comparator<?>> comparatorByPropertyOrField,
  3. TypeComparators comparatorByType,
  4. String[] givenIgnoredFields) {
  5. Set<Field> declaredFieldsIncludingInherited = getDeclaredFieldsIncludingInherited(actual.getClass());
  6. List<String> fieldsNames = new LinkedList<>();
  7. List<Object> expectedValues = new LinkedList<>();
  8. List<Object> rejectedValues = new LinkedList<>();
  9. Set<String> ignoredFields = newLinkedHashSet(givenIgnoredFields);
  10. for (Field field : declaredFieldsIncludingInherited) {
  11. // ignore private field if user has decided not to use them in comparison
  12. String fieldName = field.getName();
  13. if (ignoredFields.contains(fieldName) || !canReadFieldValue(field, actual)) {
  14. continue;
  15. }
  16. Object actualFieldValue = getPropertyOrFieldValue(actual, fieldName);
  17. Object otherFieldValue = getPropertyOrFieldValue(other, fieldName);
  18. if (!propertyOrFieldValuesAreEqual(actualFieldValue, otherFieldValue, fieldName,
  19. comparatorByPropertyOrField, comparatorByType)) {
  20. fieldsNames.add(fieldName);
  21. rejectedValues.add(actualFieldValue);
  22. expectedValues.add(otherFieldValue);
  23. }
  24. }
  25. return new ByFieldsComparison(fieldsNames, expectedValues, rejectedValues);
  26. }

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

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

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

  1. /**
  2. * Asserts that the given object has null fields except the given ones.
  3. *
  4. * @param <A> the actual type.
  5. * @param info contains information about the assertion.
  6. * @param actual the given object.
  7. * @param propertiesOrFieldsToIgnore the fields to ignore in comparison.
  8. * @throws AssertionError is actual is {@code null}.
  9. * @throws AssertionError if some of the fields of the actual object are not null.
  10. */
  11. public <A> void assertHasAllNullFieldsOrPropertiesExcept(AssertionInfo info, A actual,
  12. String... propertiesOrFieldsToIgnore) {
  13. assertNotNull(info, actual);
  14. Set<Field> declaredFields = getDeclaredFieldsIncludingInherited(actual.getClass());
  15. Set<String> ignoredFields = newLinkedHashSet(propertiesOrFieldsToIgnore);
  16. List<String> nonNullFieldNames = declaredFields.stream()
  17. .filter(field -> !ignoredFields.contains(field.getName()))
  18. .filter(field -> canReadFieldValue(field, actual))
  19. .filter(field -> getPropertyOrFieldValue(actual, field.getName()) != null)
  20. .map(Field::getName)
  21. .collect(toList());
  22. if (!nonNullFieldNames.isEmpty()) {
  23. throw failures.failure(info, shouldHaveAllNullFields(actual, nonNullFieldNames, list(propertiesOrFieldsToIgnore)));
  24. }
  25. }

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

  1. private <A> ByFieldsComparison isEqualToIgnoringGivenFields(A actual, A other,
  2. Map<String, Comparator<?>> comparatorByPropertyOrField,
  3. TypeComparators comparatorByType,
  4. String[] givenIgnoredFields) {
  5. Set<Field> declaredFieldsIncludingInherited = getDeclaredFieldsIncludingInherited(actual.getClass());
  6. List<String> fieldsNames = new LinkedList<>();
  7. List<Object> expectedValues = new LinkedList<>();
  8. List<Object> rejectedValues = new LinkedList<>();
  9. Set<String> ignoredFields = newLinkedHashSet(givenIgnoredFields);
  10. for (Field field : declaredFieldsIncludingInherited) {
  11. // ignore private field if user has decided not to use them in comparison
  12. String fieldName = field.getName();
  13. if (ignoredFields.contains(fieldName) || !canReadFieldValue(field, actual)) {
  14. continue;
  15. }
  16. Object actualFieldValue = getPropertyOrFieldValue(actual, fieldName);
  17. Object otherFieldValue = getPropertyOrFieldValue(other, fieldName);
  18. if (!propertyOrFieldValuesAreEqual(actualFieldValue, otherFieldValue, fieldName,
  19. comparatorByPropertyOrField, comparatorByType)) {
  20. fieldsNames.add(fieldName);
  21. rejectedValues.add(actualFieldValue);
  22. expectedValues.add(otherFieldValue);
  23. }
  24. }
  25. return new ByFieldsComparison(fieldsNames, expectedValues, rejectedValues);
  26. }

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

  1. /**
  2. * Assert that the given object has no null fields except the given ones.
  3. *
  4. * @param <A> the actual type
  5. * @param info contains information about the assertion.
  6. * @param actual the given object.
  7. * @param propertiesOrFieldsToIgnore the fields to ignore in comparison
  8. * @throws AssertionError if actual is {@code null}.
  9. * @throws AssertionError if some of the fields of the actual object are null.
  10. */
  11. public <A> void assertHasNoNullFieldsOrPropertiesExcept(AssertionInfo info, A actual,
  12. String... propertiesOrFieldsToIgnore) {
  13. assertNotNull(info, actual);
  14. Set<Field> declaredFieldsIncludingInherited = getDeclaredFieldsIncludingInherited(actual.getClass());
  15. List<String> nullFieldNames = new LinkedList<>();
  16. Set<String> ignoredFields = newLinkedHashSet(propertiesOrFieldsToIgnore);
  17. for (Field field : declaredFieldsIncludingInherited) {
  18. // ignore private field if user has decided not to use them in comparison
  19. String fieldName = field.getName();
  20. if (ignoredFields.contains(fieldName) || !canReadFieldValue(field, actual)) continue;
  21. Object actualFieldValue = getPropertyOrFieldValue(actual, fieldName);
  22. if (actualFieldValue == null) nullFieldNames.add(fieldName);
  23. }
  24. if (!nullFieldNames.isEmpty())
  25. throw failures.failure(info, shouldHaveNoNullFieldsExcept(actual, nullFieldNames,
  26. newArrayList(propertiesOrFieldsToIgnore)));
  27. }

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

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

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

  1. /**
  2. * Assert that the given object has no null fields except the given ones.
  3. *
  4. * @param <A> the actual type.
  5. * @param info contains information about the assertion.
  6. * @param actual the given object.
  7. * @param propertiesOrFieldsToIgnore the fields to ignore in comparison.
  8. * @throws AssertionError if actual is {@code null}.
  9. * @throws AssertionError if some of the fields of the actual object are null.
  10. */
  11. public <A> void assertHasNoNullFieldsOrPropertiesExcept(AssertionInfo info, A actual,
  12. String... propertiesOrFieldsToIgnore) {
  13. assertNotNull(info, actual);
  14. Set<Field> declaredFieldsIncludingInherited = getDeclaredFieldsIncludingInherited(actual.getClass());
  15. List<String> nullFieldNames = new LinkedList<>();
  16. Set<String> ignoredFields = newLinkedHashSet(propertiesOrFieldsToIgnore);
  17. for (Field field : declaredFieldsIncludingInherited) {
  18. // ignore private field if user has decided not to use them in comparison
  19. String fieldName = field.getName();
  20. if (ignoredFields.contains(fieldName) || !canReadFieldValue(field, actual)) continue;
  21. Object actualFieldValue = getPropertyOrFieldValue(actual, fieldName);
  22. if (actualFieldValue == null) nullFieldNames.add(fieldName);
  23. }
  24. if (!nullFieldNames.isEmpty())
  25. throw failures.failure(info, shouldHaveNoNullFieldsExcept(actual, nullFieldNames,
  26. newArrayList(propertiesOrFieldsToIgnore)));
  27. }

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

  1. private <A> ByFieldsComparison isEqualToIgnoringGivenFields(A actual, A other, String[] givenIgnoredFields) {
  2. Set<Field> declaredFieldsIncludingInherited = getDeclaredFieldsIncludingInherited(actual.getClass());
  3. verifyIgnoredFieldsExist(actual, declaredFieldsIncludingInherited, givenIgnoredFields);
  4. List<String> fieldsNames = new LinkedList<String>();
  5. List<Object> expectedValues = new LinkedList<Object>();
  6. List<Object> rejectedValues = new LinkedList<Object>();
  7. Set<String> ignoredFields = newLinkedHashSet(givenIgnoredFields);
  8. for (Field field : declaredFieldsIncludingInherited) {
  9. // ignore private field if user has decided not to use them in comparison
  10. if (ignoredFields.contains(field.getName()) || !canReadFieldValue(field, actual)) {
  11. continue;
  12. }
  13. Object actualFieldValue = getFieldOrPropertyValue(actual, field.getName());
  14. Object otherFieldValue = getFieldOrPropertyValue(other, field.getName());
  15. if (!org.assertj.core.util.Objects.areEqual(actualFieldValue, otherFieldValue)) {
  16. fieldsNames.add(field.getName());
  17. rejectedValues.add(actualFieldValue);
  18. expectedValues.add(otherFieldValue);
  19. }
  20. }
  21. return new ByFieldsComparison(fieldsNames, expectedValues, rejectedValues);
  22. }

相关文章