/** @tests java.text.DateFormat#getTimeInstance(int, java.util.Locale) */ public void test_getTimeInstanceILjava_util_Locale() { SimpleDateFormat f2 = (SimpleDateFormat) DateFormat.getTimeInstance(DateFormat.SHORT, Locale.GERMAN); assertTrue("Wrong class", f2.getClass() == SimpleDateFormat.class); assertTrue( "Wrong symbols", f2.getDateFormatSymbols().equals(new DateFormatSymbols(Locale.GERMAN))); assertTrue("Doesn't work", f2.format(new Date()).getClass() == String.class); f2 = (SimpleDateFormat) DateFormat.getTimeInstance(DateFormat.MEDIUM, Locale.GERMAN); assertTrue("Wrong class", f2.getClass() == SimpleDateFormat.class); assertTrue( "Wrong symbols", f2.getDateFormatSymbols().equals(new DateFormatSymbols(Locale.GERMAN))); assertTrue("Doesn't work", f2.format(new Date()).getClass() == String.class); f2 = (SimpleDateFormat) DateFormat.getTimeInstance(DateFormat.LONG, Locale.GERMAN); assertTrue("Wrong class", f2.getClass() == SimpleDateFormat.class); assertTrue( "Wrong symbols", f2.getDateFormatSymbols().equals(new DateFormatSymbols(Locale.GERMAN))); assertTrue("Doesn't work", f2.format(new Date()).getClass() == String.class); f2 = (SimpleDateFormat) DateFormat.getTimeInstance(DateFormat.FULL, Locale.GERMAN); assertTrue("Wrong class", f2.getClass() == SimpleDateFormat.class); assertTrue( "Wrong symbols", f2.getDateFormatSymbols().equals(new DateFormatSymbols(Locale.GERMAN))); assertTrue("Doesn't work", f2.format(new Date()).getClass() == String.class); // regression test for HARMONY-940 try { DateFormat.getTimeInstance(77, Locale.GERMAN); fail("Should throw IAE"); } catch (IllegalArgumentException iae) { // expected } }
/** @tests java.text.DateFormat#getDateInstance() */ public void test_getDateInstance() { SimpleDateFormat f2 = (SimpleDateFormat) DateFormat.getDateInstance(); assertTrue("Wrong class", f2.getClass() == SimpleDateFormat.class); assertTrue( "Wrong default", f2.equals(DateFormat.getDateInstance(DateFormat.DEFAULT, Locale.getDefault()))); assertEquals(f2.getDateFormatSymbols(), new DateFormatSymbols()); assertTrue("Doesn't work", f2.format(new Date()).getClass() == String.class); }
/** @tests java.text.DateFormat#getDateInstance(int) */ public void test_getDateInstanceI() { assertTrue("Default not medium", DateFormat.DEFAULT == DateFormat.MEDIUM); SimpleDateFormat f2 = (SimpleDateFormat) DateFormat.getDateInstance(DateFormat.SHORT); assertTrue("Wrong class1", f2.getClass() == SimpleDateFormat.class); assertTrue( "Wrong default1", f2.equals(DateFormat.getDateInstance(DateFormat.SHORT, Locale.getDefault()))); assertTrue("Wrong symbols1", f2.getDateFormatSymbols().equals(new DateFormatSymbols())); assertTrue("Doesn't work1", f2.format(new Date()).getClass() == String.class); f2 = (SimpleDateFormat) DateFormat.getDateInstance(DateFormat.MEDIUM); assertTrue("Wrong class2", f2.getClass() == SimpleDateFormat.class); assertTrue( "Wrong default2", f2.equals(DateFormat.getDateInstance(DateFormat.MEDIUM, Locale.getDefault()))); assertTrue("Wrong symbols2", f2.getDateFormatSymbols().equals(new DateFormatSymbols())); assertTrue("Doesn't work2", f2.format(new Date()).getClass() == String.class); f2 = (SimpleDateFormat) DateFormat.getDateInstance(DateFormat.LONG); assertTrue("Wrong class3", f2.getClass() == SimpleDateFormat.class); assertTrue( "Wrong default3", f2.equals(DateFormat.getDateInstance(DateFormat.LONG, Locale.getDefault()))); assertTrue("Wrong symbols3", f2.getDateFormatSymbols().equals(new DateFormatSymbols())); assertTrue("Doesn't work3", f2.format(new Date()).getClass() == String.class); f2 = (SimpleDateFormat) DateFormat.getDateInstance(DateFormat.FULL); assertTrue("Wrong class4", f2.getClass() == SimpleDateFormat.class); assertTrue( "Wrong default4", f2.equals(DateFormat.getDateInstance(DateFormat.FULL, Locale.getDefault()))); assertTrue("Wrong symbols4", f2.getDateFormatSymbols().equals(new DateFormatSymbols())); assertTrue("Doesn't work4", f2.format(new Date()).getClass() == String.class); // regression test for HARMONY-940 try { DateFormat.getDateInstance(77); fail("Should throw IAE"); } catch (IllegalArgumentException iae) { // expected } }
private void testDateTimeLocale(int dStyle, int tStyle) { SimpleDateFormat f2 = (SimpleDateFormat) DateFormat.getDateTimeInstance(dStyle, tStyle, Locale.GERMAN); assertTrue("Wrong class", f2.getClass() == SimpleDateFormat.class); SimpleDateFormat date = (SimpleDateFormat) DateFormat.getDateInstance(dStyle, Locale.GERMAN); SimpleDateFormat time = (SimpleDateFormat) DateFormat.getTimeInstance(tStyle, Locale.GERMAN); assertTrue("Wrong default", f2.toPattern().equals(date.toPattern() + " " + time.toPattern())); assertTrue( "Wrong symbols", f2.getDateFormatSymbols().equals(new DateFormatSymbols(Locale.GERMAN))); assertTrue("Doesn't work", f2.format(new Date()).getClass() == String.class); }