1 // Tags: JDK1.1 |
|
2 |
|
3 // Copyright (c) 2001 Jeff Sturm |
|
4 |
|
5 // This file is part of Mauve. |
|
6 |
|
7 package gnu.testlet.java.util.Calendar; |
|
8 |
|
9 import gnu.testlet.Testlet; |
|
10 import gnu.testlet.TestHarness; |
|
11 import java.text.*; |
|
12 import java.util.*; |
|
13 |
|
14 public class simple implements Testlet |
|
15 { |
|
16 public void test (TestHarness harness) |
|
17 { |
|
18 DateFormat format = new SimpleDateFormat("MM/dd/yyyy"); |
|
19 Calendar calendar = Calendar.getInstance(); |
|
20 |
|
21 Date date; |
|
22 try |
|
23 { |
|
24 date = format.parse("04/30/2001"); |
|
25 } |
|
26 catch (ParseException _) |
|
27 { |
|
28 harness.debug (_); |
|
29 harness.fail ("couldn't run any tests"); |
|
30 return; |
|
31 } |
|
32 |
|
33 calendar.setTime(date); |
|
34 harness.check (format.format(date), "04/30/2001"); |
|
35 |
|
36 harness.check ("weekday = " + calendar.get(Calendar.DAY_OF_WEEK), |
|
37 "weekday = 2"); |
|
38 |
|
39 calendar.add(Calendar.DATE, 1); |
|
40 date = calendar.getTime(); |
|
41 harness.check (format.format (date), "05/01/2001"); |
|
42 |
|
43 harness.check ("weekday = " + calendar.get(Calendar.DAY_OF_WEEK), |
|
44 "weekday = 3"); |
|
45 |
|
46 calendar.add(Calendar.MONTH, 1); |
|
47 date = calendar.getTime(); |
|
48 harness.check (format.format(date), "06/01/2001"); |
|
49 |
|
50 // Although this looks reasonable, and it does work in the JDK, it |
|
51 // isn't actually guaranteed to work. In fact, incrementing MONTH |
|
52 // and then looking at DAY_OF_WEEK is the example in the 1.2 |
|
53 // online docs which shows that this may not work. |
|
54 // harness.check ("weekday = " + calendar.get(Calendar.DAY_OF_WEEK), |
|
55 // "weekday = 6"); |
|
56 } |
|
57 } |
|