modules/graphics/src/test/java/test/javafx/css/StyleTest.java

Print this page
rev 9250 : 8134762: Refactor Javafx graphics module tests for clear separation of tests
Reviewed-by:


   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; }", 




   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.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 javafx.css.CssParser;
  33 import javafx.css.Declaration;
  34 import javafx.css.Rule;
  35 import javafx.css.RuleShim;
  36 import javafx.css.Selector;
  37 import javafx.css.Style;
  38 import javafx.css.Stylesheet;
  39 import org.junit.Test;
  40 import static org.junit.Assert.*;
  41 
  42 import org.junit.runner.RunWith;
  43 import org.junit.runners.Parameterized;
  44 import org.junit.runners.Parameterized.Parameters;
  45 
  46 @RunWith(Parameterized.class)
  47 public class StyleTest {
  48     
  49     private static class Data {
  50         private final String s1, s2;
  51         private final boolean expected;
  52         Data(String s1, String s2, boolean expected){
  53             this.s1 = s1;
  54             this.s2 = s2;
  55             this.expected = expected;
  56         }
  57         
  58         @Override public String toString() {
  59             return "\"" + s1 + "\" " + (expected ? "==" : "!=") + " \"" + s2 + "\"";
  60         }
  61     }
  62     
  63     public StyleTest(Data data) {
  64         this.data = data;
  65     }
  66     private final Data data;
  67     
  68     private static Style createStyle(String stylesheetText) {
  69         
  70         Stylesheet stylesheet = new CssParser().parse(stylesheetText);
  71         Rule rule = stylesheet.getRules().get(0);
  72         Selector sel = RuleShim.getUnobservedSelectorList(rule).get(0);
  73         Declaration decl = RuleShim.getUnobservedDeclarationList(rule).get(0);
  74         return new Style(sel, decl);
  75     }
  76 
  77     @Parameters
  78     public static Collection data() {
  79         
  80         return Arrays.asList(new Object[] {
  81             new Object[] { new Data("*.style { -fx-fill: red; }", 
  82                                     "*.style { -fx-fill: red; }", true) },
  83             new Object[] { new Data("*.style { -fx-fill: red; }", 
  84                                     "*.bad   { -fx-fill: red; }", false) },
  85             new Object[] { new Data("*.style:p { -fx-fill: red; }", 
  86                                     "*.style:p { -fx-fill: red; }", true) },
  87             new Object[] { new Data("*.style:p { -fx-fill: red; }", 
  88                                     "*.style:q { -fx-fill: red; }", false) },
  89             new Object[] { new Data("*.style:p { -fx-fill: red; }", 
  90                                     "*.bad:p   { -fx-fill: red; }", false) },
  91             new Object[] { new Data("*.style#c { -fx-fill: red; }", 
  92                                     "*.style#c { -fx-fill: red; }", true) },
  93             new Object[] { new Data("*.style#c { -fx-fill: red; }",