1 /*
   2  * Copyright (c) 2012, 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;
  27 
  28 import com.sun.javafx.css.ParsedValueImpl;
  29 import javafx.css.StyleConverter.StringStore;
  30 
  31 import java.io.DataInputStream;
  32 import java.io.DataOutputStream;
  33 import java.util.ArrayList;
  34 import java.util.Collections;
  35 import java.util.List;
  36 import javafx.scene.Node;
  37 import org.junit.AfterClass;
  38 import org.junit.Test;
  39 import static org.junit.Assert.*;
  40 import org.junit.BeforeClass;
  41 import org.junit.Ignore;
  42 
  43 
  44 public class RuleTest {
  45     
  46     public RuleTest() {
  47     }
  48 
  49     @BeforeClass
  50     public static void setUpClass() throws Exception {
  51     }
  52 
  53     @AfterClass
  54     public static void tearDownClass() throws Exception {
  55     }
  56 
  57     @Test
  58     public void testGetUnobservedSelectorList() {
  59         List<Selector> expResult = new ArrayList<Selector>();
  60         expResult.add(Selector.createSelector("One.two#three"));
  61         expResult.add(Selector.createSelector("Four.five#six"));
  62         Rule instance = new Rule(expResult, Collections.EMPTY_LIST);
  63         List result = instance.getUnobservedSelectorList();
  64         assertEquals(expResult, result);
  65     }
  66 
  67     @Test
  68     public void testGetUnobservedDeclarationList() {
  69         List<Declaration> expResult = new ArrayList<Declaration>();
  70         expResult.add(new Declaration("one", new ParsedValueImpl<String,String>("one", null), false));
  71         expResult.add(new Declaration("two", new ParsedValueImpl<String,String>("two", null), false));
  72         expResult.add(new Declaration("three", new ParsedValueImpl<String,String>("three", null), false));
  73         Rule instance = new Rule(Collections.EMPTY_LIST, expResult);
  74         List result = instance.getUnobservedDeclarationList();
  75         assertEquals(expResult, result);
  76     }
  77 
  78     @Test
  79     public void testGetSelectors() {
  80         List<Selector> expResult = new ArrayList<Selector>();
  81         expResult.add(Selector.createSelector("One.two#three"));
  82         expResult.add(Selector.createSelector("Four.five#six"));
  83         Rule instance = new Rule(expResult, Collections.EMPTY_LIST);
  84         List result = instance.getSelectors();
  85         assertEquals(expResult, result);
  86     }
  87 
  88     @Test
  89     public void testGetDeclarations() {
  90         List<Declaration> expResult = new ArrayList<Declaration>();
  91         expResult.add(new Declaration("one", new ParsedValueImpl<String,String>("one", null), false));
  92         expResult.add(new Declaration("two", new ParsedValueImpl<String,String>("two", null), false));
  93         expResult.add(new Declaration("three", new ParsedValueImpl<String,String>("three", null), false));
  94         Rule instance = new Rule(Collections.EMPTY_LIST, expResult);
  95         List result = instance.getDeclarations();
  96         assertEquals(expResult, result);
  97     }
  98 
  99     @Test
 100     public void testGetStylesheet() {
 101         Rule instance = new Rule(Collections.EMPTY_LIST, Collections.EMPTY_LIST);
 102         Stylesheet expResult = new Stylesheet();
 103         expResult.getRules().add(instance);
 104         Stylesheet result = instance.getStylesheet();
 105         assertEquals(expResult, result);
 106     }
 107 
 108     @Test
 109     public void testGetOriginAfterSettingOriginAfterAddingRuleToStylesheet() {
 110         Rule instance = new Rule(Collections.EMPTY_LIST, Collections.EMPTY_LIST);
 111         Stylesheet stylesheet = new Stylesheet();
 112         stylesheet.getRules().add(instance);
 113         stylesheet.setOrigin(StyleOrigin.INLINE);
 114         StyleOrigin expResult = StyleOrigin.INLINE;
 115         StyleOrigin result = instance.getOrigin();
 116         assertEquals(expResult, result);
 117     }
 118 
 119     @Test
 120     public void testGetOriginAfterSettingOriginBeforeAddingRuleToStylesheet() {
 121         Rule instance = new Rule(Collections.EMPTY_LIST, Collections.EMPTY_LIST);
 122         Stylesheet stylesheet = new Stylesheet();
 123         stylesheet.setOrigin(StyleOrigin.INLINE);
 124         stylesheet.getRules().add(instance);
 125         StyleOrigin expResult = StyleOrigin.INLINE;
 126         StyleOrigin result = instance.getOrigin();
 127         assertEquals(expResult, result);
 128     }
 129     
 130     @Test
 131     public void testGetOriginWithoutAddingRuleToStylesheet() {
 132         Rule instance = new Rule(Collections.EMPTY_LIST, Collections.EMPTY_LIST);
 133         StyleOrigin result = instance.getOrigin();
 134         assertNull(result);
 135     }
 136 
 137     @Test
 138     public void testGetOriginAfterRemovingRuleFromStylesheet() {
 139         Rule instance = new Rule(Collections.EMPTY_LIST, Collections.EMPTY_LIST);
 140         Stylesheet stylesheet = new Stylesheet();
 141         stylesheet.getRules().add(instance);
 142         stylesheet.setOrigin(StyleOrigin.INLINE);
 143         stylesheet.getRules().remove(instance);        
 144         StyleOrigin result = instance.getOrigin();
 145         assertNull(result);
 146     }
 147 
 148     @Ignore @Test
 149     public void testApplies() {
 150         System.out.println("applies");
 151         Node node = null;
 152         Rule instance = null;
 153         long expResult = 0l;
 154         long result = instance.applies(node, null);
 155         assertEquals(expResult, result);
 156         fail("The test case is a prototype.");
 157     }
 158 
 159     @Ignore @Test
 160     public void testToString() {
 161         System.out.println("toString");
 162         Rule instance = null;
 163         String expResult = "";
 164         String result = instance.toString();
 165         assertEquals(expResult, result);
 166         fail("The test case is a prototype.");
 167     }
 168 
 169     @Ignore @Test
 170     public void testWriteBinary() throws Exception {
 171         System.out.println("writeBinary");
 172         DataOutputStream os = null;
 173         StringStore stringStore = null;
 174         Rule instance = null;
 175         instance.writeBinary(os, stringStore);
 176         fail("The test case is a prototype.");
 177     }
 178 
 179     @Ignore @Test
 180     public void testReadBinary() throws Exception {
 181         System.out.println("readBinary");
 182         DataInputStream is = null;
 183         String[] strings = null;
 184         Rule expResult = null;
 185         Rule result = Rule.readBinary(Stylesheet.BINARY_CSS_VERSION, is, strings);
 186         assertEquals(expResult, result);
 187         fail("The test case is a prototype.");
 188     }
 189 }