01: package test.util;
02:
03: import java.io.IOException;
04: import java.util.Collections;
05:
06: import org.testng.Assert;
07: import org.testng.internal.PackageUtils;
08:
09: /**
10: * Not very safe test for Utils.findClassesInPackage. It relies on some
11: * internal directories/jar content.
12: *
13: * @author <a href='mailto:the_mindstorm[at]evolva[dot]ro'>Alexandru Popescu</a>
14: */
15: public class FindPackageClassesTest {
16: /**
17: * @testng.test
18: */
19: public void findFilesInFolderNonRecursive() {
20: try {
21: String[] classes = PackageUtils.findClassesInPackage(
22: "test.confordering", Collections.EMPTY_LIST,
23: Collections.EMPTY_LIST);
24:
25: Assert
26: .assertEquals(classes.length, 1,
27: "check if test/confordering contains more than 1 source");
28: } catch (IOException ioe) {
29: Assert.fail("cannot read directory", ioe);
30: }
31: }
32:
33: /**
34: * @testng.test
35: */
36: public void findFilesInFolderRecursive() {
37: try {
38: String[] classes = PackageUtils.findClassesInPackage(
39: "test.confordering.*", Collections.EMPTY_LIST,
40: Collections.EMPTY_LIST);
41:
42: Assert
43: .assertEquals(classes.length, 5,
44: "check if test/confordering and subdirs contains more than 5 sources");
45: } catch (IOException ioe) {
46: Assert.fail("cannot read directory", ioe);
47: }
48: }
49:
50: /**
51: * @testng.test
52: */
53: public void findFilesInJarNonRecursive() {
54: try {
55: String[] classes = PackageUtils.findClassesInPackage(
56: "com.thoughtworks.qdox.parser",
57: Collections.EMPTY_LIST, Collections.EMPTY_LIST);
58:
59: Assert
60: .assertEquals(
61: classes.length,
62: 3,
63: "qdox-1.5.jar should contain only 3 classes in dir com.thoughtworks.qdox.parser");
64: } catch (IOException ioe) {
65: Assert.fail("cannot read jar [qdox-1.5.jar]", ioe);
66: }
67: }
68:
69: /**
70: * @testng.test
71: */
72: public void findFilesInJarRecursive() {
73: try {
74: String[] classes = PackageUtils.findClassesInPackage(
75: "com.thoughtworks.qdox.parser.*",
76: Collections.EMPTY_LIST, Collections.EMPTY_LIST);
77:
78: Assert
79: .assertEquals(
80: classes.length,
81: 13,
82: "qdox-1.5.jar should contain only 3 classes in dir and subdirs com.thoughtworks.qdox.parser");
83: } catch (IOException ioe) {
84: Assert.fail("cannot read jar [qdox-1.5.jar]", ioe);
85: }
86: }
87: }
|