/** * used to check that the start of period date to compare actual date to is not null, in that case throws a * {@link NullPointerException} with an explicit message * @param start the start date to check * @throws NullPointerException with an explicit message if the given start date is null */ private static void startDateParameterIsNotNull(Date start) { checkNotNull(start, "The start date of period to compare actual with should not be null"); }
/** * used to check that the class to compare is not null, in that case throws a {@link NullPointerException} with an * explicit message. * * @param clazz the date to check * @throws NullPointerException with an explicit message if the given class is null */ private static void classParameterIsNotNull(Class<?> clazz) { checkNotNull(clazz, "The class to compare actual with should not be null"); } }
/** * used to check that the end of period date to compare actual date to is not null, in that case throws a * {@link NullPointerException} with an explicit message * @param end the end date to check * @throws NullPointerException with an explicit message if the given end date is null */ private static void endDateParameterIsNotNull(Date end) { checkNotNull(end, "The end date of period to compare actual with should not be null"); }
/** * used to check that the date to compare actual date to is not null, in that case throws a {@link NullPointerException} with an * explicit message * @param date the date to check * @throws NullPointerException with an explicit message if the given date is null */ private static void dateParameterIsNotNull(Date date) { checkNotNull(date, "The date to compare actual with should not be null"); }
/** * Asserts the given <code>{@link Condition}</code> is not null. * @param condition the given {@code Condition}. * @param format as in {@link String#format(String, Object...)} * @param args as in {@link String#format(String, Object...)} * @throws NullPointerException if the given {@code Condition} is {@code null}. */ public void assertIsNotNull(Condition<?> condition, String format, Object... args) { checkNotNull(condition, format(format, args)); } }
static void checkIndexValueIsValid(Index index, int maximum) { checkNotNull(index, "Index should not be null"); if (index.value <= maximum) return; String errorMessage = "Index should be between <0> and <%d> (inclusive) but was:%n <%d>"; throw new IndexOutOfBoundsException(format(errorMessage, maximum, index.value)); }
private void checkCharSequenceArrayDoesNotHaveNullElements(CharSequence[] values) { if (values.length == 1) { checkCharSequenceIsNotNull(values[0]); } else { for (int i = 0; i < values.length; i++) { checkNotNull(values[i], "Expecting CharSequence elements not to be null but found one at index " + i); } } }
/** * Creates a new <code>{@link Join}</code>. * @param conditions the conditions to join. * @throws NullPointerException if the given array is {@code null}. * @throws NullPointerException if any of the elements in the given array is {@code null}. */ @SafeVarargs protected Join(Condition<? super T>... conditions) { checkNotNull(conditions, conditionsIsNull()); this.conditions = Arrays.stream(conditions).map(Join::notNull).collect(toList()); }
public void assertHasDigest(AssertionInfo info, File actual, String algorithm, byte[] expected) { checkNotNull(algorithm, "The message digest algorithm should not be null"); try { assertHasDigest(info, actual, MessageDigest.getInstance(algorithm), expected); } catch (NoSuchAlgorithmException e) { throw new IllegalStateException(format("Unable to find digest implementation for: <%s>", algorithm), e); } }
public static String toHex(byte[] digest) { checkNotNull(digest, "The digest should not be null"); StringBuilder hex = new StringBuilder(digest.length * 2); for (byte b : digest) { hex.append(byteToHexString(b)); } return hex.toString(); }
/** * Returns the size of the given {@link Iterable}. * * @param iterable the {@link Iterable} to get size. * @return the size of the given {@link Iterable}. * @throws NullPointerException if given {@link Iterable} is null. */ public static int sizeOf(Iterable<?> iterable) { checkNotNull(iterable, "Iterable must not be null"); if (iterable instanceof Collection) return ((Collection<?>) iterable).size(); return Math.toIntExact(Streams.stream(iterable).count()); }
public void assertHasDigest(AssertionInfo info, InputStream actual, String algorithm, byte[] expected) { checkNotNull(algorithm, "The message digest algorithm should not be null"); try { assertHasDigest(info, actual, MessageDigest.getInstance(algorithm), expected); } catch (NoSuchAlgorithmException e) { throw new IllegalStateException(format("Unable to find digest implementation for: <%s>", algorithm), e); } }
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)); }
/** * Creates a new <code>{@link Join}</code>. * @param conditions the conditions to join. * @throws NullPointerException if the given iterable is {@code null}. * @throws NullPointerException if any of the elements in the given iterable is {@code null}. */ protected Join(Iterable<? extends Condition<? super T>> conditions) { checkNotNull(conditions, conditionsIsNull()); this.conditions = new ArrayList<>(); for (Condition<? super T> condition : conditions) this.conditions.add(notNull(condition)); }
public void assertHasDigest(AssertionInfo info, Path actual, String algorithm, String expected) { checkNotNull(expected, "The string representation of digest to compare to should not be null"); assertHasDigest(info, actual, algorithm, Digests.fromHex(expected)); } }
public void assertHasDigest(AssertionInfo info, File actual, String algorithm, String expected) { checkNotNull(expected, "The string representation of digest to compare to should not be null"); assertHasDigest(info, actual, algorithm, Digests.fromHex(expected)); } }
public void assertHasDigest(AssertionInfo info, InputStream actual, String algorithm, String expected) { checkNotNull(expected, "The string representation of digest to compare to should not be null"); assertHasDigest(info, actual, algorithm, Digests.fromHex(expected)); } }
public void assertHasDigest(AssertionInfo info, InputStream actual, MessageDigest digest, byte[] expected) { checkNotNull(digest, "The message digest algorithm should not be null"); checkNotNull(expected, "The binary representation of digest to compare to should not be null"); assertNotNull(info, actual); try { DigestDiff diff = digestDiff(actual, digest, expected); if (diff.digestsDiffer()) throw failures.failure(info, shouldHaveDigest(actual, diff)); } catch (IOException e) { String msg = format("Unable to calculate digest of InputStream:%n <%s>", actual); throw new InputStreamsException(msg, e); } }
public void assertHasBinaryContent(AssertionInfo info, Path actual, byte[] expected) { checkNotNull(expected, "The binary content to compare to should not be null"); assertIsReadable(info, actual); try { BinaryDiffResult diffResult = binaryDiff.diff(actual, expected); if (diffResult.hasNoDiff()) return; throw failures.failure(info, shouldHaveBinaryContent(actual, diffResult)); } catch (IOException e) { throw new UncheckedIOException(format("Unable to verify binary contents of path:<%s>", actual), e); } }
public void assertHasSuppressedException(AssertionInfo info, Throwable actual, Throwable expectedSuppressedException) { assertNotNull(info, actual); checkNotNull(expectedSuppressedException, "The expected suppressed exception should not be null"); Throwable[] suppressed = actual.getSuppressed(); for (int i = 0; i < suppressed.length; i++) { if (compareThrowable(suppressed[i], expectedSuppressedException)) return; } throw failures.failure(info, shouldHaveSuppressedException(actual, expectedSuppressedException)); }