modules/graphics/src/test/java/com/sun/javafx/css/converters/URLConverterTest.java

Print this page
rev 9240 : 8076423: JEP 253: Prepare JavaFX UI Controls & CSS APIs for Modularization


   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 com.sun.javafx.css.converters;
  27 
  28 import java.net.URL;
  29 import javafx.css.ParsedValue;
  30 import javafx.css.StyleConverter;
  31 import javafx.scene.text.Font;
  32 import com.sun.javafx.css.ParsedValueImpl;
  33 import org.junit.Test;
  34 
  35 import static org.junit.Assert.*;
  36 
  37 
  38 public class URLConverterTest {
  39 
  40     public URLConverterTest() {
  41     }
  42     /**
  43      * Test of getInstance method, of class URLConverter.
  44      */
  45     @Test
  46     public void testGetInstance() {
  47         StyleConverter<ParsedValue[],String> result = URLConverter.getInstance();
  48         assertNotNull(result);
  49     }
  50 
  51     /**
  52      * Test of convert method, of class URLConverter.
  53      */
  54     @Test
  55     public void testConvertWithNullBaseURL() {
  56         
  57         ParsedValue[] values = new ParsedValue[] {
  58             new ParsedValueImpl<String,String>("com/sun/javafx/css/converters/some.txt", null),
  59             new ParsedValueImpl<String,String>(null,null)
  60         };
  61         ParsedValueImpl<ParsedValue[], String> value = 
  62             new ParsedValueImpl<ParsedValue[], String>(values, URLConverter.getInstance());
  63                 
  64         Font font = null;
  65         ClassLoader cl = Thread.currentThread().getContextClassLoader();
  66         String expResult = cl.getResource("com/sun/javafx/css/converters/some.txt").toExternalForm();
  67         String result = value.convert(font);
  68         assertEquals(expResult, result);
  69     }
  70 
  71     public void testConvertWithBaseURL() {
  72         ClassLoader cl = Thread.currentThread().getContextClassLoader();
  73         String base = cl.getResource("com/..").toExternalForm();
  74         ParsedValue[] values = new ParsedValue[] {
  75             new ParsedValueImpl<String,String>("com/sun/javafx/css/converters/some.txt", null),
  76             new ParsedValueImpl<String,String>(base,null)
  77         };
  78         ParsedValueImpl<ParsedValue[], String> value = 
  79             new ParsedValueImpl<ParsedValue[], String>(values, URLConverter.getInstance());
  80                 
  81         Font font = null;
  82         String expResult = cl.getResource("com/sun/javafx/css/converters/some.txt").toExternalForm();
  83         String result = value.convert(font);
  84         assertEquals(expResult, result);
  85     }
  86     
  87     @Test
  88     public void testConvertWithAbsoluteURLAndNullBaseURL() {
  89         
  90         ClassLoader cl = Thread.currentThread().getContextClassLoader();
  91         String expResult = cl.getResource("com/sun/javafx/css/converters/some.txt").toExternalForm();
  92         ParsedValue[] values = new ParsedValue[] {
  93             new ParsedValueImpl<String,String>(expResult, null),
  94             new ParsedValueImpl<String,String>(null,null)
  95         };
  96         ParsedValueImpl<ParsedValue[], String> value = 
  97             new ParsedValueImpl<ParsedValue[], String>(values, URLConverter.getInstance());
  98                 
  99         Font font = null;
 100         String result = value.convert(font);
 101         assertEquals(expResult, result);
 102     }
 103 
 104     @Test
 105     public void testConvertWithAbsoluteURLWithBaseURL() {
 106         
 107         ClassLoader cl = Thread.currentThread().getContextClassLoader();
 108         String baseURL = cl.getResource("com/..").toExternalForm();
 109         String expResult = cl.getResource("com/sun/javafx/css/converters/some.txt").toExternalForm();
 110         ParsedValue[] values = new ParsedValue[] {
 111             new ParsedValueImpl<String,String>(expResult, null),
 112             new ParsedValueImpl<String,String>(baseURL,null)
 113         };
 114         ParsedValueImpl<ParsedValue[], String> value = 
 115             new ParsedValueImpl<ParsedValue[], String>(values, URLConverter.getInstance());
 116                 
 117         Font font = null;
 118         String result = value.convert(font);
 119         assertEquals(expResult, result);
 120     }
 121     
 122 }


   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.css.converter;
  27 

  28 import javafx.css.ParsedValue;
  29 import javafx.css.StyleConverter;
  30 import javafx.scene.text.Font;
  31 import com.sun.javafx.css.ParsedValueImpl;
  32 import org.junit.Test;
  33 
  34 import static org.junit.Assert.*;
  35 
  36 
  37 public class URLConverterTest {
  38 
  39     public URLConverterTest() {
  40     }
  41     /**
  42      * Test of getInstance method, of class URLConverter.
  43      */
  44     @Test
  45     public void testGetInstance() {
  46         StyleConverter<ParsedValue[],String> result = URLConverter.getInstance();
  47         assertNotNull(result);
  48     }
  49 
  50     /**
  51      * Test of convert method, of class URLConverter.
  52      */
  53     @Test
  54     public void testConvertWithNullBaseURL() {
  55         
  56         ParsedValue[] values = new ParsedValue[] {
  57             new ParsedValueImpl<String,String>("javafx/css/converter/some.txt", null),
  58             new ParsedValueImpl<String,String>(null,null)
  59         };
  60         ParsedValueImpl<ParsedValue[], String> value = 
  61             new ParsedValueImpl<ParsedValue[], String>(values, URLConverter.getInstance());
  62                 
  63         Font font = null;
  64         ClassLoader cl = Thread.currentThread().getContextClassLoader();
  65         String expResult = cl.getResource("javafx/css/converter/some.txt").toExternalForm();
  66         String result = value.convert(font);
  67         assertEquals(expResult, result);
  68     }
  69 
  70     public void testConvertWithBaseURL() {
  71         ClassLoader cl = Thread.currentThread().getContextClassLoader();
  72         String base = cl.getResource("com/..").toExternalForm();
  73         ParsedValue[] values = new ParsedValue[] {
  74             new ParsedValueImpl<String,String>("javafx/css/converter/some.txt", null),
  75             new ParsedValueImpl<String,String>(base,null)
  76         };
  77         ParsedValueImpl<ParsedValue[], String> value = 
  78             new ParsedValueImpl<ParsedValue[], String>(values, URLConverter.getInstance());
  79                 
  80         Font font = null;
  81         String expResult = cl.getResource("javafx/css/converter/some.txt").toExternalForm();
  82         String result = value.convert(font);
  83         assertEquals(expResult, result);
  84     }
  85     
  86     @Test
  87     public void testConvertWithAbsoluteURLAndNullBaseURL() {
  88         
  89         ClassLoader cl = Thread.currentThread().getContextClassLoader();
  90         String expResult = cl.getResource("javafx/css/converter/some.txt").toExternalForm();
  91         ParsedValue[] values = new ParsedValue[] {
  92             new ParsedValueImpl<String,String>(expResult, null),
  93             new ParsedValueImpl<String,String>(null,null)
  94         };
  95         ParsedValueImpl<ParsedValue[], String> value = 
  96             new ParsedValueImpl<ParsedValue[], String>(values, URLConverter.getInstance());
  97                 
  98         Font font = null;
  99         String result = value.convert(font);
 100         assertEquals(expResult, result);
 101     }
 102 
 103     @Test
 104     public void testConvertWithAbsoluteURLWithBaseURL() {
 105         
 106         ClassLoader cl = Thread.currentThread().getContextClassLoader();
 107         String baseURL = cl.getResource("com/..").toExternalForm();
 108         String expResult = cl.getResource("javafx/css/converter/some.txt").toExternalForm();
 109         ParsedValue[] values = new ParsedValue[] {
 110             new ParsedValueImpl<String,String>(expResult, null),
 111             new ParsedValueImpl<String,String>(baseURL,null)
 112         };
 113         ParsedValueImpl<ParsedValue[], String> value = 
 114             new ParsedValueImpl<ParsedValue[], String>(values, URLConverter.getInstance());
 115                 
 116         Font font = null;
 117         String result = value.convert(font);
 118         assertEquals(expResult, result);
 119     }
 120     
 121 }