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.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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 static org.junit.Assert.assertEquals;
  20. import static org.junit.Assert.assertTrue;
  21. import org.junit.Test;
  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. assertEquals(version, Version.getValueOf("1." + index++));
  35. }
  36. }
  37. @Test(expected = IllegalArgumentException.class)
  38. public void testGetValueIllegalArgument() {
  39. Version.getValueOf("blah");
  40. }
  41. /**
  42. * Tests that the <code>toString()</method> method returns the PDF version string of the proper
  43. * format.
  44. */
  45. @Test
  46. public void testToString() {
  47. // Test all the normal values
  48. int index = 0;
  49. for (Version version : Version.values()) {
  50. assertTrue(version.toString().equals("1." + index++));
  51. }
  52. }
  53. /**
  54. * Tests that the <code>compareTo()</code> contract is obeyed.
  55. */
  56. @Test
  57. public void testCompareTo() {
  58. // Ensure that the implicit comparison contract is satisfied
  59. Version[] expected = {
  60. Version.V1_0,
  61. Version.V1_1,
  62. Version.V1_2,
  63. Version.V1_3,
  64. Version.V1_4,
  65. Version.V1_5,
  66. Version.V1_6,
  67. Version.V1_7
  68. };
  69. Version[] actual = Version.values();
  70. for (int i = 0; i < actual.length - 1; i++) {
  71. assertEquals(-1, actual[i].compareTo(expected[i + 1]));
  72. assertEquals(0, actual[i].compareTo(expected[i]));
  73. assertEquals(1, actual[i + 1].compareTo(expected[i]));
  74. }
  75. }
  76. }