You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

ProtectedJarMethodsTest.java 3.3 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*
  2. * Copyright 2004 The Apache Software Foundation
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. *
  16. */
  17. package org.apache.tools.ant.taskdefs;
  18. import java.io.File;
  19. import java.io.IOException;
  20. import java.util.ArrayList;
  21. import org.apache.tools.ant.BuildFileTest;
  22. /**
  23. */
  24. public class ProtectedJarMethodsTest extends BuildFileTest {
  25. private static String tempJar = "tmp.jar";
  26. public ProtectedJarMethodsTest(String name) {
  27. super(name);
  28. }
  29. public void setUp() {
  30. configureProject("src/etc/testcases/taskdefs/jar.xml");
  31. }
  32. public void tearDown() {
  33. executeTarget("cleanup");
  34. }
  35. public void testGrabFilesAndDirs() throws IOException {
  36. executeTarget("testIndexTests");
  37. String archive = getProject().resolveFile(tempJar).getAbsolutePath();
  38. ArrayList dirs = new ArrayList();
  39. ArrayList files = new ArrayList();
  40. String[] expectedDirs = new String[] {
  41. "sub/",
  42. };
  43. String[] expectedFiles = new String[] {
  44. "foo",
  45. };
  46. Jar.grabFilesAndDirs(archive, dirs, files);
  47. assertEquals(expectedDirs.length, dirs.size());
  48. for (int i = 0; i < expectedDirs.length; i++) {
  49. assertTrue("Found " + expectedDirs[i],
  50. dirs.contains(expectedDirs[i]));
  51. }
  52. assertEquals(expectedFiles.length, files.size());
  53. for (int i = 0; i < expectedFiles.length; i++) {
  54. assertTrue("Found " + expectedFiles[i],
  55. files.contains(expectedFiles[i]));
  56. }
  57. }
  58. public void testFindJarNameNoClasspath() {
  59. assertEquals("foo", Jar.findJarName("foo", null));
  60. assertEquals("foo", Jar.findJarName("lib" + File.separatorChar + "foo",
  61. null));
  62. }
  63. public void testFindJarNameNoMatch() {
  64. assertNull(Jar.findJarName("foo", new String[] {"bar"}));
  65. }
  66. public void testFindJarNameSimpleMatches() {
  67. assertEquals("foo", Jar.findJarName("foo", new String[] {"foo"}));
  68. assertEquals("lib/foo", Jar.findJarName("foo",
  69. new String[] {"lib/foo"}));
  70. assertEquals("foo", Jar.findJarName("bar" + File.separatorChar + "foo",
  71. new String[] {"foo"}));
  72. assertEquals("lib/foo",
  73. Jar.findJarName("bar" + File.separatorChar + "foo",
  74. new String[] {"lib/foo"}));
  75. }
  76. public void testFindJarNameLongestMatchWins() {
  77. assertEquals("lib/foo",
  78. Jar.findJarName("lib/foo",
  79. new String[] {"foo", "lib/foo",
  80. "lib/bar/foo"}));
  81. }
  82. }