/** * 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"); } }
/** * Check that the {@link LocalDate} to compare actual {@link LocalDate} to is not null, in that case throws a * {@link IllegalArgumentException} with an explicit message * * @param other the {@link LocalDate} to check * @throws IllegalArgumentException with an explicit message if the given {@link LocalDate} is null */ private static void assertLocalDateParameterIsNotNull(LocalDate other) { checkArgument(other != null, NULL_LOCAL_DATE_TIME_PARAMETER_MESSAGE); }
/** * Verifies that the given {@code CharSequence} is not {@code null} or empty. * * @param s the given {@code CharSequence}. * @return the validated {@code CharSequence}. * @throws NullPointerException if the given {@code CharSequence} is {@code null}. * @throws IllegalArgumentException if the given {@code CharSequence} is empty. */ public static CharSequence checkNotNullOrEmpty(CharSequence s) { return checkNotNullOrEmpty(s, ARGUMENT_EMPTY); }
/** * Verifies that the given array is not {@code null} or empty. * * @param <T> the type of elements of the array. * @param array the given array. * @return the validated array. * @throws NullPointerException if the given array is {@code null}. * @throws IllegalArgumentException if the given array is empty. */ public static <T> T[] checkNotNullOrEmpty(T[] array) { T[] checked = checkNotNull(array); if (checked.length == 0) throwExceptionForBeingEmpty(); return checked; }
/** * Returns result of given method invocation on provided object. * <p> * Following requirements have to be met to extract method results: * <ul> * <li>method has to be public,</li> * <li>method cannot accept any arguments,</li> * <li>method cannot return void.</li> * </ul> * * @param instance object on which * @param methodName name of method to be invoked * @return result of method invocation * @throws IllegalArgumentException if method does not exist or is not public, method returns void or method accepts * any argument */ public static Object methodResultFor(Object instance, String methodName) { checkNotNull(instance, "Object instance can not be null!"); checkNotNullOrEmpty(methodName, "Method name can not be empty!"); Method method = findMethod(methodName, instance.getClass()); return invokeMethod(instance, method); }
checkArgument(path != null, "path is null"); checkArgument(orig != null, "original sequence is null"); checkArgument(rev != null, "revised sequence is null"); path = path.prev; while (path != null && path.prev != null && path.prev.j >= 0) { checkState(!path.isSnake(), "bad diffpath: found snake when looking for diff"); int i = path.i; int j = path.j;
private static void throwExceptionForBeingEmpty() { throwExceptionForBeingEmpty(ARGUMENT_EMPTY); }
private static Object actual(Object result) { checkState(result instanceof AbstractAssert, "We should be trying to make a proxy of an *Assert class but it was: %s", result.getClass()); return ((AbstractAssert<?, ?>) result).actual; }
/** * Returns the getter {@link Method} for a property matching the given name in the given object. * * @param propertyName the given property name. * @param target the given object. * @return the getter {@code Method} for a property matching the given name in the given object. * @throws NullPointerException if the given property name is {@code null}. * @throws IllegalArgumentException if the given property name is empty. * @throws NullPointerException if the given object is {@code null}. * @throws IntrospectionError if the getter for the matching property cannot be found or accessed. */ public static Method getPropertyGetter(String propertyName, Object target) { checkNotNullOrEmpty(propertyName); checkNotNull(target); Method getter; try { getter = findGetter(propertyName, target); if (Modifier.isPublic(getter.getModifiers())) { // force access for static class with public getter getter.setAccessible(true); } getter.invoke(target); } catch (Exception t) { throw new IntrospectionError(propertyNotFoundErrorMessage(propertyName, target), t); } return getter; }
/** * Verifies that the given {@code CharSequence} is not {@code null} or empty. * * @param s the given {@code CharSequence}. * @param message error message in case of empty {@code String}. * @return the validated {@code CharSequence}. * @throws NullPointerException if the given {@code CharSequence} is {@code null}. * @throws IllegalArgumentException if the given {@code CharSequence} is empty. */ public static CharSequence checkNotNullOrEmpty(CharSequence s, String message) { checkNotNull(s, message); if (s.length() == 0) throwExceptionForBeingEmpty(message); return s; }
checkArgument(path != null, "path is null"); checkArgument(orig != null, "original sequence is null"); checkArgument(rev != null, "revised sequence is null"); path = path.prev; while (path != null && path.prev != null && path.prev.j >= 0) { checkState(!path.isSnake(), "bad diffpath: found snake when looking for diff"); int i = path.i; int j = path.j;
private static void throwExceptionForBeingEmpty() { throwExceptionForBeingEmpty(ARGUMENT_EMPTY); }
private static Object actual(Object result) { checkState(result instanceof AbstractAssert, "We should be trying to make a proxy of an *Assert class but it was: %s", result.getClass()); return ((AbstractAssert<?, ?>) result).actual; }
/** * 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"); }
/** * Returns result of given method invocation on provided object. * <p> * Following requirements have to be met to extract method results: * <ul> * <li>method has to be public,</li> * <li>method cannot accept any arguments,</li> * <li>method cannot return void.</li> * </ul> * * @param instance object on which * @param methodName name of method to be invoked * @return result of method invocation * @throws IllegalArgumentException if method does not exist or is not public, method returns void or method accepts * any argument */ public static Object methodResultFor(Object instance, String methodName) { checkNotNull(instance, "Object instance can not be null!"); checkNotNullOrEmpty(methodName, "Method name can not be empty!"); Method method = findMethod(methodName, instance.getClass()); return invokeMethod(instance, method); }
/** * Check that the {@link LocalTime} string representation to compare actual {@link LocalTime} to is not null, * otherwise throws a {@link IllegalArgumentException} with an explicit message * * @param localTimeAsString String representing the {@link LocalTime} to compare actual with * @throws IllegalArgumentException with an explicit message if the given {@link String} is null */ private static void assertLocalTimeAsStringParameterIsNotNull(String localTimeAsString) { checkArgument(localTimeAsString != null, "The String representing the LocalTime to compare actual with should not be null"); }
/** * Verifies that the given array is not {@code null} or empty. * * @param <T> the type of elements of the array. * @param array the given array. * @return the validated array. * @throws NullPointerException if the given array is {@code null}. * @throws IllegalArgumentException if the given array is empty. */ public static <T> T[] checkNotNullOrEmpty(T[] array) { T[] checked = checkNotNull(array); if (checked.length == 0) throwExceptionForBeingEmpty(); return checked; }
/** * Verifies that the given {@code CharSequence} is not {@code null} or empty. * * @param s the given {@code CharSequence}. * @return the validated {@code CharSequence}. * @throws NullPointerException if the given {@code CharSequence} is {@code null}. * @throws IllegalArgumentException if the given {@code CharSequence} is empty. */ public static CharSequence checkNotNullOrEmpty(CharSequence s) { return checkNotNullOrEmpty(s, ARGUMENT_EMPTY); }
private static void throwExceptionForBeingEmpty() { throwExceptionForBeingEmpty(ARGUMENT_EMPTY); }
/** * Verifies that this chunk's saved text matches the corresponding text in * the given sequence. * * @param target * the sequence to verify against. */ public void verify(List<T> target) throws IllegalStateException { checkState(last() <= target.size(), "Incorrect Chunk: the position of chunk > target size"); for (int i = 0; i < size(); i++) { checkState(target.get(position + i).equals(lines.get(i)), "Incorrect Chunk: the chunk content doesn't match the target"); } }