1717import static org .assertj .core .api .Assertions .assertThat ;
1818import static org .junit .jupiter .api .Assertions .assertNotNull ;
1919
20- import java .util .List ;
2120import java .util .stream .IntStream ;
21+ import java .util .stream .Stream ;
2222
2323import org .eclipse .e4 .ui .tests .css .core .util .ParserTestUtil ;
2424import org .junit .jupiter .api .Test ;
@@ -40,12 +40,16 @@ void testMediaRule() throws Exception {
4040 Label { background-color: #FF0000 }""" ;
4141 CSSStyleSheet styleSheet = ParserTestUtil .parseCss (css );
4242 assertNotNull (styleSheet );
43- List <String > cssRules = IntStream .range (0 , styleSheet .getCssRules ().getLength ())
44- .mapToObj (i -> styleSheet .getCssRules ().item (i ).getCssText ()).toList ();
43+ // This one is provided only inside the @media so it shouldn't be there
44+ assertThat (findCssRuleThatContains (styleSheet , "background-color" )).isEmpty ();
45+ // This one is provided outside the @media and it shouldn't be overwritten by
46+ // any of them
47+ assertThat (findCssRuleThatContains (styleSheet , "line-height" )).containsOnly ("BODY { line-height: 1.3; }" );
48+ }
4549
46- assertThat ( cssRules . stream (). filter ( it -> it . contains ( "background-color" )). toList ())
47- . containsOnly ( "Label { background-color: rgb(255, 0, 0); }" );
48- assertThat ( cssRules . stream (). filter ( it -> it . contains ( "line-height" )). toList ())
49- . containsOnly ( "BODY { line-height: 1.3; }" );
50+ private Stream < String > findCssRuleThatContains ( CSSStyleSheet styleSheet , String text ) {
51+ Stream < String > cssRulesText = IntStream . range ( 0 , styleSheet . getCssRules (). getLength ())
52+ . mapToObj ( i -> styleSheet . getCssRules (). item ( i ). getCssText ());
53+ return cssRulesText . filter ( r -> r . contains ( text ) );
5054 }
5155}
0 commit comments