Skip to content

Commit 8bd594f

Browse files
author
John Keyes
committed
- added test for maximum date
git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/cli/trunk@191209 13f79535-47bb-0310-9956-ffa450edef68
1 parent 2e9586d commit 8bd594f

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

src/test/org/apache/commons/cli2/validation/DateValidatorTest.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,35 @@ public void testMinimumBounds() throws InvalidArgumentException {
7777
}
7878
}
7979
}
80+
81+
public void testMaximumBounds() throws InvalidArgumentException {
82+
final DateValidator validator = new DateValidator(formats);
83+
final Calendar cal = Calendar.getInstance();
84+
85+
{
86+
final Object[] array = new Object[] { "23/12/03", "2002-10-12" };
87+
final List list = Arrays.asList(array);
88+
cal.set(2004, 1, 12);
89+
final Date max = cal.getTime();
90+
validator.setMaximum(max);
91+
validator.validate(list);
92+
}
93+
94+
{
95+
final Object[] array = new Object[] { "23/12/03", "2004-10-12" };
96+
final List list = Arrays.asList(array);
97+
cal.set(2004, 1, 12);
98+
final Date max = cal.getTime();
99+
validator.setMaximum(max);
100+
101+
try {
102+
validator.validate(list);
103+
fail("maximum out of bounds exception not caught");
104+
}
105+
catch (final InvalidArgumentException exp) {
106+
assertEquals("Out of range: 2004-10-12", exp.getMessage());
107+
}
108+
}
109+
}
110+
80111
}

0 commit comments

Comments
 (0)