Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

FileIDGeneratorTestCase.java 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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.pdf;
  19. import java.util.Arrays;
  20. import junit.framework.Test;
  21. import junit.framework.TestCase;
  22. import junit.framework.TestSuite;
  23. /**
  24. * Tests the {@link FileIDGenerator} class.
  25. */
  26. public abstract class FileIDGeneratorTestCase extends TestCase {
  27. /**
  28. * Returns a suite containing all the {@link FileIDGenerator} test cases.
  29. *
  30. * @return the test suite
  31. */
  32. public static final Test suite() {
  33. TestSuite suite = new TestSuite(new Class[] {
  34. RandomFileIDGeneratorTestCase.class,
  35. DigestFileIDGeneratorTestCase.class },
  36. FileIDGeneratorTestCase.class.getName());
  37. return suite;
  38. }
  39. /** The generator under test. */
  40. protected FileIDGenerator fileIDGenerator;
  41. /** Tests that the getOriginalFileID method generates valid output. */
  42. public void testOriginal() {
  43. byte[] fileID = fileIDGenerator.getOriginalFileID();
  44. fileIDMustBeValid(fileID);
  45. }
  46. /** Tests that the getUpdatedFileID method generates valid output. */
  47. public void testUpdated() {
  48. byte[] fileID = fileIDGenerator.getUpdatedFileID();
  49. fileIDMustBeValid(fileID);
  50. }
  51. private void fileIDMustBeValid(byte[] fileID) {
  52. assertNotNull(fileID);
  53. assertEquals(16, fileID.length);
  54. }
  55. /** Tests that multiple calls to getOriginalFileID method always return the same value. */
  56. public void testOriginalMultipleCalls() {
  57. byte[] fileID1 = fileIDGenerator.getUpdatedFileID();
  58. byte[] fileID2 = fileIDGenerator.getUpdatedFileID();
  59. assertTrue(Arrays.equals(fileID1, fileID2));
  60. }
  61. /** Tests that getUpdatedFileID returns the same value as getOriginalFileID. */
  62. public void testUpdateEqualsOriginal() {
  63. byte[] originalFileID = fileIDGenerator.getOriginalFileID();
  64. byte[] updatedFileID = fileIDGenerator.getUpdatedFileID();
  65. assertTrue(Arrays.equals(originalFileID, updatedFileID));
  66. }
  67. /**
  68. * Tests the random file ID generator.
  69. */
  70. public static class RandomFileIDGeneratorTestCase extends FileIDGeneratorTestCase {
  71. @Override
  72. protected void setUp() throws Exception {
  73. fileIDGenerator = FileIDGenerator.getRandomFileIDGenerator();
  74. }
  75. }
  76. /**
  77. * Tests the file ID generator based on an MD5 digest.
  78. */
  79. public static class DigestFileIDGeneratorTestCase extends FileIDGeneratorTestCase {
  80. @Override
  81. protected void setUp() throws Exception {
  82. fileIDGenerator = FileIDGenerator.getDigestFileIDGenerator(
  83. new PDFDocument("Apache FOP"));
  84. }
  85. }
  86. }