Permalink
Browse files

Closes #289: improves tests coverage

  • Loading branch information...
1 parent b7b1a46 commit f5097d544ae191661da713983f5f570b024cccea @garcia-jj garcia-jj committed Sep 21, 2012
View
20 vraptor-core/src/test/java/br/com/caelum/vraptor/scan/ScannotationComponentScannerTest.java
@@ -1,6 +1,7 @@
package br.com.caelum.vraptor.scan;
import static org.hamcrest.Matchers.hasItem;
+import static org.hamcrest.Matchers.hasSize;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.when;
@@ -35,6 +36,7 @@ public void shouldScanWEBINFClasses() {
ScannotationComponentScanner scanner = new ScannotationComponentScanner();
assertThat(scanner.scan(classPathResolver), hasItem(ResourceInTheClasspath.class.getName()));
}
+
@Test
public void shouldScanBasePackages() {
ClassLoader classLoader = new URLClassLoader(new URL[] {ScannotationComponentScannerTest.class.getResource("/test-fixture.jar")});
@@ -46,4 +48,22 @@ public void shouldScanBasePackages() {
Collection<String> classes = scanner.scan(classPathResolver);
assertThat(classes, hasItem(ResourceInTheClasspath.class.getName()));
}
+
+ @Test
+ public void shouldReturnEmptyCollectionIfWebinfClassesNotFound() throws Exception {
+ URL webinfLocation = new URL("file:/a/url/that/not-found");
+ when(classPathResolver.findWebInfClassesLocation()).thenReturn(webinfLocation);
+
+ ScannotationComponentScanner scanner = new ScannotationComponentScanner();
+ assertThat(scanner.scan(classPathResolver), hasSize(0));
+ }
+
+ @Test(expected=ScannerException.class)
+ public void shouldThrowScannerExceptionIfHasExceptionWhenProcessWebinfClasses() throws Exception {
+ URL webinfLocation = new URL("file://x");
+ when(classPathResolver.findWebInfClassesLocation()).thenReturn(webinfLocation);
+
+ ScannotationComponentScanner scanner = new ScannotationComponentScanner();
+ assertThat(scanner.scan(classPathResolver), hasSize(0));
+ }
}

0 comments on commit f5097d5

Please sign in to comment.