Skip to content

Commit 43a69c6

Browse files
committed
refactored media rule test
1 parent fe06271 commit 43a69c6

File tree

1 file changed

+11
-7
lines changed
  • tests/org.eclipse.e4.ui.tests.css.core/src/org/eclipse/e4/ui/tests/css/core/parser

1 file changed

+11
-7
lines changed

tests/org.eclipse.e4.ui.tests.css.core/src/org/eclipse/e4/ui/tests/css/core/parser/MediaRulesTest.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
import static org.assertj.core.api.Assertions.assertThat;
1818
import static org.junit.jupiter.api.Assertions.assertNotNull;
1919

20-
import java.util.List;
2120
import java.util.stream.IntStream;
21+
import java.util.stream.Stream;
2222

2323
import org.eclipse.e4.ui.tests.css.core.util.ParserTestUtil;
2424
import 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

Comments
 (0)