test/java/time/test/java/time/format/TestFractionPrinterParser.java

Print this page




  61 
  62 import static java.time.temporal.ChronoField.NANO_OF_SECOND;
  63 import static java.time.temporal.ChronoField.SECOND_OF_MINUTE;
  64 import static org.testng.Assert.assertEquals;
  65 import static org.testng.Assert.fail;
  66 
  67 import java.text.ParsePosition;
  68 import java.time.DateTimeException;
  69 import java.time.LocalTime;
  70 import java.time.format.DateTimeFormatter;
  71 import java.time.temporal.TemporalAccessor;
  72 import java.time.temporal.TemporalField;
  73 
  74 import org.testng.annotations.DataProvider;
  75 import org.testng.annotations.Test;
  76 import test.java.time.temporal.MockFieldValue;
  77 
  78 /**
  79  * Test FractionPrinterParser.
  80  */
  81 @Test(groups={"implementation"})
  82 public class TestFractionPrinterParser extends AbstractTestPrinterParser {
  83 
  84     private DateTimeFormatter getFormatter(TemporalField field, int minWidth, int maxWidth, boolean decimalPoint) {
  85         return builder.appendFraction(field, minWidth, maxWidth, decimalPoint).toFormatter(locale).withSymbols(symbols);
  86     }
  87 
  88     //-----------------------------------------------------------------------
  89     // print
  90     //-----------------------------------------------------------------------
  91     @Test(expectedExceptions=DateTimeException.class)
  92     public void test_print_emptyCalendrical() throws Exception {
  93         getFormatter(NANO_OF_SECOND, 0, 9, true).formatTo(EMPTY_DTA, buf);
  94     }
  95 
  96     public void test_print_append() throws Exception {
  97         buf.append("EXISTING");
  98         getFormatter(NANO_OF_SECOND, 0, 9, true).formatTo(LocalTime.of(12, 30, 40, 3), buf);
  99         assertEquals(buf.toString(), "EXISTING.000000003");
 100     }
 101 




  61 
  62 import static java.time.temporal.ChronoField.NANO_OF_SECOND;
  63 import static java.time.temporal.ChronoField.SECOND_OF_MINUTE;
  64 import static org.testng.Assert.assertEquals;
  65 import static org.testng.Assert.fail;
  66 
  67 import java.text.ParsePosition;
  68 import java.time.DateTimeException;
  69 import java.time.LocalTime;
  70 import java.time.format.DateTimeFormatter;
  71 import java.time.temporal.TemporalAccessor;
  72 import java.time.temporal.TemporalField;
  73 
  74 import org.testng.annotations.DataProvider;
  75 import org.testng.annotations.Test;
  76 import test.java.time.temporal.MockFieldValue;
  77 
  78 /**
  79  * Test FractionPrinterParser.
  80  */
  81 @Test
  82 public class TestFractionPrinterParser extends AbstractTestPrinterParser {
  83 
  84     private DateTimeFormatter getFormatter(TemporalField field, int minWidth, int maxWidth, boolean decimalPoint) {
  85         return builder.appendFraction(field, minWidth, maxWidth, decimalPoint).toFormatter(locale).withSymbols(symbols);
  86     }
  87 
  88     //-----------------------------------------------------------------------
  89     // print
  90     //-----------------------------------------------------------------------
  91     @Test(expectedExceptions=DateTimeException.class)
  92     public void test_print_emptyCalendrical() throws Exception {
  93         getFormatter(NANO_OF_SECOND, 0, 9, true).formatTo(EMPTY_DTA, buf);
  94     }
  95 
  96     public void test_print_append() throws Exception {
  97         buf.append("EXISTING");
  98         getFormatter(NANO_OF_SECOND, 0, 9, true).formatTo(LocalTime.of(12, 30, 40, 3), buf);
  99         assertEquals(buf.toString(), "EXISTING.000000003");
 100     }
 101