File: simple.java

package info (click to toggle)
mauve 20080616-1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 26,856 kB
  • ctags: 21,952
  • sloc: java: 234,107; sh: 2,834; xml: 208; makefile: 59
file content (57 lines) | stat: -rw-r--r-- 1,493 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// Tags: JDK1.1

// Copyright (c) 2001  Jeff Sturm

// This file is part of Mauve.

package gnu.testlet.java.util.Calendar;

import gnu.testlet.Testlet;
import gnu.testlet.TestHarness;
import java.text.*;
import java.util.*;

public class simple implements Testlet
{
  public void test (TestHarness harness)
  {
    DateFormat format = new SimpleDateFormat("MM/dd/yyyy");
    Calendar calendar = Calendar.getInstance();

    Date date;
    try
      {
	date = format.parse("04/30/2001");
      }
    catch (ParseException _)
      {
	harness.debug (_);
	harness.fail ("couldn't run any tests");
	return;
      }

    calendar.setTime(date);
    harness.check (format.format(date), "04/30/2001");

    harness.check ("weekday = " + calendar.get(Calendar.DAY_OF_WEEK),
		   "weekday = 2");

    calendar.add(Calendar.DATE, 1);
    date = calendar.getTime();
    harness.check (format.format (date), "05/01/2001");

    harness.check ("weekday = " + calendar.get(Calendar.DAY_OF_WEEK),
		   "weekday = 3");

    calendar.add(Calendar.MONTH, 1);
    date = calendar.getTime();
    harness.check (format.format(date), "06/01/2001");

    // Although this looks reasonable, and it does work in the JDK, it
    // isn't actually guaranteed to work.  In fact, incrementing MONTH
    // and then looking at DAY_OF_WEEK is the example in the 1.2
    // online docs which shows that this may not work.
    // harness.check ("weekday = " + calendar.get(Calendar.DAY_OF_WEEK),
    // "weekday = 6");
  }
}