@@ -54,12 +54,14 @@ This file is part of the iText (R) project.
54
54
import com .itextpdf .layout .element .List ;
55
55
import com .itextpdf .layout .element .Paragraph ;
56
56
import com .itextpdf .layout .property .ListNumberingType ;
57
+ import com .itextpdf .layout .property .Property ;
57
58
import com .itextpdf .test .ExtendedITextTest ;
58
59
import com .itextpdf .test .annotations .LogMessage ;
59
60
import com .itextpdf .test .annotations .LogMessages ;
60
61
import com .itextpdf .test .annotations .type .IntegrationTest ;
61
62
import org .junit .Assert ;
62
63
import org .junit .BeforeClass ;
64
+ import org .junit .Ignore ;
63
65
import org .junit .Test ;
64
66
import org .junit .experimental .categories .Category ;
65
67
@@ -229,5 +231,37 @@ public void keepTogetherDivTest02() throws IOException, InterruptedException {
229
231
Assert .assertNull (new CompareTool ().compareByContent (outFile , cmpFileName , destinationFolder , "diff" ));
230
232
}
231
233
234
+ @ Test
235
+ @ LogMessages (messages = {
236
+ @ LogMessage (messageTemplate = LogMessageConstant .ELEMENT_DOES_NOT_FIT_AREA )
237
+ })
238
+ public void keepTogetherDefaultTest01 () throws IOException , InterruptedException {
239
+ String cmpFileName = sourceFolder + "cmp_keepTogetherDefaultTest01.pdf" ;
240
+ String outFile = destinationFolder + "keepTogetherDefaultTest01.pdf" ;
241
+
242
+ PdfDocument pdfDoc = new PdfDocument (new PdfWriter (outFile ));
243
+ Document doc = new Document (pdfDoc );
244
+
245
+ Div div = new KeepTogetherDiv ();
246
+ doc .add (new Paragraph ("first string" ));
247
+ for (int i = 0 ; i < 130 ; i ++) {
248
+ div .add (new Paragraph ("String number " + i ));
249
+ }
250
+
251
+ doc .add (div );
252
+ doc .close ();
253
+ Assert .assertNull (new CompareTool ().compareByContent (outFile , cmpFileName , destinationFolder , "diff" ));
254
+ }
255
+
256
+ private static class KeepTogetherDiv extends Div {
257
+ @ Override
258
+ public <T1 > T1 getDefaultProperty (int property ) {
259
+ if (property == Property .KEEP_TOGETHER ) {
260
+ return (T1 ) (Object ) true ;
261
+ }
262
+ return super .<T1 >getDefaultProperty (property );
263
+ }
264
+ }
265
+
232
266
233
267
}
0 commit comments