< prev index next >

test/jdk/java/util/Calendar/bug4100311.java

Print this page

 1 /*
 2  * Copyright (c) 1998, 2016, Oracle and/or its affiliates. All rights reserved.
 3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 4  *
 5  * This code is free software; you can redistribute it and/or modify it
 6  * under the terms of the GNU General Public License version 2 only, as
 7  * published by the Free Software Foundation.
 8  *
 9  * This code is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12  * version 2 for more details (a copy is included in the LICENSE file that
13  * accompanied this code).
14  *
15  * You should have received a copy of the GNU General Public License version
16  * 2 along with this work; if not, write to the Free Software Foundation,
17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18  *
19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20  * or visit www.oracle.com if you need additional information or have any
21  * questions.
22  */
23 
24 /*
25  * @test
26  * @bug 4100311
27  * @summary Make sure set(DAY_OF_YEAR, 1) works.

28  */
29 
30 import java.util.Calendar;
31 import java.util.GregorianCalendar;
32 import java.util.Date;
33 
34 public class bug4100311
35 {





36     @SuppressWarnings("deprecation")
37     public static void main(String args[])
38     {
39         GregorianCalendar cal = new GregorianCalendar();
40         cal.set(Calendar.YEAR, 1997);
41         cal.set(Calendar.DAY_OF_YEAR, 1);
42         Date d = cal.getTime();             // Should be Jan 1
43         if (d.getMonth() != 0 || d.getDate() != 1) {
44             throw new RuntimeException("Date isn't Jan 1");
45         }
46     }
47 }

 1 /*
 2  * Copyright (c) 1998, 2023, Oracle and/or its affiliates. All rights reserved.
 3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 4  *
 5  * This code is free software; you can redistribute it and/or modify it
 6  * under the terms of the GNU General Public License version 2 only, as
 7  * published by the Free Software Foundation.
 8  *
 9  * This code is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12  * version 2 for more details (a copy is included in the LICENSE file that
13  * accompanied this code).
14  *
15  * You should have received a copy of the GNU General Public License version
16  * 2 along with this work; if not, write to the Free Software Foundation,
17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18  *
19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20  * or visit www.oracle.com if you need additional information or have any
21  * questions.
22  */
23 
24 /*
25  * @test
26  * @bug 4100311
27  * @summary Ensure set(DAY_OF_YEAR, 1) works.
28  * @run junit bug4100311
29  */
30 
31 import java.util.Calendar;
32 import java.util.GregorianCalendar;
33 import java.util.Date;
34 
35 import org.junit.jupiter.api.Test;
36 
37 import static org.junit.jupiter.api.Assertions.assertEquals;
38 
39 public class bug4100311 {
40 
41     // GregorianCalendar should be able to date to january 1st properly
42     @SuppressWarnings("deprecation")
43     @Test
44     public void dayOfYearIsOneTest() {
45         GregorianCalendar cal = new GregorianCalendar();
46         cal.set(Calendar.YEAR, 1997);
47         cal.set(Calendar.DAY_OF_YEAR, 1);
48         Date d = cal.getTime();
49         assertEquals(0, d.getMonth(), "Date: "+d+" isn't January 1st");
50         assertEquals(1, d.getDate(),"Date: "+d+" isn't January 1st");

51     }
52 }
< prev index next >