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.

VersionTestCase.java 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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 org.junit.Test;
  20. import static org.junit.Assert.assertEquals;
  21. import static org.junit.Assert.assertTrue;
  22. /**
  23. * This is a test case for ({@link Version}.
  24. */
  25. public class VersionTestCase {
  26. /**
  27. * Test the <code>getValue()</code> method. This should return {@link Version} given a
  28. * {@link String}.
  29. */
  30. @Test
  31. public void testGetValue() {
  32. int index = 0;
  33. for (Version version : Version.values()) {
  34. if (index > 7) {
  35. assertEquals(version, Version.getValueOf("2.0"));
  36. } else {
  37. assertEquals(version, Version.getValueOf("1." + index++));
  38. }
  39. }
  40. }
  41. @Test(expected = IllegalArgumentException.class)
  42. public void testGetValueIllegalArgument() {
  43. Version.getValueOf("blah");
  44. }
  45. /**
  46. * Tests that the <code>toString()</method> method returns the PDF version string of the proper
  47. * format.
  48. */
  49. @Test
  50. public void testToString() {
  51. // Test all the normal values
  52. int index = 0;
  53. for (Version version : Version.values()) {
  54. if (index > 7) {
  55. assertTrue(version.toString().equals("2.0"));
  56. } else {
  57. assertTrue(version.toString().equals("1." + index++));
  58. }
  59. }
  60. }
  61. /**
  62. * Tests that the <code>compareTo()</code> contract is obeyed.
  63. */
  64. @Test
  65. public void testCompareTo() {
  66. // Ensure that the implicit comparison contract is satisfied
  67. Version[] expected = {
  68. Version.V1_0,
  69. Version.V1_1,
  70. Version.V1_2,
  71. Version.V1_3,
  72. Version.V1_4,
  73. Version.V1_5,
  74. Version.V1_6,
  75. Version.V1_7,
  76. Version.V2_0
  77. };
  78. Version[] actual = Version.values();
  79. for (int i = 0; i < actual.length - 1; i++) {
  80. assertEquals(-1, actual[i].compareTo(expected[i + 1]));
  81. assertEquals(0, actual[i].compareTo(expected[i]));
  82. assertEquals(1, actual[i + 1].compareTo(expected[i]));
  83. }
  84. }
  85. }