View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  
18  package org.apache.commons.lang3.time;
19  
20  import static org.junit.jupiter.api.Assertions.assertEquals;
21  
22  import java.util.Calendar;
23  import java.util.Locale;
24  
25  import org.apache.commons.lang3.AbstractLangTest;
26  import org.junit.jupiter.api.Test;
27  
28  public class CalendarUtilsTest extends AbstractLangTest {
29  
30      @Test
31      public void testGetDayOfMonth() {
32          assertEquals(Calendar.getInstance().get(Calendar.DAY_OF_MONTH), CalendarUtils.getInstance().getDayOfMonth());
33      }
34  
35      @Test
36      public void testGetDayOfYear() {
37          assertEquals(Calendar.getInstance().get(Calendar.DAY_OF_YEAR), CalendarUtils.getInstance().getDayOfYear());
38      }
39  
40      @Test
41      public void testGetMonth() {
42          assertEquals(Calendar.getInstance().get(Calendar.MONTH), CalendarUtils.getInstance().getMonth());
43      }
44  
45      @Test
46      public void testGetStandaloneLongMonthNames() {
47          final String[] monthNames = CalendarUtils.getInstance(Locale.GERMAN).getStandaloneLongMonthNames();
48          assertEquals(12, monthNames.length);
49          assertEquals("Januar", monthNames[0]);
50          assertEquals("Februar", monthNames[1]);
51          assertEquals("M\u00e4rz", monthNames[2]);
52          assertEquals("April", monthNames[3]);
53          assertEquals("Mai", monthNames[4]);
54          assertEquals("Juni", monthNames[5]);
55          assertEquals("Juli", monthNames[6]);
56          assertEquals("August", monthNames[7]);
57          assertEquals("September", monthNames[8]);
58          assertEquals("Oktober", monthNames[9]);
59          assertEquals("November", monthNames[10]);
60          assertEquals("Dezember", monthNames[11]);
61      }
62  
63      @Test
64      public void testGetStandaloneShortMonthNames() {
65          final String[] monthNames = CalendarUtils.getInstance(Locale.GERMAN).getStandaloneShortMonthNames();
66          assertEquals(12, monthNames.length);
67          assertEquals("Jan", monthNames[0]);
68          assertEquals("Feb", monthNames[1]);
69          assertEquals("M\u00e4r", monthNames[2]);
70          assertEquals("Apr", monthNames[3]);
71          assertEquals("Mai", monthNames[4]);
72          assertEquals("Jun", monthNames[5]);
73          assertEquals("Jul", monthNames[6]);
74          assertEquals("Aug", monthNames[7]);
75          assertEquals("Sep", monthNames[8]);
76          assertEquals("Okt", monthNames[9]);
77          assertEquals("Nov", monthNames[10]);
78          assertEquals("Dez", monthNames[11]);
79      }
80  
81      @Test
82      public void testGetYear() {
83          assertEquals(Calendar.getInstance().get(Calendar.YEAR), CalendarUtils.INSTANCE.getYear());
84      }
85  
86  }