/** * Returns true if actual and other are equal based on {@link Object#equals(Object)}, false otherwise. * * @param actual the object to compare to other * @param other the object to compare to actual * @return true if actual and other are equal based on {@link Object#equals(Object)}, false otherwise. */ @Override public boolean areEqual(Object actual, Object other) { return Objects.areEqual(actual, other); }
/** * Returns <code>true</code> if given item is in given array, <code>false</code> otherwise. * @param item the object to look for in arrayOfValues * @param arrayOfValues the array of values * @return <code>true</code> if given item is in given array, <code>false</code> otherwise. */ private static boolean isItemInArray(Object item, Object[] arrayOfValues) { for (Object value : arrayOfValues) if (areEqual(value, item)) return true; return false; }
/** * Returns true if given {@link Iterable} contains given value based on {@link Object#equals(Object)}, false otherwise.<br> * If given {@link Iterable} is null, return false. * * @param iterable the {@link Iterable} to search value in * @param value the object to look for in given {@link Iterable} * @return true if given {@link Iterable} contains given value based on {@link Object#equals(Object)}, false otherwise. */ @Override public boolean iterableContains(Iterable<?> iterable, Object value) { if (iterable == null) { return false; } for (Object next : iterable) { if (Objects.areEqual(next, value)) { return true; } } return false; }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; BasicErrorMessageFactory other = (BasicErrorMessageFactory) obj; if (!areEqual(format, other.format)) return false; // because it does not manage array recursively, don't use : Arrays.equals(arguments, other.arguments); // example if arguments[1] and other.arguments[1] are logically same arrays but not same object, it will return // false return areEqual(arguments, other.arguments); }
private boolean containsEntry(Map<?, ?> actual, MapEntry entry) { if (entry == null) { throw new NullPointerException("Entries to look for should not be null"); } if (!actual.containsKey(entry.key)) { return false; } return areEqual(actual.get(entry.key), entry.value); }
@Override public boolean equals(Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (getClass() != obj.getClass()) { return false; } Offset<?> other = (Offset<?>) obj; return areEqual(value, other.value); }
@Override public boolean equals(Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (getClass() != obj.getClass()) { return false; } TextDescription other = (TextDescription) obj; return areEqual(value, other.value); } }
/** * {@inheritDoc} */ @Override public void iterableRemoves(Iterable<?> iterable, Object value) { if (iterable == null) { return; } Iterator<?> iterator = iterable.iterator(); while (iterator.hasNext()) { if (Objects.areEqual(iterator.next(), value)) { iterator.remove(); } } }
private List<String> diff(BufferedReader actual, BufferedReader expected) throws IOException { List<String> diffs = new ArrayList<String>(); int lineNumber = 0; while (true) { String actualLine = actual.readLine(); String expectedLine = expected.readLine(); if (actualLine == null || expectedLine == null) { if (expectedLine != null) { diffs.add(output(lineNumber, EOF, expectedLine)); } if (actualLine != null) { diffs.add(output(lineNumber, actualLine, EOF)); } return diffs; } else if (!areEqual(actualLine, expectedLine)) { diffs.add(output(lineNumber, actualLine, expectedLine)); } lineNumber += 1; } }
private boolean actualAndExpectedHaveSameStringRepresentation() { return areEqual(toStringOf(actual), toStringOf(expected)); }
/** * Filters the underlying iterable to keep object with property (specified by {@link #with(String)}) <b>not equals to</b> given * value. * <p> * Typical usage : * * <pre> * filter(employees).with("name").notEqualsTo("Vader").get(); * </pre> * * @param propertyValue the filter value. * @return this {@link Filters} to chain other filter operation. * @throws NullPointerException if the property name to filter on has not been set. */ public Filters<E> notEqualsTo(Object propertyValue) { checkPropertyNameToFilterOnIsNotNull(); List<E> newFilteredIterable = new ArrayList<E>(); for (E element : filteredIterable) { Object propertyValueOfCurrentElement = propertySupport.propertyValueOf(propertyNameToFilterOn, propertyValue.getClass(), element); if (!areEqual(propertyValueOfCurrentElement, propertyValue)) { newFilteredIterable.add(element); } } this.filteredIterable = newFilteredIterable; return this; }
/** * Filters the underlying iterable to keep object with property (specified by {@link #with(String)}) <b>equals to</b> given * value. * <p> * Typical usage : * * <pre> * filter(employees).with("name").equalsTo("Luke").get(); * </pre> * * @param propertyValue the filter value. * @return this {@link Filters} to chain other filter operation. * @throws NullPointerException if the property name to filter on has not been set. */ public Filters<E> equalsTo(Object propertyValue) { checkPropertyNameToFilterOnIsNotNull(); List<E> newFilteredIterable = new ArrayList<E>(); for (E element : filteredIterable) { // As we don't know the propertyValue class, we use Object.class Class<? extends Object> propertyValueClass = propertyValue == null ? Object.class : propertyValue.getClass(); Object propertyValueOfCurrentElement = propertySupport.propertyValueOf(propertyNameToFilterOn, propertyValueClass, element); if (areEqual(propertyValueOfCurrentElement, propertyValue)) { newFilteredIterable.add(element); } } this.filteredIterable = newFilteredIterable; return this; }
/** * Asserts that the given actual {@code Throwable} message is equal to the given one. * @param info contains information about the assertion. * @param actual the given {@code Throwable}. * @param message the expected message. * @throws AssertionError if the actual {@code Throwable} is {@code null}. * @throws AssertionError if the message of the actual {@code Throwable} is not equal to the given one. */ public void assertHasMessage(AssertionInfo info, Throwable actual, String message) { assertNotNull(info, actual); if (areEqual(actual.getMessage(), message)) return; throw failures.failure(info, shouldHaveMessage(actual, message)); }
Object actualFieldValue = propertySupport.propertyValue(fieldName, Object.class, actual); Object otherFieldValue = propertySupport.propertyValue(fieldName, Object.class, other); if (!org.fest.util.Objects.areEqual(actualFieldValue, otherFieldValue)) { fieldsNames.add(fieldName); expectedValues.add(otherFieldValue);
/** * Verifies that two floats are equal within a positive offset.<br> * It does not rely on the custom comparisonStrategy (if one is set) because using an offset is already a specific comparison * strategy. * @param info contains information about the assertion. * @param actual the actual value. * @param expected the expected value. * @param offset the given positive offset. * @throws NullPointerException if the given offset is {@code null}. * @throws AssertionError if the actual value is {@code null}. * @throws AssertionError if the actual value is not equal to the expected one. */ // can't be defined in RealNumbers because Offset parameter must inherits from Number // while RealNumber parameter must inherits from Comparable (sadly Number is not Comparable) public void assertEqual(AssertionInfo info, Double actual, Double expected, Offset<Double> offset) { checkOffsetIsNotNull(offset); checkNumberIsNotNull(expected); assertNotNull(info, actual); // doesn't use areEqual method relying on comparisonStrategy attribute if (Objects.areEqual(actual, expected)) return; if (expected != null && isEqualTo(actual, expected, offset)) return; throw failures.failure(info, shouldBeEqual(actual, expected, offset, abs(expected.doubleValue() - actual.doubleValue()))); }
/** * Verifies that two floats are equal within a positive offset.<br> * It does not rely on the custom comparisonStrategy (if one is set) because using an offset is already a specific comparison * strategy. * @param info contains information about the assertion. * @param actual the actual value. * @param expected the expected value. * @param offset the given positive offset. * @throws NullPointerException if the given offset is {@code null}. * @throws AssertionError if the actual value is not equal to the expected one. */ // can't be defined in RealNumbers because Offset parameter must inherits from Number // while RealNumber parameter must inherits from Comparable (sadly Number is not Comparable) public void assertEqual(AssertionInfo info, Float actual, Float expected, Offset<Float> offset) { assertNotNull(info, actual); checkOffsetIsNotNull(offset); checkNumberIsNotNull(expected); // doesn't use areEqual method relying on comparisonStrategy attribute if (Objects.areEqual(actual, expected)) return; if (expected != null && isEqualTo(actual, expected, offset)) return; throw failures.failure(info, shouldBeEqual(actual, expected, offset, abs(expected - actual.floatValue()))); }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; Money other = (Money) obj; return compatibleCurrency(other) && Objects.areEqual(denomination, other.denomination); }
private static boolean areEqualArrays(Object o1, Object o2) { if (!isArray(o1) || !isArray(o2)) { return false; } if (o1 == o2) { return true; } int size = Array.getLength(o1); if (Array.getLength(o2) != size) { return false; } for (int i = 0; i < size; i++) { Object e1 = Array.get(o1, i); Object e2 = Array.get(o2, i); if (!areEqual(e1, e2)) { return false; } } return true; }