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.

PropertyMocks.java 3.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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.ArgumentMatchers.nullable;
  20. import static org.mockito.Mockito.mock;
  21. import static org.mockito.Mockito.when;
  22. import org.apache.fop.datatypes.Numeric;
  23. import org.apache.fop.datatypes.PercentBaseContext;
  24. import org.apache.fop.fo.Constants;
  25. /**
  26. * Helper class to create mocks of various kinds of properties.
  27. */
  28. public final class PropertyMocks {
  29. private PropertyMocks() { }
  30. /**
  31. * Creates and returns a generic mock property returning decent defaults for the
  32. * {@link Property#getString()}, {@link Property#getEnum()} and
  33. * {@link Property#getLengthRange()} methods.
  34. *
  35. * @return a mock all-purpose property
  36. */
  37. public static Property mockGenericProperty() {
  38. final Property mockGenericProperty = mock(Property.class);
  39. when(mockGenericProperty.getString()).thenReturn("A non-empty string");
  40. when(mockGenericProperty.getEnum()).thenReturn(Constants.EN_SPACE);
  41. LengthRangeProperty lengthRangeProperty = mockLengthRangeProperty();
  42. when(mockGenericProperty.getLengthRange()).thenReturn(lengthRangeProperty);
  43. return mockGenericProperty;
  44. }
  45. private static LengthRangeProperty mockLengthRangeProperty() {
  46. final LengthRangeProperty mockLengthRangeProperty = mock(LengthRangeProperty.class);
  47. final Property optimum = mockOptimumProperty();
  48. when(mockLengthRangeProperty.getOptimum(nullable(PercentBaseContext.class)))
  49. .thenReturn(optimum);
  50. return mockLengthRangeProperty;
  51. }
  52. /**
  53. * Creates and returns a mock property returning a decent default for the
  54. * {@link Property#getNumeric()} method.
  55. *
  56. * @return a mock number property
  57. */
  58. public static Property mockNumberProperty() {
  59. final Property mockNumberProperty = mock(Property.class);
  60. final Numeric mockNumeric = mock(Numeric.class);
  61. when(mockNumberProperty.getNumeric()).thenReturn(mockNumeric);
  62. return mockNumberProperty;
  63. }
  64. private static Property mockOptimumProperty() {
  65. final Property optimum = mock(Property.class);
  66. when(optimum.isAuto()).thenReturn(true);
  67. return optimum;
  68. }
  69. }