1 /*
   2  * Copyright (c) 2011, 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 test.com.sun.javafx.css.converters;
  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 javafx.css.converter.URLConverter;
  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>("test/javafx/css/converter/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("test/javafx/css/converter/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>("test/javafx/css/converter/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("test/javafx/css/converter/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("test/javafx/css/converter/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("test/javafx/css/converter/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 }