33import static org .hamcrest .MatcherAssert .assertThat ;
44import static org .hamcrest .Matchers .is ;
55
6+ import org .junit .Rule ;
67import org .junit .Test ;
8+ import org .junit .rules .ExpectedException ;
79import org .junit .runner .RunWith ;
810import org .robolectric .RobolectricTestRunner ;
911
12+ import java .text .ParseException ;
1013import java .util .Arrays ;
1114import java .util .Calendar ;
1215import java .util .Collection ;
13- import java .util .List ;
1416
1517@ RunWith (RobolectricTestRunner .class )
1618public class DateUtilTest {
1719 private final DateUtil mDateUtil = new DateUtil ();
1820
21+ @ Rule
22+ public final ExpectedException mThrown = ExpectedException .none ();
1923
2024 @ Test
21- public void testParseIncorrectDateFromServerToWidget () throws Exception {
22- final List <String > inputParamList = buildParamsDateFromServerToWidget ();
23- for (String serverDate : inputParamList ) {
24- boolean isIncorrect = false ;
25- try {
26- mDateUtil .convertDateFromServerToWidgetFormat (serverDate );
27- } catch (DateParseException e ) {
28- isIncorrect = true ;
29- }
30- assertThat (isIncorrect , is (true ));
31- }
32- }
33-
34- @ Test
35- public void testParseCorrectDateFromServerToWidget () throws Exception {
25+ public void testConvertDateFromServerToWidgetFormat () throws Exception {
3626 String serverDate = "2005-05-23" ;
3727 String widgetDate = "23 May 2005" ;
3828 assertThat (mDateUtil .convertDateFromServerToWidgetFormat (serverDate ), is (widgetDate ));
29+ }
30+
31+ @ Test
32+ public void testBuildParamsDateFromServerToWidget_whenIncorrectDate () throws Exception {
33+ mThrown .expect (ParseException .class );
34+ mDateUtil .convertDateFromServerToWidgetFormat ("1990-01" );
35+ }
36+
37+ @ Test
38+ public void testConvertDateFromServerToWidgetFormat_whenDateIsNullOrEmpty () throws Exception {
3939 assertThat (mDateUtil .convertDateFromServerToWidgetFormat ("" ), is ("" ));
4040 assertThat (mDateUtil .convertDateFromServerToWidgetFormat (null ), is ("" ));
4141 }
4242
4343 @ Test
44- public void testParseIncorrectDateFromServerToCalendar () throws Exception {
45- List <String > inputParamList = buildParamsDateFromServerToCalendar ();
46- for (String serverDate : inputParamList ) {
47- boolean isIncorrect = false ;
48- try {
49- mDateUtil .convertDateFromServerFormatToCalendar (serverDate ).getTime ();
50- } catch (DateParseException e ) {
51- isIncorrect = true ;
52- }
53- assertThat (isIncorrect , is (true ));
54- }
44+ public void testBuildParamsDateFromServerToCalendar_whenIncorrectDate () throws Exception {
45+ mThrown .expect (ParseException .class );
46+ mDateUtil .convertDateFromServerFormatToCalendar ("123-32" ).getTime ();
5547 }
5648
5749 @ Test
58- public void testParseCorrectDateFromServerToCalendar () throws DateParseException {
50+ public void testConvertDateFromServerFormatToCalendar_whenDateIsNullOrEmpty () throws ParseException {
5951 assertThat (mDateUtil .convertDateFromServerFormatToCalendar (null ).getTime ().toString (),
6052 is (Calendar .getInstance ().getTime ().toString ()));
6153 assertThat (mDateUtil .convertDateFromServerFormatToCalendar ("" ).getTime ().toString (),
6254 is (Calendar .getInstance ().getTime ().toString ()));
55+ }
56+
57+ @ Test
58+ public void testConvertDateFromServerFormatToCalendar () throws ParseException {
6359 String serverDate = "2005-05-23" ;
6460 final Calendar mayCalendar = Calendar .getInstance ();
6561 mayCalendar .set (2005 , 4 , 23 , 0 , 0 , 0 );
@@ -68,7 +64,7 @@ public void testParseCorrectDateFromServerToCalendar() throws DateParseException
6864 }
6965
7066 @ Test
71- public void testParseDateFromDialogToServerFormat () {
67+ public void testBuildDateFromDateDialogToServerFormat () {
7268 String widgetDate ;
7369 int year ;
7470 int month ;
@@ -83,34 +79,6 @@ public void testParseDateFromDialogToServerFormat() {
8379 }
8480 }
8581
86- private List <String > buildParamsDateFromServerToWidget () {
87- return Arrays .asList (
88- "0" ,
89- "1990-01" ,
90- "1990-03-111" ,
91- "10-20-1" ,
92- "2190-13-1" ,
93- "2190-00-1" ,
94- "2190-01-00" ,
95- "2190-01-0" ,
96- "2190-01-32"
97- );
98- }
99-
100- private List <String > buildParamsDateFromServerToCalendar () {
101- return Arrays .asList (
102- "0" ,
103- "1990-01" ,
104- "1990-03-111" ,
105- "10-20-1" ,
106- "19-1102-1" ,
107- "2190-13-1" ,
108- "2190-00-1" ,
109- "2190-01-00" ,
110- "2190-01-0"
111- );
112- }
113-
11482 private Collection <Object []> buildParamsFromDialogToServer () {
11583 return Arrays .asList (new Object [][]{
11684 {1900 , 0 , 1 , "1900-01-01" },
0 commit comments