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.

PSPainterTestCase.java 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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.ps;
  18. import java.io.IOException;
  19. import org.junit.Before;
  20. import org.junit.Test;
  21. import org.mockito.verification.VerificationMode;
  22. import org.apache.xmlgraphics.ps.PSGenerator;
  23. import org.apache.fop.render.intermediate.IFState;
  24. import static org.mockito.Mockito.mock;
  25. import static org.mockito.Mockito.never;
  26. import static org.mockito.Mockito.times;
  27. import static org.mockito.Mockito.verify;
  28. public class PSPainterTestCase {
  29. private PSDocumentHandler docHandler;
  30. private PSPainter psPainter;
  31. private PSGenerator gen;
  32. private IFState state;
  33. @Before
  34. public void setup() {
  35. docHandler = new PSDocumentHandler();
  36. gen = mock(PSGenerator.class);
  37. docHandler.gen = gen;
  38. state = IFState.create();
  39. psPainter = new PSPainter(docHandler, state);
  40. }
  41. @Test
  42. public void testNonZeroFontSize() throws IOException {
  43. testFontSize(6, times(1));
  44. }
  45. @Test
  46. public void testZeroFontSize() throws IOException {
  47. testFontSize(0, never());
  48. }
  49. private void testFontSize(int fontSize, VerificationMode test) throws IOException {
  50. state.setFontSize(fontSize);
  51. try {
  52. psPainter.drawText(10, 10, 2, 2, null, "Test");
  53. } catch (Exception ex) {
  54. //Expected
  55. }
  56. verify(gen, test).useColor(state.getTextColor());
  57. }
  58. }