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 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 }