DateBoundary extends AbstractBoundary { @Override public String outOfBoundary(int restrictionAttribute, String value) { switch (restrictionAttribute) { case MAX_EXCLISIVE: return BoundaryUtils.createDate(value, (int) (Math.random() * OFFSET), simpleDateFormat.get()); case MIN_EXCLISIVE: return BoundaryUtils.createDate(value, -(int) (Math.random() * OFFSET), simpleDateFormat.get()); case MAX_INCLISIVE: return BoundaryUtils.createDate(value, (int) (Math.random() * OFFSET + 1), simpleDateFormat.get()); case MIN_INCLISIVE: return BoundaryUtils.createDate(value, (-(int) (Math.random() * OFFSET) - 1), simpleDateFormat.get()); default: return null; } }  @Override String outOfBoundary(int restrictionAttribute, String value); static final String DATE_FORMAT; }
@Test public void testOutOfBoundaryMinExclusive() throws ParseException { String outOfBoundaryDate = dateBoundary.outOfBoundary(Boundary.MIN_EXCLISIVE, today); Calendar calendar1 = Calendar.getInstance(); Calendar calendar2 = Calendar.getInstance(); calendar1.setTime(DateTimeBoundary.simpleDateFormat.get().parse(outOfBoundaryDate)); calendar2.setTime(DateTimeBoundary.simpleDateFormat.get().parse(today)); assertTrue(calendar1.before(calendar2) || calendar1.equals(calendar2)); }
@Test public void testOutOfBoundaryMaxExclusive() throws ParseException { String outOfBoundaryDate = dateBoundary.outOfBoundary(Boundary.MAX_EXCLISIVE, today); Calendar calendar1 = Calendar.getInstance(); Calendar calendar2 = Calendar.getInstance(); calendar1.setTime(DateTimeBoundary.simpleDateFormat.get().parse(outOfBoundaryDate)); calendar2.setTime(DateTimeBoundary.simpleDateFormat.get().parse(today)); assertTrue(calendar1.after(calendar2) || calendar1.equals(calendar2)); }
@Test public void testOutOfBoundaryMinInclusive() throws ParseException { String outOfBoundaryDate = dateBoundary.outOfBoundary(Boundary.MIN_INCLISIVE, today); Calendar calendar1 = Calendar.getInstance(); Calendar calendar2 = Calendar.getInstance(); calendar1.setTime(DateTimeBoundary.simpleDateFormat.get().parse(outOfBoundaryDate)); calendar2.setTime(DateTimeBoundary.simpleDateFormat.get().parse(today)); assertTrue(calendar1.before(calendar2)); }
@Test public void testOutOfBoundaryMaxInclusive() throws ParseException { String outOfBoundaryDate = dateBoundary.outOfBoundary(Boundary.MAX_INCLISIVE, today); Calendar calendar1 = Calendar.getInstance(); Calendar calendar2 = Calendar.getInstance(); calendar1.setTime(DateTimeBoundary.simpleDateFormat.get().parse(outOfBoundaryDate)); calendar2.setTime(DateTimeBoundary.simpleDateFormat.get().parse(today)); assertTrue(calendar1.after(calendar2)); }