You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

TableCellLayoutManagerTestCase.java 5.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one or more
  3. * contributor license agreements. See the NOTICE file distributed with
  4. * this work for additional information regarding copyright ownership.
  5. * The ASF licenses this file to You under the Apache License, Version 2.0
  6. * (the "License"); you may not use this file except in compliance with
  7. * the License. You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. /* $Id:$ */
  18. package org.apache.fop.layoutmgr.table;
  19. import java.awt.Color;
  20. import org.junit.Test;
  21. import static org.mockito.Mockito.mock;
  22. import static org.mockito.Mockito.verify;
  23. import static org.mockito.Mockito.when;
  24. import org.apache.fop.fo.flow.table.PrimaryGridUnit;
  25. import org.apache.fop.fo.flow.table.Table;
  26. import org.apache.fop.fo.flow.table.TableCell;
  27. import org.apache.fop.fo.flow.table.TableColumn;
  28. import org.apache.fop.fo.flow.table.TableHeader;
  29. import org.apache.fop.fo.flow.table.TableRow;
  30. import org.apache.fop.fo.properties.CommonBorderPaddingBackground;
  31. import org.apache.fop.fo.properties.CommonBorderPaddingBackground.BorderInfo;
  32. import org.apache.fop.fo.properties.CondLengthProperty;
  33. import org.apache.fop.layoutmgr.LayoutContext;
  34. import org.apache.fop.layoutmgr.PageSequenceLayoutManager;
  35. import org.apache.fop.layoutmgr.PositionIterator;
  36. import org.apache.fop.layoutmgr.RetrieveTableMarkerLayoutManager;
  37. public class TableCellLayoutManagerTestCase {
  38. // this test aims to check that the first call to addAreas() calls
  39. // TLM.saveTableHeaderTableCellLayoutManagers() but the second call, through repeatAddAreas()
  40. // does not call it again; there are a lot of mocks here, but just the necessary so that the
  41. // addAreas() call can run to completion without NPE; also, the mocking needs to be done so
  42. // the methods isDecendantOfTableHeaderOrFooter() and hasRetrieveTableMarker() return true.
  43. @Test
  44. public void testRepeatAddAreas() {
  45. LayoutContext lc = LayoutContext.newInstance();
  46. // mock background
  47. CommonBorderPaddingBackground cbpb = mock(CommonBorderPaddingBackground.class);
  48. // mock conditional length property
  49. CondLengthProperty clp = mock(CondLengthProperty.class);
  50. when(clp.getLengthValue()).thenReturn(0);
  51. // real border info
  52. BorderInfo bi = BorderInfo.getInstance(0, clp, Color.BLACK, clp, clp);
  53. // mock column
  54. TableColumn tcol = mock(TableColumn.class);
  55. when(tcol.getCommonBorderPaddingBackground()).thenReturn(cbpb);
  56. // mock table
  57. Table t = mock(Table.class);
  58. when(t.getColumn(0)).thenReturn(tcol);
  59. // mock header
  60. TableHeader th = mock(TableHeader.class);
  61. when(th.getCommonBorderPaddingBackground()).thenReturn(cbpb);
  62. // mock row
  63. TableRow tr = mock(TableRow.class);
  64. when(tr.getParent()).thenReturn(th);
  65. // mock cell
  66. TableCell tc = mock(TableCell.class);
  67. when(tc.hasRetrieveTableMarker()).thenReturn(true);
  68. when(tc.getTable()).thenReturn(t);
  69. when(tc.getId()).thenReturn("cellId");
  70. when(tc.getCommonBorderPaddingBackground()).thenReturn(cbpb);
  71. when(tc.getParent()).thenReturn(tr);
  72. // mock PGU
  73. PrimaryGridUnit pgu = mock(PrimaryGridUnit.class);
  74. when(pgu.getCell()).thenReturn(tc);
  75. when(pgu.getColIndex()).thenReturn(0);
  76. when(pgu.getBorderBefore(0)).thenReturn(bi);
  77. when(pgu.getBorderAfter(0)).thenReturn(bi);
  78. when(pgu.getBorderEnd()).thenReturn(bi);
  79. when(pgu.getBorderStart()).thenReturn(bi);
  80. when(pgu.getTablePart()).thenReturn(th);
  81. // mock RTMLM
  82. RetrieveTableMarkerLayoutManager rtmlm = mock(RetrieveTableMarkerLayoutManager.class);
  83. when(rtmlm.isFinished()).thenReturn(true); // avoids infinite loop
  84. // mock PSLM
  85. PageSequenceLayoutManager pslm = mock(PageSequenceLayoutManager.class);
  86. // mock TLM
  87. TableLayoutManager tlm = mock(TableLayoutManager.class);
  88. when(tlm.getPSLM()).thenReturn(pslm);
  89. // mock PI
  90. PositionIterator pi = mock(PositionIterator.class);
  91. // mock RP
  92. RowPainter rp = mock(RowPainter.class);
  93. // real TCLM, not a mock!
  94. TableCellLayoutManager tclm = new TableCellLayoutManager(tc, pgu);
  95. tclm.addChildLM(rtmlm);
  96. tclm.setParent(tlm);
  97. // lets call addAreas
  98. int[] n = {};
  99. tclm.addAreas(pi, lc, n, 0, 0, 0, 0, true, true, rp, 0);
  100. // check the TCLM is added to the TLM
  101. verify(tlm).saveTableHeaderTableCellLayoutManagers(tclm);
  102. // call the repeat
  103. tclm.repeatAddAreas();
  104. // check the TCLM was not added again
  105. verify(tlm).saveTableHeaderTableCellLayoutManagers(tclm);
  106. }
  107. }