static void checkIsNotNullAndNotEmpty(Iterable<?> iterable) { checkIsNotNull(iterable); checkIsNotEmpty(iterable); }
private boolean commonCheckThatIterableAssertionSucceeds(AssertionInfo info, Iterable<?> actual, Object[] sequence) { checkNotNullIterables(info, actual, sequence); // if both actual and values are empty, then assertion passes. if (!actual.iterator().hasNext() && sequence.length == 0) return true; failIfEmptySinceActualIsNotEmpty(sequence); return false; }
public <T> void satisfies(AssertionInfo info, List<? extends T> actual, Consumer<? super T> requirements, Index index) { assertNotNull(info, actual); checkNotNull(requirements, "The Consumer expressing the assertions requirements must not be null"); checkIndexValueIsValid(index, actual.size() - 1); requirements.accept(actual.get(index.value)); }
public static void hasSameSizeAsCheck(AssertionInfo info, Object actual, Map<?, ?> other, int sizeOfActual) { checkOtherIsNotNull(other, "Map"); checkSameSizes(info, actual, sizeOfActual, other.size()); }
/** * Asserts that the actual value is close to the an offset expressed as an percentage value. * * @param info contains information about the assertion. * @param actual the actual value. * @param other the expected value. * @param percentage the given positive percentage. */ public void assertIsCloseToPercentage(final AssertionInfo info, final NUMBER actual, final NUMBER other, final Percentage percentage) { assertNotNull(info, actual); checkPercentageIsNotNull(percentage); checkNumberIsNotNull(other); if (areEqual(actual, other)) return; double acceptableDiff = abs(percentage.value * other.doubleValue() / 100d); double actualDiff = absDiff(actual, other).doubleValue(); if (actualDiff > acceptableDiff || Double.isNaN(actualDiff) || Double.isInfinite(actualDiff)) throw failures.failure(info, shouldBeEqualWithinPercentage(actual, other, percentage, absDiff(actual, other))); }
public void assertContainsSubsequence(AssertionInfo info, Iterable<?> actual, List<?> subsequence) { checkIsNotNull(subsequence); assertContainsSubsequence(info, actual, subsequence.toArray()); }
/** * Asserts that the actual value is not close to the expected one by less than the given offset. * * @param info contains information about the assertion. * @param actual the actual value. * @param expected the value to compare actual too. * @param offset the given positive offset. */ public void assertIsNotCloseTo(final AssertionInfo info, final NUMBER actual, final NUMBER expected, final Offset<NUMBER> offset) { assertNotNull(info, actual); checkOffsetIsNotNull(offset); checkNumberIsNotNull(expected); NUMBER diff = absDiff(actual, expected); // with strict offset and actual == other => too close ! if (offset.strict && isGreaterThanOrEqualTo(diff, offset.value)) return; // with non strict offset and actual == other => too close ! if (!offset.strict && !areEqual(actual, expected)) { if (isGreaterThan(diff, offset.value)) return; } throw failures.failure(info, shouldNotBeEqual(actual, expected, offset, diff)); }
private boolean commonCheckThatLogFileAssertionSucceeds(AssertionInfo info, File actual, Object[] sequence) { checkIsNotNull(sequence); assertNotNull(info, actual); files.assertIsFile(info, actual); files.assertExists(info, actual); // if both actual and values are empty, then assertion passes. if (FileUtils.sizeOf(actual) == 0 && sequence.length == 0) { return true; } failIfEmptySinceActualIsNotEmpty(sequence); return false; }
public <T> void assertDoesNotContainAnyElementsOf(AssertionInfo info, Object[] actual, Iterable<? extends T> iterable) { checkIsNotNullAndNotEmpty(iterable); List<T> values = newArrayList(iterable); assertDoesNotContain(info, actual, values.toArray()); }
/** * Asserts that the line count of the given {@code CharSequence} is equal to the expected one. * * @param info contains information about the assertion. * @param actual the given {@code CharSequence}. * @param expectedLineCount the expected line count of {@code actual}. * @throws AssertionError if the given {@code CharSequence} is {@code null}. * @throws AssertionError if the line count of the given {@code CharSequence} is different than the expected one. */ public void assertHasLineCount(AssertionInfo info, CharSequence actual, int expectedLineCount) { assertNotNull(info, actual); LineNumberReader reader = new LineNumberReader(new StringReader(actual.toString())); try { while (reader.readLine() != null); } catch (IOException e) { throw new InputStreamsException(format("Unable to count lines in `%s`", actual), e); } checkLineCounts(actual, reader.getLineNumber(), expectedLineCount, info); }
public static void hasSameSizeAsCheck(AssertionInfo info, Object actual, Object other, int sizeOfActual) { checkOtherIsNotNull(other, "Array"); checkSameSizes(info, actual, sizeOfActual, Array.getLength(other)); }
private void checkNotNullIterables(AssertionInfo info, Iterable<?> actual, Object[] sequence) { checkIsNotNull(sequence); assertNotNull(info, actual); }
/** * Asserts that the actual value is not close to the expected one by less than the given offset. * * @param info contains information about the assertion. * @param actual the actual value. * @param expected the value to compare actual too. * @param offset the given positive offset. */ public void assertIsNotCloseTo(final AssertionInfo info, final NUMBER actual, final NUMBER expected, final Offset<NUMBER> offset) { assertNotNull(info, actual); checkOffsetIsNotNull(offset); checkNumberIsNotNull(expected); NUMBER diff = absDiff(actual, expected); // with strict offset and actual == other => too close ! if (offset.strict && isGreaterThanOrEqualTo(diff, offset.value)) return; // with non strict offset and actual == other => too close ! if (!offset.strict && !areEqual(actual, expected)) { if (isGreaterThan(diff, offset.value)) return; } throw failures.failure(info, shouldNotBeEqual(actual, expected, offset, diff)); }
private boolean commonCheckThatIterableAssertionSucceeds(AssertionInfo info, Iterable<?> actual, Object[] sequence) { checkIsNotNull(sequence); assertNotNull(info, actual); // if both actual and values are empty, then assertion passes. if (!actual.iterator().hasNext() && sequence.length == 0) return true; failIfEmptySinceActualIsNotEmpty(sequence); return false; }
/** * Asserts that the actual value is not close to the an offset expressed as an percentage value. * * @param info contains information about the assertion. * @param actual the actual value. * @param other the expected value. * @param percentage the given positive percentage. */ public void assertIsNotCloseToPercentage(final AssertionInfo info, final NUMBER actual, final NUMBER other, final Percentage percentage) { assertNotNull(info, actual); checkPercentageIsNotNull(percentage); checkNumberIsNotNull(other); double diff = abs(percentage.value * other.doubleValue() / 100d); boolean areEqual = areEqual(actual, other); if (!areEqual && Double.isInfinite(diff)) return; if (absDiff(actual, other).doubleValue() <= diff || areEqual) throw failures.failure(info, shouldNotBeEqualWithinPercentage(actual, other, percentage, absDiff(actual, other))); }
/** * Asserts that the given {@code Iterable} does not contain the given values. * * @param <T> the type of actual elements * @param info contains information about the assertion. * @param actual the given {@code Iterable}. * @param iterable the values that are expected not to be in the given {@code Iterable}. * @throws NullPointerException if the array of values is {@code null}. * @throws IllegalArgumentException if the array of values is empty. * @throws AssertionError if the given {@code Iterable} is {@code null}. * @throws AssertionError if the given {@code Iterable} contains any of given values. */ public <T> void assertDoesNotContainAnyElementsOf(AssertionInfo info, Iterable<? extends T> actual, Iterable<? extends T> iterable) { checkIsNotNullAndNotEmpty(iterable); List<T> values = newArrayList(iterable); assertDoesNotContain(info, actual, values.toArray()); }
/** * Asserts that the line count of the given {@code CharSequence} is equal to the expected one. * * @param info contains information about the assertion. * @param actual the given {@code CharSequence}. * @param expectedLineCount the expected line count of {@code actual}. * @throws AssertionError if the given {@code CharSequence} is {@code null}. * @throws AssertionError if the line count of the given {@code CharSequence} is different than the expected one. */ public void assertHasLineCount(AssertionInfo info, CharSequence actual, int expectedLineCount) { assertNotNull(info, actual); LineNumberReader reader = new LineNumberReader(new StringReader(actual.toString())); try { while (reader.readLine() != null); } catch (IOException e) { throw new InputStreamsException(format("Unable to count lines in `%s`", actual), e); } checkLineCounts(actual, reader.getLineNumber(), expectedLineCount, info); }
public static void hasSameSizeAsCheck(AssertionInfo info, Object actual, Map<?, ?> other, int sizeOfActual) { checkOtherIsNotNull(other, "Map"); checkSameSizes(info, actual, sizeOfActual, other.size()); }
static void checkIsNotNullAndNotEmpty(Object[] values) { checkIsNotNull(values); checkIsNotEmpty(values); }
public void assertContainsSubsequence(AssertionInfo info, Iterable<?> actual, List<?> subsequence) { checkIsNotNull(subsequence); assertContainsSubsequence(info, actual, subsequence.toArray()); }