File tree Expand file tree Collapse file tree 3 files changed +62
-6
lines changed
main/java/com/itextpdf/styledxmlparser/css
test/java/com/itextpdf/styledxmlparser/css Expand file tree Collapse file tree 3 files changed +62
-6
lines changed Original file line number Diff line number Diff line change @@ -42,8 +42,6 @@ This file is part of the iText (R) project.
42
42
*/
43
43
package com .itextpdf .styledxmlparser .css ;
44
44
45
- import com .itextpdf .io .util .MessageFormatUtil ;
46
-
47
45
import java .util .ArrayList ;
48
46
import java .util .List ;
49
47
@@ -89,13 +87,11 @@ public void addBodyCssDeclarations(List<CssDeclaration> cssDeclarations) {
89
87
@ Override
90
88
public String toString () {
91
89
StringBuilder sb = new StringBuilder ();
92
- sb .append (MessageFormatUtil .format ("@{0} " , ruleName ));
93
- sb .append ("{" );
94
- sb .append ("\n " );
90
+ sb .append ("@" ).append (getRuleName ()).append (" {" ).append ("\n " );
95
91
for (CssDeclaration declaration : properties ) {
96
92
sb .append (" " );
97
93
sb .append (declaration );
98
- sb .append ("\n " );
94
+ sb .append ("; \n " );
99
95
}
100
96
sb .append ("}" );
101
97
return sb .toString ();
Original file line number Diff line number Diff line change
1
+ package com .itextpdf .styledxmlparser .css ;
2
+
3
+ import com .itextpdf .test .ExtendedITextTest ;
4
+ import com .itextpdf .test .annotations .type .UnitTest ;
5
+ import org .junit .Assert ;
6
+ import org .junit .Test ;
7
+ import org .junit .experimental .categories .Category ;
8
+
9
+ import java .util .ArrayList ;
10
+ import java .util .List ;
11
+
12
+ @ Category (UnitTest .class )
13
+ public class CssFontFaceRuleTest extends ExtendedITextTest {
14
+
15
+ @ Test
16
+ public void verifyThatToStringProducesValidCss () {
17
+ CssFontFaceRule fontFaceRule = new CssFontFaceRule ("" );
18
+ List <CssDeclaration > declarations = new ArrayList <>();
19
+ declarations .add (new CssDeclaration (CommonCssConstants .FONT_FAMILY , "test-font-family" ));
20
+ declarations .add (new CssDeclaration (CommonCssConstants .FONT_WEIGHT , CommonCssConstants .BOLD ));
21
+ fontFaceRule .addBodyCssDeclarations (declarations );
22
+
23
+ String expectedCss = "@font-face {\n " +
24
+ " font-family: test-font-family;\n " +
25
+ " font-weight: bold;\n " +
26
+ "}" ;
27
+ Assert .assertEquals (expectedCss , fontFaceRule .toString ());
28
+ }
29
+
30
+ }
Original file line number Diff line number Diff line change
1
+ package com .itextpdf .styledxmlparser .css ;
2
+
3
+ import com .itextpdf .styledxmlparser .css .page .CssMarginRule ;
4
+ import com .itextpdf .styledxmlparser .css .page .CssPageRule ;
5
+ import com .itextpdf .test .ExtendedITextTest ;
6
+ import com .itextpdf .test .annotations .type .UnitTest ;
7
+ import org .junit .Assert ;
8
+ import org .junit .Test ;
9
+ import org .junit .experimental .categories .Category ;
10
+
11
+ @ Category (UnitTest .class )
12
+ public class CssNestedAtRuleFactoryTest extends ExtendedITextTest {
13
+
14
+ @ Test
15
+ public void testCreatingNestedRule () {
16
+ CssNestedAtRule pageRule = CssNestedAtRuleFactory .createNestedRule ("page:first" );
17
+ Assert .assertTrue (pageRule instanceof CssPageRule );
18
+ Assert .assertEquals (CssRuleName .PAGE , pageRule .getRuleName ());
19
+ Assert .assertEquals (":first" , pageRule .getRuleParameters ());
20
+
21
+ CssNestedAtRule rightBottomMarginRule = CssNestedAtRuleFactory .createNestedRule ("bottom-right" );
22
+ Assert .assertTrue (rightBottomMarginRule instanceof CssMarginRule );
23
+ Assert .assertEquals (CssRuleName .BOTTOM_RIGHT , rightBottomMarginRule .getRuleName ());
24
+
25
+ CssNestedAtRule fontFaceRule = CssNestedAtRuleFactory .createNestedRule ("font-face" );
26
+ Assert .assertTrue (fontFaceRule instanceof CssFontFaceRule );
27
+ Assert .assertEquals (CssRuleName .FONT_FACE , fontFaceRule .getRuleName ());
28
+ }
29
+
30
+ }
You can’t perform that action at this time.
0 commit comments