1 /* 2 * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 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.util.Collection; 30 import static org.junit.Assert.assertEquals; 31 import static org.junit.Assert.assertFalse; 32 import static org.junit.Assert.assertNull; 33 import static org.junit.Assert.assertSame; 34 import static org.junit.Assert.assertTrue; 35 36 import javafx.util.StringConverter; 37 38 import org.junit.Before; 39 import org.junit.Test; 40 import org.junit.Ignore; 41 import org.junit.runner.RunWith; 42 import org.junit.runners.Parameterized; 43 44 /** 45 */ 46 @RunWith(Parameterized.class) 47 public class ParameterizedConverterTest { 48 private final Class<? extends StringConverter> converterClass; 49 private StringConverter converter; 50 51 @Parameterized.Parameters public static Collection implementations() { 52 return Arrays.asList(new Object[][] { 53 { BigDecimalStringConverter.class }, 54 { BigIntegerStringConverter.class }, 55 { BooleanStringConverter.class }, 56 { ByteStringConverter.class }, 57 { CharacterStringConverter.class }, 58 { CurrencyStringConverter.class }, 59 { DateStringConverter.class }, 60 { DateTimeStringConverter.class }, 61 { DefaultStringConverter.class }, 62 { DoubleStringConverter.class }, 63 { FloatStringConverter.class }, 64 { IntegerStringConverter.class }, 65 { LongStringConverter.class }, 66 { NumberStringConverter.class }, 67 { PercentageStringConverter.class }, 68 { ShortStringConverter.class }, 69 { TimeStringConverter.class }, 70 }); 71 } 72 73 public ParameterizedConverterTest(Class<? extends StringConverter> converterClass) { 74 this.converterClass = converterClass; 75 } 76 77 @Before public void setup() { 78 try { 79 converter = converterClass.newInstance(); 80 } catch (Exception ex) { 81 ex.printStackTrace(); 82 } 83 } 84 85 @Test public void toString_testNull() { 86 assertEquals("", converter.toString(null)); 87 } 88 89 @Test public void fromString_testEmptyStringWithWhiteSpace() { 90 if (converterClass == DefaultStringConverter.class) { 91 assertEquals(" ", converter.fromString(" ")); 92 } else { 93 assertNull(converter.fromString(" ")); 94 } 95 } 96 97 @Test public void fromString_testNull() { 98 assertNull(converter.fromString(null)); 99 } 100 101 @Test public void fromString_testEmptyString() { 102 if (converterClass == DefaultStringConverter.class) { 103 assertEquals("", converter.fromString("")); 104 } else { 105 assertNull(converter.fromString("")); 106 } 107 } 108 }