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.

CommandLineOptionsTestCase.java 2.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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: CommandLineOptions.java 1293736 2012-02-26 02:29:01Z gadams $ */
  18. package org.apache.fop.cli;
  19. import java.io.IOException;
  20. import org.junit.Before;
  21. import org.junit.Test;
  22. import static org.junit.Assert.assertEquals;
  23. import static org.junit.Assert.assertTrue;
  24. import org.apache.fop.apps.FOPException;
  25. public class CommandLineOptionsTestCase {
  26. private final CommandLineOptions clo = new CommandLineOptions();
  27. private final String commandLine = "-fo examples/fo/basic/simple.fo -print";
  28. private String[] cmd;
  29. private boolean parsed;
  30. @Before
  31. public void setUp() throws Exception {
  32. cmd = commandLine.split(" ");
  33. parsed = clo.parse(cmd);
  34. }
  35. @Test
  36. public void testParse() {
  37. assertTrue(parsed);
  38. }
  39. @Test
  40. public void testGetOutputFormat() throws FOPException {
  41. assertEquals(clo.getOutputFormat(), "application/X-fop-print");
  42. }
  43. @Test
  44. public void testVandVersionSwitchs() throws FOPException, IOException {
  45. // test -v
  46. String cl1 = "-v";
  47. String[] cmd1 = cl1.split(" ");
  48. CommandLineOptions clo1 = new CommandLineOptions();
  49. assertTrue(!clo1.parse(cmd1));
  50. // test -version
  51. String cl2 = "-version";
  52. String[] cmd2 = cl2.split(" ");
  53. CommandLineOptions clo2 = new CommandLineOptions();
  54. assertTrue(!clo2.parse(cmd2));
  55. // test -v + more switches
  56. String cl3 = "-v " + commandLine;
  57. String[] cmd3 = cl3.split(" ");
  58. CommandLineOptions clo3 = new CommandLineOptions();
  59. assertTrue(clo3.parse(cmd3));
  60. }
  61. }