...11import static org.hamcrest.core.IsNot.not;12public class WhenLoadingClassesFromAPackage {13 @Test14 public void shouldLoadAllClassesInAPackage() {15 List<Class<?>> classes = ClassFinder.loadClasses().fromPackage("net.serenitybdd.jbehave.pages");16 assertThat(classes.size(), is(1));17 assertThat(classes.get(0).getName(), is("net.serenitybdd.jbehave.pages.StaticSitePage"));18 }19 @Test20 public void shouldNotCrashForARootPackage() {21 List<Class<?>> classes = ClassFinder.loadClasses().fromPackage("net");22 assertThat(classes.size(), not(0));23 }24 @Test25 public void shouldLoadAllClassesInNestedPackages() {26 List<Class<?>> classes = ClassFinder.loadClasses().fromPackage("net.serenitybdd.jbehave");27 assertThat(classes.size(), greaterThan(10));28 }29 @Test30 public void shouldLoadAllAnnotatedClassesInNestedPackages() {31 List<Class<?>> classes = ClassFinder.loadClasses().annotatedWith(Given.class).fromPackage("net.serenitybdd.jbehave");32 assertThat(classes.size(), greaterThan(10));33 }34 @Test35 public void shouldLoadNoClassesIfThePackageDoesNotExist() {36 List<Class<?>> classes = ClassFinder.loadClasses().fromPackage("that.does.not.exist");37 assertThat(classes.size(), is(0));38 }39 @Test40 public void shouldNotLoadResourcesOnClasspath() {41 List<Class<?>> classes = ClassFinder.loadClasses().fromPackage("stories");42 assertThat(classes.size(), is(0));43 }44 @Test45 public void shouldLoadClassesFromDependencies() {46 List<Class<?>> classes = ClassFinder.loadClasses().annotatedWith(Ignore.class).fromPackage("net.thucydides.jbehave");47 List<String> classnames = classes.stream().map(Class::getName).collect(Collectors.toList());48 assertThat(classnames, hasItem("net.thucydides.jbehave.SomeBoilerplateSteps"));49 }50 @Test51 public void shouldLoadAllClassesInAGivenPackageFromAnotherModuleAndAllSubpackages() {52 List<Class<?>> classes = ClassFinder.loadClasses().fromPackage("net.thucydides.jbehave");53 List<String> classnames = classes.stream().map(Class::getName).collect(Collectors.toList());54 assertThat(classnames, hasItem("net.thucydides.jbehave.SomeBoilerplateSteps"));55 }56 // enable testing from an IDE, where otherwise the classpath is setup to depend directly on .class files, without packaging to .jar57 @Test58 public void shouldLoadClassesInAGivenPackageFromADependencyJar() {59 List<Class<?>> classes = ClassFinder.loadClasses().fromPackage("org.junit.runners");60 List<String> classnames = classes.stream().map(Class::getName).collect(Collectors.toList());61 assertThat(classnames, hasItem("org.junit.runners.JUnit4"));62 }63 // enable testing from an IDE, where otherwise the classpath is setup to depend directly on .class files, without packaging to .jar64 @Test65 public void shouldLoadNestedClassesInAGivenPackageFromADependencyJar() {66 List<Class<?>> classes = ClassFinder.loadClasses().fromPackage("org.junit.runners");67 List<String> classnames = classes.stream().map(Class::getName).collect(Collectors.toList());68 assertThat(classnames, hasItem("org.junit.runners.model.RunnerScheduler"));69 }70 // enable testing from an IDE, where otherwise the classpath is setup to depend directly on .class files, without packaging to .jar71 @Test72 public void shouldLoadAnnotatedClassesInAGivenPackageFromADependencyJar() {73 List<Class<?>> classes = net.thucydides.core.reflection.ClassFinder.loadClasses()74 .annotatedWith(Deprecated.class)75 .fromPackage("junit.framework");76 List<String> classnames = classes.stream().map(Class::getName).collect(Collectors.toList());77 assertThat(classnames, hasItem("junit.framework.Assert"));78 }79}...