Esempio n. 1
0
  @Test
  public void testConvertWithMutlipleFormats() {
    LocalDate referenceDate = new LocalDate(1999, 2, 13);
    String[] dateFormats = {"MM/dd/yyyy", "MM-dd-yyyy"};
    CommonsLocalDateConverter multiFormatConverter = new CommonsLocalDateConverter(dateFormats);

    LocalDate dateWithSlashes =
        (LocalDate) multiFormatConverter.convert(LocalDate.class, "02/13/1999");
    assertEquals("Converted date from MM/dd/yyyy format", referenceDate, dateWithSlashes);

    LocalDate dateWithHyphens =
        (LocalDate) multiFormatConverter.convert(LocalDate.class, "02-13-1999");
    assertEquals("Converted date from MM-dd-yyyy format", referenceDate, dateWithHyphens);
  }
Esempio n. 2
0
 @Test
 public void testConvertWrongFormat() {
   try {
     converter.convert(LocalDate.class, "02-13-1999");
     fail();
   } catch (ConversionException ce) {
     assertEquals(
         "Error converting 'String' to 'Date' using pattern 'MM/dd/yyyy'", ce.getMessage());
   }
 }
Esempio n. 3
0
 @Test
 public void testConvertNull() {
   LocalDate result = (LocalDate) converter.convert(LocalDate.class, null);
   assertEquals(null, result);
 }
Esempio n. 4
0
 @Test
 public void testConvertToTypeClassObject() {
   LocalDate result = (LocalDate) converter.convert(LocalDate.class, "02/13/1999");
   LocalDate localDate = new LocalDate(1999, 2, 13);
   assertEquals(localDate, result);
 }