test/java/time/tck/java/time/format/TCKFormatStyle.java

Print this page




  76  */
  77 @Test
  78 public class TCKFormatStyle {
  79 
  80     private static final ZoneId ZONEID_PARIS = ZoneId.of("Europe/Paris");
  81     private static final ZoneId OFFSET_PTWO = ZoneOffset.of("+02:00");
  82 
  83     //-----------------------------------------------------------------------
  84     // valueOf()
  85     //-----------------------------------------------------------------------
  86     @Test
  87     public void test_valueOf() {
  88         for (FormatStyle style : FormatStyle.values()) {
  89             assertEquals(FormatStyle.valueOf(style.name()), style);
  90         }
  91     }
  92 
  93     @DataProvider(name="formatStyle")
  94     Object[][] data_formatStyle() {
  95         return new Object[][] {
  96                 {ZonedDateTime.of(LocalDateTime.of(2001, 10, 2, 1, 2, 3), ZONEID_PARIS), FormatStyle.FULL, "Tuesday, October 2, 2001 1:02:03 AM CEST Europe/Paris"},
  97                 {ZonedDateTime.of(LocalDateTime.of(2001, 10, 2, 1, 2, 3), ZONEID_PARIS), FormatStyle.LONG, "October 2, 2001 1:02:03 AM CEST Europe/Paris"},
  98                 {ZonedDateTime.of(LocalDateTime.of(2001, 10, 2, 1, 2, 3), ZONEID_PARIS), FormatStyle.MEDIUM, "Oct 2, 2001 1:02:03 AM Europe/Paris"},
  99                 {ZonedDateTime.of(LocalDateTime.of(2001, 10, 2, 1, 2, 3), ZONEID_PARIS), FormatStyle.SHORT, "10/2/01 1:02 AM Europe/Paris"},
 100 
 101                 {ZonedDateTime.of(LocalDateTime.of(2001, 10, 2, 1, 2, 3), OFFSET_PTWO), FormatStyle.FULL, "Tuesday, October 2, 2001 1:02:03 AM +02:00 +02:00"},
 102                 {ZonedDateTime.of(LocalDateTime.of(2001, 10, 2, 1, 2, 3), OFFSET_PTWO), FormatStyle.LONG, "October 2, 2001 1:02:03 AM +02:00 +02:00"},
 103                 {ZonedDateTime.of(LocalDateTime.of(2001, 10, 2, 1, 2, 3), OFFSET_PTWO), FormatStyle.MEDIUM, "Oct 2, 2001 1:02:03 AM +02:00"},
 104                 {ZonedDateTime.of(LocalDateTime.of(2001, 10, 2, 1, 2, 3), OFFSET_PTWO), FormatStyle.SHORT, "10/2/01 1:02 AM +02:00"},
 105         };
 106     }
 107 
 108     @Test(dataProvider = "formatStyle")
 109     public void test_formatStyle(Temporal temporal, FormatStyle style, String formattedStr) {
 110         DateTimeFormatterBuilder builder = new DateTimeFormatterBuilder();
 111         DateTimeFormatter formatter = builder.appendLocalized(style, style).appendLiteral(" ").appendZoneOrOffsetId().toFormatter();
 112         formatter = formatter.withLocale(Locale.US);
 113         assertEquals(formatter.format(temporal), formattedStr);
 114     }
 115 }


  76  */
  77 @Test
  78 public class TCKFormatStyle {
  79 
  80     private static final ZoneId ZONEID_PARIS = ZoneId.of("Europe/Paris");
  81     private static final ZoneId OFFSET_PTWO = ZoneOffset.of("+02:00");
  82 
  83     //-----------------------------------------------------------------------
  84     // valueOf()
  85     //-----------------------------------------------------------------------
  86     @Test
  87     public void test_valueOf() {
  88         for (FormatStyle style : FormatStyle.values()) {
  89             assertEquals(FormatStyle.valueOf(style.name()), style);
  90         }
  91     }
  92 
  93     @DataProvider(name="formatStyle")
  94     Object[][] data_formatStyle() {
  95         return new Object[][] {
  96                 {ZonedDateTime.of(LocalDateTime.of(2001, 10, 2, 1, 2, 3), ZONEID_PARIS), FormatStyle.FULL, "Tuesday, October 2, 2001 at 1:02:03 AM Central European Summer Time Europe/Paris"},
  97                 {ZonedDateTime.of(LocalDateTime.of(2001, 10, 2, 1, 2, 3), ZONEID_PARIS), FormatStyle.LONG, "October 2, 2001 at 1:02:03 AM CEST Europe/Paris"},
  98                 {ZonedDateTime.of(LocalDateTime.of(2001, 10, 2, 1, 2, 3), ZONEID_PARIS), FormatStyle.MEDIUM, "Oct 2, 2001, 1:02:03 AM Europe/Paris"},
  99                 {ZonedDateTime.of(LocalDateTime.of(2001, 10, 2, 1, 2, 3), ZONEID_PARIS), FormatStyle.SHORT, "10/2/01, 1:02 AM Europe/Paris"},
 100 
 101                 {ZonedDateTime.of(LocalDateTime.of(2001, 10, 2, 1, 2, 3), OFFSET_PTWO), FormatStyle.FULL, "Tuesday, October 2, 2001 at 1:02:03 AM +02:00 +02:00"},
 102                 {ZonedDateTime.of(LocalDateTime.of(2001, 10, 2, 1, 2, 3), OFFSET_PTWO), FormatStyle.LONG, "October 2, 2001 at 1:02:03 AM +02:00 +02:00"},
 103                 {ZonedDateTime.of(LocalDateTime.of(2001, 10, 2, 1, 2, 3), OFFSET_PTWO), FormatStyle.MEDIUM, "Oct 2, 2001, 1:02:03 AM +02:00"},
 104                 {ZonedDateTime.of(LocalDateTime.of(2001, 10, 2, 1, 2, 3), OFFSET_PTWO), FormatStyle.SHORT, "10/2/01, 1:02 AM +02:00"},
 105         };
 106     }
 107 
 108     @Test(dataProvider = "formatStyle")
 109     public void test_formatStyle(Temporal temporal, FormatStyle style, String formattedStr) {
 110         DateTimeFormatterBuilder builder = new DateTimeFormatterBuilder();
 111         DateTimeFormatter formatter = builder.appendLocalized(style, style).appendLiteral(" ").appendZoneOrOffsetId().toFormatter();
 112         formatter = formatter.withLocale(Locale.US);
 113         assertEquals(formatter.format(temporal), formattedStr);
 114     }
 115 }