modules/base/src/test/java/test/javafx/util/converter/LocalDateStringConverterTest.java

Print this page
rev 9235 : 8134760: Refactor Javafx base module tests for clear separation of tests
Reviewed-by:


   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package javafx.util.converter;
  27 
  28 import java.util.Arrays;
  29 import java.time.LocalDate;
  30 import java.time.chrono.Chronology;
  31 import java.time.chrono.IsoChronology;
  32 import java.time.format.DateTimeFormatter;
  33 import java.time.format.FormatStyle;
  34 import java.util.Collection;
  35 import java.util.Locale;
  36 
  37 import javafx.util.StringConverter;



  38 
  39 import static org.junit.Assert.*;
  40 import org.junit.Before;
  41 import org.junit.Test;
  42 import org.junit.Ignore;
  43 import org.junit.runner.RunWith;
  44 import org.junit.runners.Parameterized;
  45 
  46 /**
  47  */
  48 @RunWith(Parameterized.class)
  49 public class LocalDateStringConverterTest {
  50     private static final LocalDate VALID_DATE = LocalDate.of(1985, 1, 12);
  51     
  52     private static final DateTimeFormatter aFormatter = DateTimeFormatter.ofPattern("dd MM yyyy");
  53     private static final DateTimeFormatter aParser = DateTimeFormatter.ofPattern("yyyy MM dd");
  54 
  55 
  56     @Parameterized.Parameters public static Collection implementations() {
  57         return Arrays.asList(new Object[][] {


  75     private DateTimeFormatter formatter, parser;
  76     private LocalDate validDate;
  77     
  78     public LocalDateStringConverterTest(LocalDateStringConverter converter, Locale locale, FormatStyle dateStyle, LocalDate validDate, DateTimeFormatter formatter, DateTimeFormatter parser) {
  79         this.converter = converter;
  80         this.locale = locale;
  81         this.dateStyle = dateStyle;
  82         this.validDate = validDate;
  83         this.formatter = formatter;
  84         this.parser = parser;
  85     }
  86     
  87     @Before public void setup() {
  88     }
  89     
  90     /*********************************************************************
  91      * Test constructors
  92      ********************************************************************/ 
  93     
  94     @Test public void testConstructor() {
  95         assertEquals(locale, converter.ldtConverter.locale);
  96         assertEquals((dateStyle != null) ? dateStyle : FormatStyle.SHORT, converter.ldtConverter.dateStyle);
  97         assertNull(converter.ldtConverter.timeStyle);

  98         if (formatter != null) {
  99             assertEquals(formatter, converter.ldtConverter.formatter);

 100         }
 101         if (parser != null) {
 102             assertEquals(parser, converter.ldtConverter.parser);

 103         } else if (formatter != null) {
 104             assertEquals(formatter, converter.ldtConverter.parser);

 105         }
 106     }
 107     
 108     
 109     /*********************************************************************
 110      * Test toString / fromString methods
 111      ********************************************************************/    
 112     
 113     @Test public void toString_to_fromString_testRoundtrip() {
 114         if (formatter == null) {
 115             // Only the default formatter/parser can guarantee roundtrip symmetry
 116             assertEquals(validDate, converter.fromString(converter.toString(validDate)));
 117         }
 118     }
 119     
 120     @Test(expected=RuntimeException.class)
 121     public void fromString_testInvalidInput() {
 122         converter.fromString("abcdefg");
 123     }
 124 }


   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package test.javafx.util.converter;
  27 
  28 import java.util.Arrays;
  29 import java.time.LocalDate;
  30 import java.time.chrono.Chronology;
  31 import java.time.chrono.IsoChronology;
  32 import java.time.format.DateTimeFormatter;
  33 import java.time.format.FormatStyle;
  34 import java.util.Collection;
  35 import java.util.Locale;
  36 
  37 import javafx.util.StringConverter;
  38 import javafx.util.converter.LocalTimeStringConverterShim;
  39 import javafx.util.converter.LocalDateStringConverter;
  40 import javafx.util.converter.LocalDateStringConverterShim;
  41 
  42 import static org.junit.Assert.*;
  43 import org.junit.Before;
  44 import org.junit.Test;
  45 import org.junit.Ignore;
  46 import org.junit.runner.RunWith;
  47 import org.junit.runners.Parameterized;
  48 
  49 /**
  50  */
  51 @RunWith(Parameterized.class)
  52 public class LocalDateStringConverterTest {
  53     private static final LocalDate VALID_DATE = LocalDate.of(1985, 1, 12);
  54     
  55     private static final DateTimeFormatter aFormatter = DateTimeFormatter.ofPattern("dd MM yyyy");
  56     private static final DateTimeFormatter aParser = DateTimeFormatter.ofPattern("yyyy MM dd");
  57 
  58 
  59     @Parameterized.Parameters public static Collection implementations() {
  60         return Arrays.asList(new Object[][] {


  78     private DateTimeFormatter formatter, parser;
  79     private LocalDate validDate;
  80     
  81     public LocalDateStringConverterTest(LocalDateStringConverter converter, Locale locale, FormatStyle dateStyle, LocalDate validDate, DateTimeFormatter formatter, DateTimeFormatter parser) {
  82         this.converter = converter;
  83         this.locale = locale;
  84         this.dateStyle = dateStyle;
  85         this.validDate = validDate;
  86         this.formatter = formatter;
  87         this.parser = parser;
  88     }
  89     
  90     @Before public void setup() {
  91     }
  92     
  93     /*********************************************************************
  94      * Test constructors
  95      ********************************************************************/ 
  96     
  97     @Test public void testConstructor() {
  98         assertEquals(locale, LocalDateStringConverterShim.getldtConverterLocale(converter));
  99         assertEquals((dateStyle != null) ? dateStyle : FormatStyle.SHORT, 
 100                 LocalDateStringConverterShim.getldtConverterDateStyle(converter));
 101         assertNull(LocalDateStringConverterShim.getldtConverterTimeStyle(converter));
 102         if (formatter != null) {
 103             assertEquals(formatter, 
 104                     LocalDateStringConverterShim.getldtConverterFormatter(converter));
 105         }
 106         if (parser != null) {
 107             assertEquals(parser, 
 108                     LocalDateStringConverterShim.getldtConverterParser(converter));
 109         } else if (formatter != null) {
 110             assertEquals(formatter, 
 111                 LocalDateStringConverterShim.getldtConverterParser(converter));
 112         }
 113     }
 114     
 115     
 116     /*********************************************************************
 117      * Test toString / fromString methods
 118      ********************************************************************/    
 119     
 120     @Test public void toString_to_fromString_testRoundtrip() {
 121         if (formatter == null) {
 122             // Only the default formatter/parser can guarantee roundtrip symmetry
 123             assertEquals(validDate, converter.fromString(converter.toString(validDate)));
 124         }
 125     }
 126     
 127     @Test(expected=RuntimeException.class)
 128     public void fromString_testInvalidInput() {
 129         converter.fromString("abcdefg");
 130     }
 131 }