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

Print this page
rev 9240 : 8076423: JEP 253: Prepare JavaFX UI Controls & CSS APIs for Modularization


   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 com.sun.javafx.css;


  27 
  28 import com.sun.javafx.css.parser.CSSParser;
  29 import java.util.Arrays;
  30 import java.util.Collection;
  31 import java.util.List;
  32 import javafx.scene.paint.Color;
  33 import org.junit.Test;
  34 import static org.junit.Assert.*;
  35 
  36 import org.junit.runner.RunWith;
  37 import org.junit.runners.Parameterized;
  38 import org.junit.runners.Parameterized.Parameters;
  39 
  40 @RunWith(Parameterized.class)
  41 public class SelectorPartitioningTest {
  42     
  43     public SelectorPartitioningTest(final Data data) {
  44         this.data = data;
  45         this.instance = new SelectorPartitioning();
  46     }
  47     private final Data data;
  48     private final SelectorPartitioning instance;


 166                     new SimpleData("*", null, null, Color.rgb(0, green += 10, 0), true),
 167                     new SimpleData("*", "c", null, Color.rgb(0, green += 10, 0), true),
 168                     new SimpleData("*", "b.c", null, Color.rgb(0, green += 10, 0), false)
 169                 )},
 170             new Object[] {
 171                 new ComplexData(
 172                     (SimpleSelector)Selector.createSelector("A.b.c"),
 173                     new SimpleData("*", "b", null, Color.rgb(0, green += 10, 0), true),
 174                     new SimpleData("A", "b", null, Color.rgb(0, green += 10, 0), true),
 175                     new SimpleData("*", null, null, Color.rgb(0, green += 10, 0), true),
 176                     new SimpleData("*", "c", null, Color.rgb(0, green += 10, 0), true),
 177                     new SimpleData("*", "b.c", null, Color.rgb(0, green += 10, 0), true)
 178                 )}
 179         });
 180     }    
 181 
 182     @Test
 183     public void testSelectorPartitionAndMatch() {
 184 
 185         Stylesheet stylesheet = 
 186                 CSSParser.getInstance().parse(data.stylesheetText);
 187                 
 188         for (Rule rule : stylesheet.getRules()) {
 189             for (Selector selector : rule.getUnobservedSelectorList()) {
 190                 instance.partition(selector);
 191             }
 192         }
 193         
 194         if (data instanceof SimpleData) {
 195             testWithSimpleData((SimpleData)data, stylesheet);            
 196         } else {
 197             testWithComplexData((ComplexData)data, stylesheet);
 198         }
 199     }
 200     
 201     private void testWithSimpleData(SimpleData simpleData, Stylesheet stylesheet) {
 202                 
 203         SimpleSelector simple = simpleData.selector;
 204         
 205         List<Selector> matched = instance.match(simple.getId(), simple.getName(), simple.getStyleClassSet());
 206         




   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.SelectorPartitioning;
  29 

  30 import java.util.Arrays;
  31 import java.util.Collection;
  32 import java.util.List;
  33 import javafx.scene.paint.Color;
  34 import org.junit.Test;
  35 import static org.junit.Assert.*;
  36 
  37 import org.junit.runner.RunWith;
  38 import org.junit.runners.Parameterized;
  39 import org.junit.runners.Parameterized.Parameters;
  40 
  41 @RunWith(Parameterized.class)
  42 public class SelectorPartitioningTest {
  43     
  44     public SelectorPartitioningTest(final Data data) {
  45         this.data = data;
  46         this.instance = new SelectorPartitioning();
  47     }
  48     private final Data data;
  49     private final SelectorPartitioning instance;


 167                     new SimpleData("*", null, null, Color.rgb(0, green += 10, 0), true),
 168                     new SimpleData("*", "c", null, Color.rgb(0, green += 10, 0), true),
 169                     new SimpleData("*", "b.c", null, Color.rgb(0, green += 10, 0), false)
 170                 )},
 171             new Object[] {
 172                 new ComplexData(
 173                     (SimpleSelector)Selector.createSelector("A.b.c"),
 174                     new SimpleData("*", "b", null, Color.rgb(0, green += 10, 0), true),
 175                     new SimpleData("A", "b", null, Color.rgb(0, green += 10, 0), true),
 176                     new SimpleData("*", null, null, Color.rgb(0, green += 10, 0), true),
 177                     new SimpleData("*", "c", null, Color.rgb(0, green += 10, 0), true),
 178                     new SimpleData("*", "b.c", null, Color.rgb(0, green += 10, 0), true)
 179                 )}
 180         });
 181     }    
 182 
 183     @Test
 184     public void testSelectorPartitionAndMatch() {
 185 
 186         Stylesheet stylesheet = 
 187                 new CssParser().parse(data.stylesheetText);
 188                 
 189         for (Rule rule : stylesheet.getRules()) {
 190             for (Selector selector : rule.getUnobservedSelectorList()) {
 191                 instance.partition(selector);
 192             }
 193         }
 194         
 195         if (data instanceof SimpleData) {
 196             testWithSimpleData((SimpleData)data, stylesheet);            
 197         } else {
 198             testWithComplexData((ComplexData)data, stylesheet);
 199         }
 200     }
 201     
 202     private void testWithSimpleData(SimpleData simpleData, Stylesheet stylesheet) {
 203                 
 204         SimpleSelector simple = simpleData.selector;
 205         
 206         List<Selector> matched = instance.match(simple.getId(), simple.getName(), simple.getStyleClassSet());
 207