DatePickerFormatter extends
        JFormattedTextField.AbstractFormatter { public DateFormat[] getFormats() { DateFormat[] results = new DateFormat[_formats.length]; System.arraycopy(_formats, 0, results, 0, results.length); return results; } DatePickerFormatter();  DatePickerFormatter(DateFormat formats[]);  DatePickerFormatter(Locale locale);  DatePickerFormatter(DateFormat formats[], Locale locale); DateFormat[] getFormats(); @Override Object stringToValue(String text); @Override String valueToString(Object value);  }
@Test public void testPickerFormatterNoDefaults() { Locale.setDefault(Locale.JAPAN); if (UIManagerExt.getString("JXDatePicker.longFormat", Locale .getDefault()) != null) { LOG.info("can't run formatter fallback - has format entry"); return; } DatePickerFormatter formatter = new DatePickerFormatter(); assertNotNull(formatter.getFormats()); assertTrue("must have formats: " + formatter.getFormats().length, formatter.getFormats().length > 0); assertEquals(DateFormat.getDateInstance(DateFormat.SHORT), formatter .getFormats()[0]); }
@Test public void testPickerFormatterDefaultToday() { Locale.setDefault(Locale.JAPAN); if (UIManagerExt.getString("JXDatePicker.longFormat", Locale .getDefault()) != null) { LOG.info("can't run formatter fallback - has format entry"); return; } String pattern = UIManagerExt.getString("JXDatePicker.linkFormat"); assertNotNull("linkFormat entry is available", pattern); MessageFormat format = new MessageFormat(pattern, Locale.getDefault()); assertEquals(DateFormat.getDateInstance(), format .getFormats()[0]); }
@Test public void testPickerFormatterCustomLocale() { Locale locale = Locale.FRENCH; DatePickerFormatter formatter = new DatePickerFormatter(locale); SimpleDateFormat format = (SimpleDateFormat) formatter.getFormats()[0]; String pattern = UIManagerExt.getString("JXDatePicker.longFormat", locale); assertEquals("format pattern must be same as from localized resource", pattern, format.toPattern()); }
@Test public void testPickerFormatterUIResourceCustomLocale() { Locale locale = Locale.FRENCH; DatePickerFormatter formatter = new DatePickerFormatterUIResource(locale); SimpleDateFormat format = (SimpleDateFormat) formatter.getFormats()[0]; String pattern = UIManagerExt.getString("JXDatePicker.longFormat", locale); assertEquals("format pattern must be same as from localized resource", pattern, format.toPattern()); }
@Test public void testPickerFormatterUIResourceDefaultLocale() { DatePickerFormatter formatter = new DatePickerFormatterUIResource(); SimpleDateFormat format = (SimpleDateFormat) formatter.getFormats()[0]; String pattern = UIManagerExt.getString("JXDatePicker.longFormat"); if (pattern != null) { assertEquals(pattern, format.toPattern()); } else { LOG.info("can't run test, no datePicker resource entries for Locale " + Locale.getDefault()); } }
@Test public void testPickerFormatterDefaultLocale() { DatePickerFormatter formatter = new DatePickerFormatter(); SimpleDateFormat format = (SimpleDateFormat) formatter.getFormats()[0]; String pattern = UIManagerExt.getString("JXDatePicker.longFormat"); if (pattern != null) { assertEquals(pattern, format.toPattern()); } else { LOG.info("can't run test, no datePicker resource entries for Locale " + Locale.getDefault()); } }
@Test public void testPickerFormatterEmptyFormats() { DateFormat[] formats = new DateFormat[0]; DatePickerFormatter formatter = new DatePickerFormatter(formats); assertNotNull(formatter.getFormats()); assertEquals(formats.length, formatter.getFormats().length); }
@Test public void testPickerFormatterDefaultConstructor() { DatePickerFormatter formatter = new DatePickerFormatter(); assertNotNull(formatter.getFormats()); int uiFormats = 0; if (UIManagerExt.getString("JXDatePicker.longFormat") != null) { uiFormats++; } if (UIManagerExt.getString("JXDatePicker.mediumFormat") != null) { uiFormats++; } if (UIManagerExt.getString("JXDatePicker.shortFormat") != null) { uiFormats++; } if (uiFormats == 0) { uiFormats = 1; } assertEquals(uiFormats, formatter.getFormats().length); }
@Test public void testPickerFormatterConstructorWithParameterNull() { DatePickerFormatter defaultFormatter = new DatePickerFormatter(); DateFormat[] defaultFormats = defaultFormatter.getFormats(); DatePickerFormatter formatter = new DatePickerFormatter((DateFormat[])null); DateFormat[] formats = formatter.getFormats(); assertNotNull("formats must not be null", formats); assertEquals(defaultFormats.length, formats.length); for (int i = 0; i < defaultFormats.length; i++) { assertEquals("format must be equals to default at " + i, defaultFormats[i], formats[i]); } }