* ResourceStore should throw Exception when a resource could not be found (not return null)
* Updated tests in this perspective
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1489365 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/ipojo/manipulator/bnd-ipojo-plugin/src/main/java/org/apache/felix/ipojo/bnd/BndJarResourceStore.java b/ipojo/manipulator/bnd-ipojo-plugin/src/main/java/org/apache/felix/ipojo/bnd/BndJarResourceStore.java
index 94b3324..0d6c5e9 100644
--- a/ipojo/manipulator/bnd-ipojo-plugin/src/main/java/org/apache/felix/ipojo/bnd/BndJarResourceStore.java
+++ b/ipojo/manipulator/bnd-ipojo-plugin/src/main/java/org/apache/felix/ipojo/bnd/BndJarResourceStore.java
@@ -19,6 +19,8 @@
package org.apache.felix.ipojo.bnd;
+import static java.lang.String.format;
+
import aQute.lib.osgi.Analyzer;
import aQute.lib.osgi.Clazz;
import aQute.lib.osgi.Jar;
@@ -67,6 +69,9 @@
Resource resource = m_analyzer.getJar().getResource(path);
if (resource == null) {
Jar embed = findJar(path);
+ if (embed == null) {
+ throw new IOException(format("Cannot find resource %s in jar and classpath", path));
+ }
resource = embed.getResource(path);
}
InputStream is = null;
diff --git a/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/util/Bindings.java b/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/util/Bindings.java
index d675351..3878190 100644
--- a/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/util/Bindings.java
+++ b/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/util/Bindings.java
@@ -253,16 +253,11 @@
// Try to read the annotation's byte code
byte[] bytes = store.read(Strings.asResourcePath(context.getAnnotationType().getClassName()));
- if (bytes != null) {
- StereotypeParser parser = new StereotypeParser();
- parser.read(bytes);
- if (parser.isStereotype()) {
- registry.addStereotype(type, parser.getRecorders());
- return true;
- } else {
- registry.addUnbound(type);
- return false;
- }
+ StereotypeParser parser = new StereotypeParser();
+ parser.read(bytes);
+ if (parser.isStereotype()) {
+ registry.addStereotype(type, parser.getRecorders());
+ return true;
}
registry.addUnbound(type);
return false;
diff --git a/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulation/RemanipulationTest.java b/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulation/RemanipulationTest.java
index 6cfd18a..74ddeb3 100644
--- a/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulation/RemanipulationTest.java
+++ b/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulation/RemanipulationTest.java
@@ -130,7 +130,11 @@
}
public byte[] read(String path) throws IOException {
- return resources.get(path);
+ byte[] bytes = resources.get(path);
+ if (bytes == null) {
+ throw new IOException();
+ }
+ return bytes;
}
public void accept(ResourceVisitor visitor) {
diff --git a/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulator/metadata/AnnotationMetadataProviderTestCase.java b/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulator/metadata/AnnotationMetadataProviderTestCase.java
index baa573d..5570eb6 100644
--- a/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulator/metadata/AnnotationMetadataProviderTestCase.java
+++ b/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulator/metadata/AnnotationMetadataProviderTestCase.java
@@ -20,6 +20,8 @@
package org.apache.felix.ipojo.manipulator.metadata;
import junit.framework.TestCase;
+
+import org.apache.felix.ipojo.annotations.Component;
import org.apache.felix.ipojo.manipulator.Reporter;
import org.apache.felix.ipojo.manipulator.ResourceStore;
import org.apache.felix.ipojo.manipulator.ResourceVisitor;
@@ -27,6 +29,7 @@
import org.apache.felix.ipojo.manipulator.util.Strings;
import org.apache.felix.ipojo.metadata.Element;
import test.AnnotatedComponent;
+import test.FakeAnnotation;
import java.io.IOException;
import java.io.InputStream;
@@ -38,7 +41,7 @@
public class AnnotationMetadataProviderTestCase extends TestCase {
public void testGetMetadatas() throws Exception {
- MiniStore store = new MiniStore(AnnotatedComponent.class);
+ MiniStore store = new MiniStore(AnnotatedComponent.class, FakeAnnotation.class);
Reporter reporter = mock(Reporter.class);
AnnotationMetadataProvider provider = new AnnotationMetadataProvider(store, reporter);
diff --git a/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulator/metadata/annotation/registry/SelectionTestCase.java b/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulator/metadata/annotation/registry/SelectionTestCase.java
index 7067d63..d1def40 100644
--- a/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulator/metadata/annotation/registry/SelectionTestCase.java
+++ b/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulator/metadata/annotation/registry/SelectionTestCase.java
@@ -39,6 +39,7 @@
import org.objectweb.asm.tree.FieldNode;
import org.objectweb.asm.tree.MethodNode;
+import java.io.IOException;
import java.lang.annotation.Annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Target;
@@ -47,6 +48,7 @@
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.when;
/**
@@ -74,6 +76,9 @@
registry = new BindingRegistry(reporter);
when(factory.newAnnotationVisitor(any(BindingContext.class)))
.thenReturn(visitor);
+ // Simulate a resource not found exception
+ when(store.read(anyString()))
+ .thenThrow(new IOException());
}
public void testSelectionOnClassNodeOnly() throws Exception {