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.

AbstractIFPainterTestCase.java 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. package org.apache.fop.render.intermediate;
  18. import java.awt.Dimension;
  19. import java.awt.Paint;
  20. import java.awt.Rectangle;
  21. import java.awt.geom.AffineTransform;
  22. import org.junit.Before;
  23. import org.junit.Test;
  24. import org.w3c.dom.Document;
  25. import static org.junit.Assert.assertEquals;
  26. import static org.mockito.Mockito.mock;
  27. import static org.mockito.Mockito.when;
  28. import org.apache.fop.fonts.FontInfo;
  29. import org.apache.fop.fonts.FontTriplet;
  30. import org.apache.fop.render.RenderingContext;
  31. import org.apache.fop.traits.BorderProps;
  32. public class AbstractIFPainterTestCase {
  33. private AbstractIFPainter<?> sut;
  34. private IFDocumentHandler handler;
  35. @Before
  36. public void setUp() {
  37. handler = mock(IFDocumentHandler.class);
  38. sut = new AbstractIFPainter<IFDocumentHandler>(handler) {
  39. public void startViewport(AffineTransform transform, Dimension size, Rectangle clipRect)
  40. throws IFException {
  41. }
  42. public void endViewport() throws IFException {
  43. }
  44. public void startGroup(AffineTransform transform, String layer) throws IFException {
  45. }
  46. public void endGroup() throws IFException {
  47. }
  48. public void clipRect(Rectangle rect) throws IFException {
  49. }
  50. public void clipBackground(Rectangle rect, BorderProps bpsBefore, BorderProps bpsAfter,
  51. BorderProps bpsStart, BorderProps bpsEnd) throws IFException {
  52. }
  53. public void fillRect(Rectangle rect, Paint fill) throws IFException {
  54. }
  55. public void drawImage(String uri, Rectangle rect) throws IFException {
  56. }
  57. public void drawImage(Document doc, Rectangle rect) throws IFException {
  58. }
  59. @Override
  60. protected RenderingContext createRenderingContext() {
  61. return null;
  62. }
  63. public void drawText(int x, int y, int letterSpacing, int wordSpacing, int[][] dp,
  64. String text) throws IFException {
  65. }
  66. };
  67. FontInfo fontInfo = mock(FontInfo.class);
  68. when(handler.getFontInfo()).thenReturn(fontInfo);
  69. }
  70. @Test
  71. public void testGetFontKey() throws IFException {
  72. String expected = "the expected string";
  73. FontTriplet triplet = mock(FontTriplet.class);
  74. FontInfo fontInfo = handler.getFontInfo();
  75. when(fontInfo.getInternalFontKey(triplet)).thenReturn(expected);
  76. assertEquals(expected, sut.getFontKey(triplet));
  77. }
  78. @Test(expected = IFException.class)
  79. public void testGetFontKeyMissingFont() throws IFException {
  80. FontTriplet triplet = mock(FontTriplet.class);
  81. when(handler.getFontInfo().getInternalFontKey(triplet)).thenReturn(null);
  82. sut.getFontKey(triplet);
  83. }
  84. }