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.

AltTextHolderTestCase.java 2.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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 org.junit.Test;
  20. import static org.junit.Assert.assertEquals;
  21. import static org.mockito.Mockito.mock;
  22. import static org.mockito.Mockito.when;
  23. import org.apache.fop.apps.FOPException;
  24. import org.apache.fop.apps.FOUserAgent;
  25. import org.apache.fop.fo.Constants;
  26. import org.apache.fop.fo.FONode;
  27. import org.apache.fop.fo.FONodeMocks;
  28. import org.apache.fop.fo.PropertyList;
  29. import org.apache.fop.fo.expr.PropertyException;
  30. import org.apache.fop.fo.flow.AbstractGraphics;
  31. import org.apache.fop.fo.flow.ExternalGraphic;
  32. import org.apache.fop.fo.flow.InstreamForeignObject;
  33. /**
  34. * Tests that the fox:alt-text property is correctly set on objects that support it.
  35. */
  36. public class AltTextHolderTestCase {
  37. private final String altText = "alternative text";
  38. @Test
  39. public void externalGraphicHasAltText() throws FOPException {
  40. testAltTextGetter(new ExternalGraphic(mockFONode()));
  41. }
  42. @Test
  43. public void instreamForeignObjectHasAltText() throws FOPException {
  44. testAltTextGetter(new InstreamForeignObject(mockFONode()));
  45. }
  46. private FONode mockFONode() {
  47. FONode mockFONode = FONodeMocks.mockFONode();
  48. FOUserAgent mockFOUserAgent = mockFONode.getFOEventHandler().getUserAgent();
  49. when(mockFOUserAgent.isAccessibilityEnabled()).thenReturn(true);
  50. return mockFONode;
  51. }
  52. private void testAltTextGetter(AbstractGraphics g) throws FOPException {
  53. g.bind(mockPropertyList());
  54. assertEquals(altText, g.getAltText());
  55. }
  56. private PropertyList mockPropertyList() throws PropertyException {
  57. PropertyList mockPropertyList = PropertyListMocks.mockPropertyList();
  58. Property mockAltText = mock(Property.class);
  59. when(mockAltText.getString()).thenReturn(altText);
  60. when(mockPropertyList.get(Constants.PR_X_ALT_TEXT)).thenReturn(mockAltText);
  61. return mockPropertyList;
  62. }
  63. }