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.

PropertyListMocks.java 3.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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.fo.properties;
  19. import static org.mockito.Matchers.anyInt;
  20. import static org.mockito.Mockito.mock;
  21. import static org.mockito.Mockito.when;
  22. import org.apache.fop.fo.Constants;
  23. import org.apache.fop.fo.PropertyList;
  24. import org.apache.fop.fo.expr.PropertyException;
  25. /**
  26. * A helper class for mocking a property list.
  27. */
  28. public final class PropertyListMocks {
  29. private PropertyListMocks() { }
  30. /**
  31. * Creates and returns a mock property list returning a generic default for the
  32. * {@link PropertyList#get(int)} method.
  33. *
  34. * @return a mock property list
  35. */
  36. public static PropertyList mockPropertyList() {
  37. try {
  38. final PropertyList mockPList = mock(PropertyList.class);
  39. final Property mockGenericProperty = PropertyMocks.mockGenericProperty();
  40. when(mockPList.get(anyInt())).thenReturn(mockGenericProperty);
  41. return mockPList;
  42. } catch (PropertyException e) {
  43. throw new RuntimeException(e);
  44. }
  45. }
  46. /**
  47. * Overrides with working mock properties the values returned by
  48. * {@link PropertyList#get(int)} for {@link Constants#PR_COLUMN_NUMBER},
  49. * {@link Constants#PR_NUMBER_COLUMNS_SPANNED},
  50. * {@link Constants#PR_NUMBER_ROWS_SPANNED} and {@link Constants#PR_BORDER_COLLAPSE}.
  51. *
  52. * @param mockPList a mock property list
  53. */
  54. public static void mockTableProperties(PropertyList mockPList) {
  55. try {
  56. final Property mockNumberProperty = PropertyMocks.mockNumberProperty();
  57. when(mockPList.get(Constants.PR_COLUMN_NUMBER)).thenReturn(mockNumberProperty);
  58. when(mockPList.get(Constants.PR_NUMBER_COLUMNS_SPANNED)).thenReturn(mockNumberProperty);
  59. when(mockPList.get(Constants.PR_NUMBER_ROWS_SPANNED)).thenReturn(mockNumberProperty);
  60. final Property borderCollapseProperty = mock(Property.class);
  61. when(borderCollapseProperty.getEnum()).thenReturn(Constants.EN_SEPARATE);
  62. when(mockPList.get(Constants.PR_BORDER_COLLAPSE)).thenReturn(borderCollapseProperty);
  63. final Property writingModeProperty = mock(Property.class);
  64. when(writingModeProperty.getEnum()).thenReturn(Constants.EN_LR_TB);
  65. when(mockPList.get(Constants.PR_WRITING_MODE)).thenReturn(writingModeProperty);
  66. } catch (PropertyException e) {
  67. throw new RuntimeException(e);
  68. }
  69. }
  70. /**
  71. * Overrides with a working mock property the value returned by
  72. * {@link PropertyList#getBorderPaddingBackgroundProps()}.
  73. *
  74. * @param mockPList a mock property list
  75. */
  76. public static void mockCommonBorderPaddingBackgroundProps(PropertyList mockPList) {
  77. try {
  78. final CommonBorderPaddingBackground mockCommonBorderPaddingBackground
  79. = mock(CommonBorderPaddingBackground.class);
  80. when(mockPList.getBorderPaddingBackgroundProps())
  81. .thenReturn(mockCommonBorderPaddingBackground);
  82. } catch (PropertyException e) {
  83. throw new RuntimeException(e);
  84. }
  85. }
  86. }