TeradataDatePeriod extends DbStruct { @Override public boolean equals(Object other) { if (other == null) return false; if (!(other instanceof TeradataDatePeriod)) return false; TeradataDatePeriod odp = (TeradataDatePeriod)other; Object[] thisAtts = null; Object[] otherAtts = null; try { otherAtts = odp.getAttributes(); thisAtts = this.getAttributes(); } catch (SQLException e) { System.out.println("TeradataDatePeriod: equal: caught exception"); } if (!(thisAtts[0].equals(otherAtts[0]))) return false; if (!(thisAtts[1].equals(otherAtts[1]))) return false; return true; } TeradataDatePeriod(Object[] dates); @Override String toString(); @Override boolean equals(Object other);  }
@Test public void equalsTest() { String fromStr = "2012-11-11"; String toStr = "2014-06-02"; DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); Date fromDate = null; Date toDate = null; try { fromDate = dateFormat.parse(fromStr); toDate = dateFormat.parse(toStr); } catch (ParseException e) { throw new Error("TeradataDatePeriodTest: toStringTest: error parsing test input"); } Date[] range = {fromDate, toDate}; TeradataDatePeriod tdp = new TeradataDatePeriod(range); TeradataDatePeriod tdp2 = new TeradataDatePeriod(range); assertTrue("Date periods are not equal", tdp.equals(tdp2)); }
@Test public void notEqualsTest() { String fromStr = "2012-11-11"; String toStr = "2014-06-02"; DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); Date fromDate = null; Date toDate = null; try { fromDate = dateFormat.parse(fromStr); toDate = dateFormat.parse(toStr); } catch (ParseException e) { throw new Error("TeradataDatePeriodTest: toStringTest: error parsing test input"); } Date[] range = {fromDate, toDate}; TeradataDatePeriod tdp = new TeradataDatePeriod(range); Date[] range2 = {fromDate, fromDate}; TeradataDatePeriod tdp2 = new TeradataDatePeriod(range2); assertFalse("Date periods are equal", tdp.equals(tdp2)); }