1 /* 2 * Copyright (C) 2016 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package libcore.java.time.chrono; 17 18 import org.junit.Test; 19 import org.junit.runner.RunWith; 20 import org.junit.runners.Parameterized; 21 import java.time.chrono.Chronology; 22 import java.time.chrono.Era; 23 import java.time.format.TextStyle; 24 import java.util.ArrayList; 25 import java.util.HashSet; 26 import java.util.List; 27 import java.util.Locale; 28 import java.util.Set; 29 30 import static org.junit.Assert.assertFalse; 31 import static org.junit.Assert.assertNotNull; 32 import static org.junit.Assert.assertTrue; 33 34 /** 35 * Test display names of chronologies and their eras. 36 * The primary reason for this test is to ensure that newly added chronologies have a display name 37 * and that their eras have a display name as well. 38 */ 39 @RunWith(Parameterized.class) 40 public class ChronologyDisplayNameTest { 41 @Parameterized.Parameters(name = "{0}") 42 public static List<Chronology> getChronologies() { 43 return new ArrayList<>(Chronology.getAvailableChronologies()); 44 } 45 46 private final Chronology chronology; 47 48 public ChronologyDisplayNameTest(Chronology chronology) { 49 this.chronology = chronology; 50 } 51 52 @Test 53 public void testDisplayName() { 54 String displayName = chronology.getDisplayName(TextStyle.FULL, Locale.ENGLISH); 55 assertNotNull(displayName); 56 assertFalse("".equals(displayName)); 57 } 58 59 @Test 60 public void testEras() { 61 List<Era> eras = chronology.eras(); 62 Set<String> eraNames = new HashSet<>(); 63 for (Era era : eras) { 64 assertNotNull(era); 65 String displayName = era.getDisplayName(TextStyle.FULL, Locale.ENGLISH); 66 assertNotNull(displayName); 67 assertFalse("".equals(displayName)); 68 assertTrue("Era name for " + era + " not unique.", eraNames.add(displayName)); 69 } 70 } 71 } 72