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 java.util.ArrayList;
  29 import java.util.Arrays;
  30 import java.util.Collection;
  31 import java.util.List;
  32 import org.junit.Test;
  33 import static org.junit.Assert.*;
  34 
  35 import org.junit.runner.RunWith;
  36 import org.junit.runners.Parameterized;
  37 import org.junit.runners.Parameterized.Parameters;
  38 
  39 @RunWith(Parameterized.class)
  40 public class StyleTest {
  41     
  42     private static class Data {
  43         private final String s1, s2;
  44         private final boolean expected;
  45         Data(String s1, String s2, boolean expected){
  46             this.s1 = s1;
  47             this.s2 = s2;
  48             this.expected = expected;
  49         }
  50         
  51         @Override public String toString() {
  52             return "\"" + s1 + "\" " + (expected ? "==" : "!=") + " \"" + s2 + "\"";
  53         }
  54     }
  55     
  56     public StyleTest(Data data) {
  57         this.data = data;
  58     }
  59     private final Data data;
  60     
  61     private static Style createStyle(String stylesheetText) {
  62         
  63         Stylesheet stylesheet = new CssParser().parse(stylesheetText);
  64         Rule rule = stylesheet.getRules().get(0);
  65         Selector sel = rule.getUnobservedSelectorList().get(0);
  66         Declaration decl = rule.getUnobservedDeclarationList().get(0);
  67         return new Style(sel, decl);
  68     }
  69 
  70     @Parameters
  71     public static Collection data() {
  72         
  73         return Arrays.asList(new Object[] {
  74             new Object[] { new Data("*.style { -fx-fill: red; }", 
  75                                     "*.style { -fx-fill: red; }", true) },
  76             new Object[] { new Data("*.style { -fx-fill: red; }", 
  77                                     "*.bad   { -fx-fill: red; }", false) },
  78             new Object[] { new Data("*.style:p { -fx-fill: red; }", 
  79                                     "*.style:p { -fx-fill: red; }", true) },
  80             new Object[] { new Data("*.style:p { -fx-fill: red; }", 
  81                                     "*.style:q { -fx-fill: red; }", false) },
  82             new Object[] { new Data("*.style:p { -fx-fill: red; }", 
  83                                     "*.bad:p   { -fx-fill: red; }", false) },
  84             new Object[] { new Data("*.style#c { -fx-fill: red; }", 
  85                                     "*.style#c { -fx-fill: red; }", true) },
  86             new Object[] { new Data("*.style#c { -fx-fill: red; }", 
  87                                     "*.style#d { -fx-fill: red; }", false) },
  88             new Object[] { new Data("*.style#c:p { -fx-fill: red; }", 
  89                                     "*.style#c:p { -fx-fill: red; }", true) },
  90             new Object[] { new Data("*.style#c:p { -fx-fill: red; }", 
  91                                     "*.style#c:q { -fx-fill: red; }", false) },
  92             new Object[] { new Data("*.style { -fx-fill: red; }", 
  93                                     "*.style { -fx-fill: green; }", false) },
  94             new Object[] { new Data("*.style { -fx-border-color: red; }", 
  95                                     "*.style { -fx-fill: red; }", false) },
  96         });
  97     }
  98     
  99     @Test
 100     public void testEquals() {
 101 
 102         Style instance = createStyle(data.s1);
 103         Style obj = createStyle(data.s2);
 104         boolean expected = data.expected;
 105         boolean actual = instance.equals(obj);
 106         assertTrue(data.toString(), expected == actual);
 107         
 108     }
 109 
 110 }