This is an automated email from the ASF dual-hosted git repository. rombert pushed a commit to annotated tag org.apache.sling.testing.osgi-mock-1.1.0 in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-osgi-mock.git
commit 5538cda9ee2f83dcf2bc3536c6b44471765882db Author: Stefan Seifert <[email protected]> AuthorDate: Wed Nov 26 21:56:24 2014 +0000 SLING-4201 MockOsgi.activate()/deactivate()/modified() should fail fast if method is declared but can't be found git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/testing/mocks/osgi-mock@1641947 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/sling/testing/mock/osgi/MockOsgi.java | 31 ++++++++++------------ .../testing/mock/osgi/ReflectionServiceUtil.java | 11 +++++--- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/main/java/org/apache/sling/testing/mock/osgi/MockOsgi.java b/src/main/java/org/apache/sling/testing/mock/osgi/MockOsgi.java index 7a7474f..d6e1b71 100644 --- a/src/main/java/org/apache/sling/testing/mock/osgi/MockOsgi.java +++ b/src/main/java/org/apache/sling/testing/mock/osgi/MockOsgi.java @@ -115,11 +115,9 @@ public final class MockOsgi { } /** - * Simulate activation of service instance. Invokes the @Activate annotated - * method. + * Simulate activation of service instance. Invokes the @Activate annotated method. * @param target Service instance. - * @return true if activation method was called. False if such a method did - * not exist. + * @return true if activation method was called. False if no activate method is defined. */ public static boolean activate(Object target) { ComponentContext componentContext = newComponentContext(); @@ -130,7 +128,7 @@ public final class MockOsgi { * Simulate activation of service instance. Invokes the @Activate annotated method. * @param target Service instance. * @param properties Properties - * @return true if activation method was called. False if it failed. + * @return true if activation method was called. False if no activate method is defined. */ public static boolean activate(Object target, Dictionary<String, Object> properties) { ComponentContext componentContext = newComponentContext(properties); @@ -141,19 +139,18 @@ public final class MockOsgi { * Simulate activation of service instance. Invokes the @Activate annotated method. * @param target Service instance. * @param properties Properties - * @return true if activation method was called. False if it failed. + * @return true if activation method was called. False if no activate method is defined. */ public static boolean activate(Object target, Map<String, Object> properties) { return activate(target, MapUtil.toDictionary(properties)); } /** - * Simulate activation of service instance. Invokes the @Activate annotated - * method. + * Simulate activation of service instance. Invokes the @Activate annotated method. * @param target Service instance. * @param bundleContext Bundle context * @param properties Properties - * @return true if activation method was called. False if it failed. + * @return true if activation method was called. False if no activate method is defined. */ public static boolean activate(Object target, BundleContext bundleContext, Dictionary<String, Object> properties) { ComponentContext componentContext = newComponentContext(bundleContext, properties); @@ -165,7 +162,7 @@ public final class MockOsgi { * @param target Service instance. * @param bundleContext Bundle context * @param properties Properties - * @return true if activation method was called. False if it failed. + * @return true if activation method was called. False if no activate method is defined. */ public static boolean activate(Object target, BundleContext bundleContext, Map<String, Object> properties) { return activate(target, bundleContext, MapUtil.toDictionary(properties)); @@ -174,7 +171,7 @@ public final class MockOsgi { /** * Simulate deactivation of service instance. Invokes the @Deactivate annotated method. * @param target Service instance. - * @return true if deactivation method was called. False if it failed. + * @return true if deactivation method was called. False if no deactivate method is defined. */ public static boolean deactivate(Object target) { ComponentContext componentContext = newComponentContext(); @@ -185,7 +182,7 @@ public final class MockOsgi { * Simulate deactivation of service instance. Invokes the @Deactivate annotated method. * @param target Service instance. * @param properties Properties - * @return true if deactivation method was called. False if it failed. + * @return true if deactivation method was called. False if no deactivate method is defined. */ public static boolean deactivate(Object target, Dictionary<String, Object> properties) { ComponentContext componentContext = newComponentContext(properties); @@ -196,7 +193,7 @@ public final class MockOsgi { * Simulate deactivation of service instance. Invokes the @Deactivate annotated method. * @param target Service instance. * @param properties Properties - * @return true if deactivation method was called. False if it failed. + * @return true if deactivation method was called. False if no deactivate method is defined. */ public static boolean deactivate(Object target, Map<String, Object> properties) { return deactivate(target, MapUtil.toDictionary(properties)); @@ -207,7 +204,7 @@ public final class MockOsgi { * @param target Service instance. * @param bundleContext Bundle context * @param properties Properties - * @return true if deactivation method was called. False if it failed. + * @return true if deactivation method was called. False if no deactivate method is defined. */ public static boolean deactivate(Object target, BundleContext bundleContext, Dictionary<String, Object> properties) { ComponentContext componentContext = newComponentContext(bundleContext, properties); @@ -219,7 +216,7 @@ public final class MockOsgi { * @param target Service instance. * @param bundleContext Bundle context * @param properties Properties - * @return true if activation method was called. False if it failed. + * @return true if deactivation method was called. False if no deactivate method is defined. */ public static boolean deactivate(Object target, BundleContext bundleContext, Map<String, Object> properties) { return deactivate(target, bundleContext, MapUtil.toDictionary(properties)); @@ -230,7 +227,7 @@ public final class MockOsgi { * @param target Service instance. * @param bundleContext Bundle context * @param properties Properties - * @return true if modified method was called. False if it failed. + * @return true if modified method was called. False if no modified method is defined. */ public static boolean modified(Object target, BundleContext bundleContext, Dictionary<String, Object> properties) { return modified(target, bundleContext, MapUtil.toMap(properties)); @@ -241,7 +238,7 @@ public final class MockOsgi { * @param target Service instance. * @param bundleContext Bundle context * @param properties Properties - * @return true if modified method was called. False if it failed. + * @return true if modified method was called. False if no modified method is defined. */ public static boolean modified(Object target, BundleContext bundleContext, Map<String, Object> properties) { return ReflectionServiceUtil.modified(target, bundleContext, properties); diff --git a/src/main/java/org/apache/sling/testing/mock/osgi/ReflectionServiceUtil.java b/src/main/java/org/apache/sling/testing/mock/osgi/ReflectionServiceUtil.java index 0ecc24f..4056ce4 100644 --- a/src/main/java/org/apache/sling/testing/mock/osgi/ReflectionServiceUtil.java +++ b/src/main/java/org/apache/sling/testing/mock/osgi/ReflectionServiceUtil.java @@ -146,8 +146,8 @@ final class ReflectionServiceUtil { return true; } - log.warn("Method {} not found in class {}", methodName, targetClass.getName()); - return false; + throw new RuntimeException("No matching " + (activate ? "activation" : "deactivation") + " method with name '" + methodName + "' " + + " found in class " + targetClass.getName()); } /** @@ -165,6 +165,9 @@ final class ReflectionServiceUtil { throw new NoScrMetadataException(targetClass); } String methodName = OsgiMetadataUtil.getModifiedMethodName(targetClass, metadata); + if (StringUtils.isEmpty(methodName)) { + return false; + } // try to find matching modified method and execute it Method method = getMethod(targetClass, methodName, new Class<?>[] { Map.class }); @@ -173,8 +176,8 @@ final class ReflectionServiceUtil { return true; } - log.warn("Method {} not found in class {}", methodName, targetClass.getName()); - return false; + throw new RuntimeException("No matching modified method with name '" + methodName + "' " + + " found in class " + targetClass.getName()); } private static Method getMethod(Class clazz, String methodName, Class<?>[] types) { -- To stop receiving notification emails like this one, please contact "[email protected]" <[email protected]>.
