test/java/time/test/java/time/temporal/TestChronoField.java

Print this page




 116                 {ChronoField.DAY_OF_MONTH},
 117                 {ChronoField.AMPM_OF_DAY},
 118                 {ChronoField.HOUR_OF_DAY},
 119                 {ChronoField.MINUTE_OF_HOUR},
 120                 {ChronoField.SECOND_OF_MINUTE},
 121         };
 122     }
 123 
 124 
 125     //-----------------------------------------------------------------------
 126     // test ChronoField.getDisplayName
 127     //-----------------------------------------------------------------------
 128     @Test(dataProvider="localeDisplayNames")
 129     public void test_localeDisplayNames(ChronoField field) {
 130         for (Locale locale : data_localeList()) {
 131             String displayname = field.getDisplayName(locale);
 132 
 133             // Verify the name returned is the same as the direct mapping to the locale resource.
 134             LocaleResources lr = LocaleProviderAdapter.getResourceBundleBased()
 135                                         .getLocaleResources(locale);
 136             ResourceBundle rb = lr.getFormatData();
 137             String displayNameKey = fieldMap.get(field);
 138             if (displayNameKey != null) {
 139                 String key = "field." + displayNameKey;
 140                 String expected = rb.containsKey(key) ? rb.getString(key) : field.getName();
 141                 assertEquals(displayname, expected);
 142             } else {
 143                 fail("no mapping for field: " + field);
 144             }
 145         }
 146     }
 147 
 148     @Test
 149     public void test_IsoFields_week_based_year() {
 150         Locale locale = Locale.US;
 151         String name = IsoFields.WEEK_OF_WEEK_BASED_YEAR.getDisplayName(locale);
 152         assertEquals(name, "Week");
 153     }
 154 
 155     @Test(expectedExceptions=NullPointerException.class)
 156     public void test_nullIsoFields_week_based_year() {




 116                 {ChronoField.DAY_OF_MONTH},
 117                 {ChronoField.AMPM_OF_DAY},
 118                 {ChronoField.HOUR_OF_DAY},
 119                 {ChronoField.MINUTE_OF_HOUR},
 120                 {ChronoField.SECOND_OF_MINUTE},
 121         };
 122     }
 123 
 124 
 125     //-----------------------------------------------------------------------
 126     // test ChronoField.getDisplayName
 127     //-----------------------------------------------------------------------
 128     @Test(dataProvider="localeDisplayNames")
 129     public void test_localeDisplayNames(ChronoField field) {
 130         for (Locale locale : data_localeList()) {
 131             String displayname = field.getDisplayName(locale);
 132 
 133             // Verify the name returned is the same as the direct mapping to the locale resource.
 134             LocaleResources lr = LocaleProviderAdapter.getResourceBundleBased()
 135                                         .getLocaleResources(locale);
 136             ResourceBundle rb = lr.getJavaTimeFormatData();
 137             String displayNameKey = fieldMap.get(field);
 138             if (displayNameKey != null) {
 139                 String key = "field." + displayNameKey;
 140                 String expected = rb.containsKey(key) ? rb.getString(key) : field.getName();
 141                 assertEquals(displayname, expected);
 142             } else {
 143                 fail("no mapping for field: " + field);
 144             }
 145         }
 146     }
 147 
 148     @Test
 149     public void test_IsoFields_week_based_year() {
 150         Locale locale = Locale.US;
 151         String name = IsoFields.WEEK_OF_WEEK_BASED_YEAR.getDisplayName(locale);
 152         assertEquals(name, "Week");
 153     }
 154 
 155     @Test(expectedExceptions=NullPointerException.class)
 156     public void test_nullIsoFields_week_based_year() {