1 /* 2 * Copyright (c) 2012, 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 7151414 27 * @summary Unit test for calendar types 28 */ 29 30 import java.util.*; 31 32 public class CalendarTypeTest { 33 // Calendar types supported in JRE 34 static Locale[] locales = new Locale[] { 35 Locale.US, 36 Locale.forLanguageTag("th-TH-u-ca-gregory"), 37 new Locale("th", "TH"), 38 Locale.forLanguageTag("en-US-u-ca-buddhist"), 39 new Locale("ja", "JP", "JP"), 40 Locale.forLanguageTag("en-US-u-ca-japanese"), 41 }; 42 static String[] types = new String[] { 43 "gregory", 44 "gregory", 45 "buddhist", 46 "buddhist", 47 "japanese", 48 "japanese", 49 }; 50 51 public static void main(String[] args) { 52 for (int i = 0; i < locales.length; i++) { 53 Calendar cal = Calendar.getInstance(locales[i]); 54 String type = cal.getCalendarType(); 55 checkValue("bad calendar type", type, types[i]); 56 } 57 58 GregorianCalendar gcal = new GregorianCalendar(); 59 checkValue("bad GregorianCalendar type", gcal.getCalendarType(), "gregory"); 60 61 Gregorian g = new Gregorian(); 62 checkValue("bad GregorianCalendar subclass type", g.getCalendarType(), "gregory"); 63 64 Calendar k = new Koyomi(); 65 checkValue("bad class name", k.getCalendarType(), k.getClass().getName()); 66 } 67 68 private static void checkValue(String msg, String got, String expected) { 69 if (!expected.equals(got)) { 70 String str = String.format("%s: got '%s', expected '%s'", msg, got, expected); 71 throw new RuntimeException(str); 72 } 73 } 74 75 private static class Gregorian extends GregorianCalendar { 76 } 77 78 private static class Koyomi extends Calendar { 79 @Override 80 protected void computeTime() { 81 throw new UnsupportedOperationException("Not supported yet."); 82 } 83 84 @Override 85 protected void computeFields() { 86 throw new UnsupportedOperationException("Not supported yet."); 87 } 88 89 @Override 90 public void add(int field, int amount) { 91 throw new UnsupportedOperationException("Not supported yet."); 92 } 93 94 @Override 95 public void roll(int field, boolean up) { 96 throw new UnsupportedOperationException("Not supported yet."); 97 } 98 99 @Override 100 public int getMinimum(int field) { 101 throw new UnsupportedOperationException("Not supported yet."); 102 } 103 104 @Override 105 public int getMaximum(int field) { 106 throw new UnsupportedOperationException("Not supported yet."); 107 } 108 109 @Override 110 public int getGreatestMinimum(int field) { 111 throw new UnsupportedOperationException("Not supported yet."); 112 } 113 114 @Override 115 public int getLeastMaximum(int field) { 116 throw new UnsupportedOperationException("Not supported yet."); 117 } 118 } 119 }