PackageUtil { public static List<String> getClassesInPackage(String packageName) throws IOException { return getClassesInPackage(packageName, null, null); }  static List<String> getResourceInPackage(String packageName); static List<String> getClassesInPackage(String packageName); static List<String> getClassesInPackage(String packageName, List<String> included, List<String> excluded); static Package getPackage(Class<?> clazz); static String getPackageNameForObject(Object object); static String getPackageName(Class<?> clazz); static String getPackageName(String javaClassName); static String getResourceNameForObjectClass(Object object); static String getResourceNameForClass(Class<?> clazz); static String getResourceNameForClass(String className); static String getResourceNameForObjectPackage(Object object); static String getResourceNameForPackage(Class<?> clazz); static String getResourceNameForPackage(String className);  }
@Test public void getClassesInPackage() throws IOException { assertNull(PackageUtil.getClassesInPackage(null)); assertNull(PackageUtil.getClassesInPackage("")); assertNull(PackageUtil.getClassesInPackage(" ")); assertNull(PackageUtil.getClassesInPackage(null, null, null)); assertNull(PackageUtil.getClassesInPackage("", null, null)); assertNull(PackageUtil.getClassesInPackage(" ", null, null)); assertNull(PackageUtil .getClassesInPackage(null, Arrays.asList(new String[] { "com.baidu.unbiz.common" }), null)); assertNull(PackageUtil.getClassesInPackage("", Arrays.asList(new String[] { "com.baidu.unbiz.common" }), null)); assertNull(PackageUtil.getClassesInPackage(" ", Arrays.asList(new String[] { "com.baidu.unbiz.common" }), null)); assertTrue(CollectionUtil.isEmpty(PackageUtil.getClassesInPackage("com.baidu.beidou.xxx"))); assertTrue(CollectionUtil.isEmpty(PackageUtil.getClassesInPackage("notexist"))); List<String> utils = PackageUtil.getClassesInPackage("com.baidu.unbiz.common"); assertTrue(CollectionUtil.isNotEmpty(utils)); List<String> subUtils = PackageUtil.getClassesInPackage("com.baidu.unbiz.common.*"); assertTrue(CollectionUtil.isNotEmpty(subUtils)); assertTrue(CollectionUtil.isNotEmpty(utils)); assertTrue(subUtils.size() > utils.size()); assertTrue(subUtils.containsAll(utils)); assertEquals(PackageUtil.getClassesInPackage("com.baidu.unbiz.common.*"), PackageUtil.getClassesInPackage("com.baidu.unbiz.common.*", null, null)); assertEquals(PackageUtil.getClassesInPackage("com.baidu.unbiz.common.*"), PackageUtil.getClassesInPackage("com.baidu.unbiz.common.*", Arrays.asList(new String[] { ".*" }), null)); assertTrue(CollectionUtil.isEmpty(PackageUtil.getClassesInPackage("com.baidu.unbiz.common.*", Arrays.asList(new String[] { ".*" }), Arrays.asList(new String[] { ".*" })))); assertTrue(CollectionUtil.isEmpty(PackageUtil.getClassesInPackage("com.baidu.unbiz.common.*", null, Arrays.asList(new String[] { ".*" })))); List<String> includeTests = PackageUtil.getClassesInPackage("com.baidu.unbiz.common.*", Arrays.asList(new String[] { ".*Test" }), null); assertTrue(CollectionUtil.isNotEmpty(includeTests)); List<String> excludeTests = PackageUtil.getClassesInPackage("com.baidu.unbiz.common.*", null, Arrays.asList(new String[] { ".*Test" })); assertTrue(CollectionUtil.isNotEmpty(excludeTests)); assertEquals(subUtils.size(), includeTests.size() + excludeTests.size()); List<String> langs = PackageUtil.getClassesInPackage("org.slf4j"); assertTrue(CollectionUtil.isNotEmpty(langs)); List<String> subLangs = PackageUtil.getClassesInPackage("org.slf4j.*"); assertTrue(CollectionUtil.isNotEmpty(subLangs)); assertEquals(subLangs, langs); }