Java Assert Equal assertDatesEqual(Calendar first, Calendar second)

Here you can find the source of assertDatesEqual(Calendar first, Calendar second)

Description

assert Dates Equal

License

Open Source License

Declaration

public static void assertDatesEqual(Calendar first, Calendar second) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    public static void assertDatesEqual(Calendar first, Calendar second) {
        if (first == null && second != null) {
            throw new AssertionError("dates are not equal. first is null, second is not");
        } else if (first != null && second == null) {
            throw new AssertionError("dates are not equal. second is null, first is not");
        }/*from   ww  w .  j  a v a2  s . com*/
        boolean yearsNotEqual = first.get(Calendar.YEAR) != second.get(Calendar.YEAR);
        boolean monthsNotEqual = first.get(Calendar.MONTH) != second.get(Calendar.MONTH);
        boolean daysNotEqual = first.get(Calendar.DAY_OF_MONTH) != second.get(Calendar.DAY_OF_MONTH);
        if (yearsNotEqual || monthsNotEqual || daysNotEqual) {
            StringBuffer buffer = new StringBuffer("dates are not equal. ");
            if (yearsNotEqual) {
                buffer.append(
                        "years (" + first.get(Calendar.YEAR) + ", " + second.get(Calendar.YEAR) + ") not equal.");
            }
            if (monthsNotEqual) {
                buffer.append("months (" + first.get(Calendar.MONTH) + ", " + second.get(Calendar.MONTH)
                        + ") not equal.");
            }
            if (daysNotEqual) {
                buffer.append("days (" + first.get(Calendar.DAY_OF_MONTH) + ", " + second.get(Calendar.DAY_OF_MONTH)
                        + ") not equal.");
            }
            throw new AssertionError(buffer.toString());
        }
    }
}

Related

  1. assertAboveEqual(final double number, final double value)
  2. assertApproxEquals(double a, double b, double relative, double absolute)
  3. assertArrayEquals(double[] p1, double[] p2, double eps)
  4. assertArrayLengthEqual(Object[] array, String name, Object[] array1, String name1)
  5. assertCharacterArraysEqual(char[] first, char[] second)
  6. assertEqual(final double d1, final double d2, final double precisionRange)
  7. assertEqual(Object obj1, Object obj2)
  8. assertEquality(Object original, Object equal, Object... notEqual)
  9. assertEquals(double x, double y)