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.

FontManagerTestCase.java 3.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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.fonts;
  18. import java.io.File;
  19. import java.net.URI;
  20. import java.net.URISyntaxException;
  21. import org.junit.Assert;
  22. import org.junit.Before;
  23. import org.junit.Test;
  24. import org.mockito.InOrder;
  25. import static org.mockito.ArgumentMatchers.nullable;
  26. import static org.mockito.Mockito.inOrder;
  27. import static org.mockito.Mockito.mock;
  28. import static org.mockito.Mockito.verify;
  29. import org.apache.fop.apps.FOPException;
  30. import org.apache.fop.apps.io.InternalResourceResolver;
  31. import org.apache.fop.apps.io.ResourceResolverFactory;
  32. public class FontManagerTestCase {
  33. private FontManager sut;
  34. private FontCacheManager fontCacheManager;
  35. private FontDetector fontDetector;
  36. private InternalResourceResolver resolver;
  37. @Before
  38. public void setUp() {
  39. resolver = mock(InternalResourceResolver.class);
  40. fontCacheManager = mock(FontCacheManager.class);
  41. fontDetector = mock(FontDetector.class);
  42. sut = new FontManager(resolver, fontDetector, fontCacheManager);
  43. }
  44. @Test
  45. public void testSetCacheFile() {
  46. URI testURI = URI.create("test/uri");
  47. sut.setCacheFile(testURI);
  48. InOrder inOrder = inOrder(resolver, fontCacheManager);
  49. inOrder.verify(resolver).resolveFromBase(testURI);
  50. inOrder.verify(fontCacheManager).setCacheFile(nullable(URI.class));
  51. }
  52. @Test
  53. public void testSetCacheURL() throws URISyntaxException {
  54. InternalResourceResolver rr = ResourceResolverFactory.createDefaultInternalResourceResolver(
  55. new File(".").toURI());
  56. String uri = "abc://localhost/f";
  57. EmbedFontInfo efi = new EmbedFontInfo(new FontUris(new URI(uri), null), false, false, null, null);
  58. FontCache fc = new FontCache();
  59. fc.addFont(efi, rr);
  60. Assert.assertTrue(fc.containsFont(uri));
  61. }
  62. @Test
  63. public void testGetFontCache() {
  64. sut.getFontCache();
  65. verify(fontCacheManager).load();
  66. }
  67. @Test
  68. public void testSaveCache() throws FOPException {
  69. sut.saveCache();
  70. verify(fontCacheManager).save();
  71. }
  72. @Test
  73. public void testDeleteCache() throws FOPException {
  74. sut.deleteCache();
  75. verify(fontCacheManager).delete();
  76. }
  77. }