|
| 1 | +package com.itextpdf.layout.renderer; |
| 2 | + |
| 3 | +import com.itextpdf.io.source.ByteArrayOutputStream; |
| 4 | +import com.itextpdf.kernel.PdfException; |
| 5 | +import com.itextpdf.kernel.pdf.PdfDocument; |
| 6 | +import com.itextpdf.kernel.pdf.PdfWriter; |
| 7 | +import com.itextpdf.layout.element.AreaBreak; |
| 8 | +import com.itextpdf.layout.element.Text; |
| 9 | +import com.itextpdf.layout.layout.LayoutContext; |
| 10 | +import com.itextpdf.layout.layout.LayoutResult; |
| 11 | +import com.itextpdf.layout.property.Property; |
| 12 | +import com.itextpdf.test.ExtendedITextTest; |
| 13 | +import com.itextpdf.test.annotations.type.UnitTest; |
| 14 | +import org.junit.Assert; |
| 15 | +import org.junit.Rule; |
| 16 | +import org.junit.Test; |
| 17 | +import org.junit.experimental.categories.Category; |
| 18 | +import org.junit.rules.ExpectedException; |
| 19 | + |
| 20 | +@Category(UnitTest.class) |
| 21 | +public class AreaBreakRendererUnitTest extends ExtendedITextTest { |
| 22 | + |
| 23 | + @Rule |
| 24 | + public ExpectedException junitExpectedException = ExpectedException.none(); |
| 25 | + |
| 26 | + @Test |
| 27 | + public void addChildTestUnsupported() { |
| 28 | + junitExpectedException.expect(RuntimeException.class); |
| 29 | + |
| 30 | + AreaBreakRenderer areaBreakRenderer = new AreaBreakRenderer(new AreaBreak()); |
| 31 | + Assert.assertNull(areaBreakRenderer.getChildRenderers()); |
| 32 | + |
| 33 | + areaBreakRenderer.addChild(new TextRenderer(new Text("Test"))); |
| 34 | + } |
| 35 | + |
| 36 | + @Test |
| 37 | + public void drawTestUnsupported() { |
| 38 | + junitExpectedException.expect(UnsupportedOperationException.class); |
| 39 | + |
| 40 | + AreaBreakRenderer areaBreakRenderer = new AreaBreakRenderer(new AreaBreak()); |
| 41 | + areaBreakRenderer.draw(new DrawContext(new PdfDocument(new PdfWriter(new ByteArrayOutputStream())), null)); |
| 42 | + } |
| 43 | + |
| 44 | + @Test |
| 45 | + public void getOccupiedAreaTestUnsupported() { |
| 46 | + junitExpectedException.expect(UnsupportedOperationException.class); |
| 47 | + |
| 48 | + AreaBreakRenderer areaBreakRenderer = new AreaBreakRenderer(new AreaBreak()); |
| 49 | + areaBreakRenderer.getOccupiedArea(); |
| 50 | + } |
| 51 | + |
| 52 | + @Test |
| 53 | + //Properties are not supported for AbstractRenderer, and it's expected that the result is false for all the properties. |
| 54 | + //The BORDER property is chosen without any specific intention. It could be replaced with any other property. |
| 55 | + public void hasPropertyTest() { |
| 56 | + AreaBreakRenderer areaBreakRenderer = new AreaBreakRenderer(new AreaBreak()); |
| 57 | + Assert.assertFalse(areaBreakRenderer.hasProperty(Property.BORDER)); |
| 58 | + } |
| 59 | + |
| 60 | + @Test |
| 61 | + //Properties are not supported for AbstractRenderer, and it's expected that the result is false for all the properties. |
| 62 | + //The BORDER property is chosen without any specific intention. It could be replaced with any other property. |
| 63 | + public void hasOwnPropertyTest() { |
| 64 | + AreaBreakRenderer areaBreakRenderer = new AreaBreakRenderer(new AreaBreak()); |
| 65 | + Assert.assertFalse(areaBreakRenderer.hasProperty(Property.BORDER)); |
| 66 | + } |
| 67 | + |
| 68 | + @Test |
| 69 | + //Properties are not supported for AbstractRenderer, and it's expected that the result is null for all the properties. |
| 70 | + //The BORDER property is chosen without any specific intention. It could be replaced with any other property. |
| 71 | + public void getPropertyTest() { |
| 72 | + AreaBreakRenderer areaBreakRenderer = new AreaBreakRenderer(new AreaBreak()); |
| 73 | + Assert.assertNull(areaBreakRenderer.<Property>getProperty(Property.BORDER)); |
| 74 | + } |
| 75 | + |
| 76 | + @Test |
| 77 | + //Properties are not supported for AbstractRenderer, and it's expected that the result is null for all the properties. |
| 78 | + //The BORDER property is chosen without any specific intention. It could be replaced with any other property. |
| 79 | + public void getOwnPropertyTest() { |
| 80 | + AreaBreakRenderer areaBreakRenderer = new AreaBreakRenderer(new AreaBreak()); |
| 81 | + Assert.assertNull(areaBreakRenderer.<Property>getOwnProperty(Property.BORDER)); |
| 82 | + } |
| 83 | + |
| 84 | + @Test |
| 85 | + //Properties are not supported for AbstractRenderer, and it's expected that the result is null for all the properties. |
| 86 | + //The BORDER property is chosen without any specific intention. It could be replaced with any other property. |
| 87 | + public void getDefaultPropertyTest() { |
| 88 | + AreaBreakRenderer areaBreakRenderer = new AreaBreakRenderer(new AreaBreak()); |
| 89 | + Assert.assertNull(areaBreakRenderer.<Property>getDefaultProperty(Property.BORDER)); |
| 90 | + } |
| 91 | + |
| 92 | + @Test |
| 93 | + //The BORDER_RADIUS property is chosen without any specific intention. It could be replaced with any other property. |
| 94 | + public void getPropertyWithDefaultValueTestUnsupported() { |
| 95 | + junitExpectedException.expect(UnsupportedOperationException.class); |
| 96 | + |
| 97 | + AreaBreakRenderer areaBreakRenderer = new AreaBreakRenderer(new AreaBreak()); |
| 98 | + areaBreakRenderer.getProperty(Property.BORDER_RADIUS, 3); |
| 99 | + } |
| 100 | + |
| 101 | + @Test |
| 102 | + //The BORDER_RADIUS property is chosen without any specific intention. It could be replaced with any other property. |
| 103 | + public void setPropertyTestUnsupported() { |
| 104 | + junitExpectedException.expect(UnsupportedOperationException.class); |
| 105 | + |
| 106 | + AreaBreakRenderer areaBreakRenderer = new AreaBreakRenderer(new AreaBreak()); |
| 107 | + areaBreakRenderer.setProperty(Property.BORDER_RADIUS, 5); |
| 108 | + } |
| 109 | + |
| 110 | + @Test |
| 111 | + //The BORDER property is chosen without any specific intention. It could be replaced with any other property. |
| 112 | + //Here we just check that no exception has been thrown. |
| 113 | + public void deleteOwnProperty() { |
| 114 | + AreaBreakRenderer areaBreakRenderer = new AreaBreakRenderer(new AreaBreak()); |
| 115 | + areaBreakRenderer.deleteOwnProperty(Property.BORDER); |
| 116 | + Assert.assertTrue(true); |
| 117 | + } |
| 118 | + |
| 119 | + @Test |
| 120 | + public void getModelElementTest() { |
| 121 | + AreaBreakRenderer areaBreakRenderer = new AreaBreakRenderer(new AreaBreak()); |
| 122 | + Assert.assertNull(areaBreakRenderer.getModelElement()); |
| 123 | + } |
| 124 | + |
| 125 | + @Test |
| 126 | + public void getParentTest() { |
| 127 | + AreaBreakRenderer areaBreakRenderer = new AreaBreakRenderer(new AreaBreak()); |
| 128 | + Assert.assertNull(areaBreakRenderer.getParent()); |
| 129 | + } |
| 130 | + |
| 131 | + @Test |
| 132 | + public void setParentTest() { |
| 133 | + AreaBreakRenderer areaBreakRenderer = new AreaBreakRenderer(new AreaBreak()); |
| 134 | + Assert.assertEquals(areaBreakRenderer, areaBreakRenderer.setParent(new AreaBreakRenderer(new AreaBreak()))); |
| 135 | + } |
| 136 | + |
| 137 | + @Test |
| 138 | + public void isFlushedTest() { |
| 139 | + AreaBreakRenderer areaBreakRenderer = new AreaBreakRenderer(new AreaBreak()); |
| 140 | + Assert.assertFalse(areaBreakRenderer.isFlushed()); |
| 141 | + } |
| 142 | + |
| 143 | + @Test |
| 144 | + public void moveTestUnsupported() { |
| 145 | + junitExpectedException.expect(UnsupportedOperationException.class); |
| 146 | + |
| 147 | + AreaBreakRenderer areaBreakRenderer = new AreaBreakRenderer(new AreaBreak()); |
| 148 | + areaBreakRenderer.move(2.0f, 2.0f); |
| 149 | + } |
| 150 | + |
| 151 | + @Test |
| 152 | + public void getNextRendererTest() { |
| 153 | + AreaBreakRenderer areaBreakRenderer = new AreaBreakRenderer(new AreaBreak()); |
| 154 | + Assert.assertNull(areaBreakRenderer.getNextRenderer()); |
| 155 | + } |
| 156 | + |
| 157 | + @Test |
| 158 | + public void layoutTest() { |
| 159 | + AreaBreakRenderer areaBreakRenderer = new AreaBreakRenderer(new AreaBreak()); |
| 160 | + LayoutResult layoutResult = areaBreakRenderer.layout(new LayoutContext(null)); |
| 161 | + Assert.assertEquals(LayoutResult.NOTHING, layoutResult.getStatus()); |
| 162 | + Assert.assertNull(layoutResult.getOccupiedArea()); |
| 163 | + Assert.assertNull(layoutResult.getSplitRenderer()); |
| 164 | + Assert.assertNull(layoutResult.getOverflowRenderer()); |
| 165 | + Assert.assertEquals(areaBreakRenderer, layoutResult.getCauseOfNothing()); |
| 166 | + Assert.assertEquals(areaBreakRenderer.areaBreak, layoutResult.getAreaBreak()); |
| 167 | + } |
| 168 | + |
| 169 | +} |
0 commit comments