Use annotation based checking for expected exceptions
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@1671690 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
8ea1aa1e7c
commit
d4c7f63054
|
@ -37,9 +37,6 @@ import java.util.NoSuchElementException;
|
||||||
import java.util.TimeZone;
|
import java.util.TimeZone;
|
||||||
|
|
||||||
import junit.framework.AssertionFailedError;
|
import junit.framework.AssertionFailedError;
|
||||||
|
|
||||||
import org.apache.commons.lang3.SystemUtils;
|
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
@ -164,10 +161,11 @@ public class DateUtilsTest {
|
||||||
assertTrue(DateUtils.isSameDay(datea, dateb));
|
assertTrue(DateUtils.isSameDay(datea, dateb));
|
||||||
dateb = new GregorianCalendar(2005, 6, 10, 13, 45).getTime();
|
dateb = new GregorianCalendar(2005, 6, 10, 13, 45).getTime();
|
||||||
assertFalse(DateUtils.isSameDay(datea, dateb));
|
assertFalse(DateUtils.isSameDay(datea, dateb));
|
||||||
try {
|
}
|
||||||
|
|
||||||
|
@Test(expected = IllegalArgumentException.class)
|
||||||
|
public void testIsDameDay_DateNullNull() throws Exception {
|
||||||
DateUtils.isSameDay((Date) null, (Date) null);
|
DateUtils.isSameDay((Date) null, (Date) null);
|
||||||
fail();
|
|
||||||
} catch (final IllegalArgumentException ex) {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
|
@ -182,10 +180,11 @@ public class DateUtilsTest {
|
||||||
assertTrue(DateUtils.isSameDay(cala, calb));
|
assertTrue(DateUtils.isSameDay(cala, calb));
|
||||||
calb.add(Calendar.YEAR, 1);
|
calb.add(Calendar.YEAR, 1);
|
||||||
assertFalse(DateUtils.isSameDay(cala, calb));
|
assertFalse(DateUtils.isSameDay(cala, calb));
|
||||||
try {
|
}
|
||||||
|
|
||||||
|
@Test(expected = IllegalArgumentException.class)
|
||||||
|
public void testIsSameDay_CalNullNull() throws Exception {
|
||||||
DateUtils.isSameDay((Calendar) null, (Calendar) null);
|
DateUtils.isSameDay((Calendar) null, (Calendar) null);
|
||||||
fail();
|
|
||||||
} catch (final IllegalArgumentException ex) {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
|
@ -200,10 +199,11 @@ public class DateUtilsTest {
|
||||||
assertTrue(DateUtils.isSameInstant(datea, dateb));
|
assertTrue(DateUtils.isSameInstant(datea, dateb));
|
||||||
dateb = new GregorianCalendar(2005, 6, 10, 13, 45).getTime();
|
dateb = new GregorianCalendar(2005, 6, 10, 13, 45).getTime();
|
||||||
assertFalse(DateUtils.isSameInstant(datea, dateb));
|
assertFalse(DateUtils.isSameInstant(datea, dateb));
|
||||||
try {
|
}
|
||||||
|
|
||||||
|
@Test(expected = IllegalArgumentException.class)
|
||||||
|
public void testIsSameInstant_DateNullNull() throws Exception {
|
||||||
DateUtils.isSameInstant((Date) null, (Date) null);
|
DateUtils.isSameInstant((Date) null, (Date) null);
|
||||||
fail();
|
|
||||||
} catch (final IllegalArgumentException ex) {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
|
@ -219,10 +219,11 @@ public class DateUtilsTest {
|
||||||
|
|
||||||
calb.set(2004, 6, 9, 11, 45, 0);
|
calb.set(2004, 6, 9, 11, 45, 0);
|
||||||
assertTrue(DateUtils.isSameInstant(cala, calb));
|
assertTrue(DateUtils.isSameInstant(cala, calb));
|
||||||
try {
|
}
|
||||||
|
|
||||||
|
@Test(expected = IllegalArgumentException.class)
|
||||||
|
public void testIsSameInstant_CalNullNull() throws Exception {
|
||||||
DateUtils.isSameInstant((Calendar) null, (Calendar) null);
|
DateUtils.isSameInstant((Calendar) null, (Calendar) null);
|
||||||
fail();
|
|
||||||
} catch (final IllegalArgumentException ex) {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
|
@ -246,10 +247,11 @@ public class DateUtilsTest {
|
||||||
|
|
||||||
calb.set(2004, 6, 9, 11, 45, 0);
|
calb.set(2004, 6, 9, 11, 45, 0);
|
||||||
assertFalse(DateUtils.isSameLocalTime(cala, calb));
|
assertFalse(DateUtils.isSameLocalTime(cala, calb));
|
||||||
try {
|
}
|
||||||
|
|
||||||
|
@Test(expected = IllegalArgumentException.class)
|
||||||
|
public void testIsSameLocalTime_CalNullNull() throws Exception {
|
||||||
DateUtils.isSameLocalTime((Calendar) null, (Calendar) null);
|
DateUtils.isSameLocalTime((Calendar) null, (Calendar) null);
|
||||||
fail();
|
|
||||||
} catch (final IllegalArgumentException ex) {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
|
@ -268,27 +270,34 @@ public class DateUtilsTest {
|
||||||
dateStr = "19721203";
|
dateStr = "19721203";
|
||||||
date = DateUtils.parseDate(dateStr, parsers);
|
date = DateUtils.parseDate(dateStr, parsers);
|
||||||
assertEquals(cal.getTime(), date);
|
assertEquals(cal.getTime(), date);
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
@Test(expected = ParseException.class)
|
||||||
|
public void testParseDate_NoDateString() throws Exception {
|
||||||
|
final String[] parsers = new String[] {"yyyy'-'DDD", "yyyy'-'MM'-'dd", "yyyyMMdd"};
|
||||||
DateUtils.parseDate("PURPLE", parsers);
|
DateUtils.parseDate("PURPLE", parsers);
|
||||||
fail();
|
}
|
||||||
} catch (final ParseException ex) {}
|
|
||||||
try {
|
@Test(expected = ParseException.class)
|
||||||
|
public void testParseDate_InvalidDateString() throws Exception {
|
||||||
|
final String[] parsers = new String[] {"yyyy'-'DDD", "yyyy'-'MM'-'dd", "yyyyMMdd"};
|
||||||
DateUtils.parseDate("197212AB", parsers);
|
DateUtils.parseDate("197212AB", parsers);
|
||||||
fail();
|
}
|
||||||
} catch (final ParseException ex) {}
|
|
||||||
try {
|
@Test(expected = IllegalArgumentException.class)
|
||||||
|
public void testParseDate_Null() throws Exception {
|
||||||
|
final String[] parsers = new String[] {"yyyy'-'DDD", "yyyy'-'MM'-'dd", "yyyyMMdd"};
|
||||||
DateUtils.parseDate(null, parsers);
|
DateUtils.parseDate(null, parsers);
|
||||||
fail();
|
}
|
||||||
} catch (final IllegalArgumentException ex) {}
|
|
||||||
try {
|
@Test(expected = IllegalArgumentException.class)
|
||||||
DateUtils.parseDate(dateStr, (String[]) null);
|
public void testParse_NullParsers() throws Exception {
|
||||||
fail();
|
DateUtils.parseDate("19721203", (String[]) null);
|
||||||
} catch (final IllegalArgumentException ex) {}
|
}
|
||||||
try {
|
|
||||||
DateUtils.parseDate(dateStr, new String[0]);
|
@Test(expected = ParseException.class)
|
||||||
fail();
|
public void testParse_EmptyParsers() throws Exception {
|
||||||
} catch (final ParseException ex) {}
|
DateUtils.parseDate("19721203");
|
||||||
}
|
}
|
||||||
|
|
||||||
// LANG-486
|
// LANG-486
|
||||||
|
|
Loading…
Reference in New Issue