You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by bd...@apache.org on 2015/09/17 16:41:33 UTC
svn commit: r1703635 - in /sling/trunk/testing/junit/core: pom.xml
src/main/java/org/apache/sling/junit/rules/OSGiService.java
src/main/java/org/apache/sling/junit/rules/Service.java
Author: bdelacretaz
Date: Thu Sep 17 14:41:29 2015
New Revision: 1703635
URL: http://svn.apache.org/r1703635
Log:
SLING-5039 - add OSGiService, a variant of Service that uses generics
Added:
sling/trunk/testing/junit/core/src/main/java/org/apache/sling/junit/rules/OSGiService.java
Modified:
sling/trunk/testing/junit/core/pom.xml
sling/trunk/testing/junit/core/src/main/java/org/apache/sling/junit/rules/Service.java
Modified: sling/trunk/testing/junit/core/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/testing/junit/core/pom.xml?rev=1703635&r1=1703634&r2=1703635&view=diff
==============================================================================
--- sling/trunk/testing/junit/core/pom.xml (original)
+++ sling/trunk/testing/junit/core/pom.xml Thu Sep 17 14:41:29 2015
@@ -61,7 +61,7 @@
<Bundle-Activator>org.apache.sling.junit.Activator</Bundle-Activator>
<Export-Package>
org.apache.sling.junit;version=1.1.0,
- org.apache.sling.junit.rules;version=1.0.10,
+ org.apache.sling.junit.rules;version=1.1.0,
org.apache.sling.junit.annotations;version=1.0.8,
</Export-Package>
<_exportcontents>
Added: sling/trunk/testing/junit/core/src/main/java/org/apache/sling/junit/rules/OSGiService.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/junit/core/src/main/java/org/apache/sling/junit/rules/OSGiService.java?rev=1703635&view=auto
==============================================================================
--- sling/trunk/testing/junit/core/src/main/java/org/apache/sling/junit/rules/OSGiService.java (added)
+++ sling/trunk/testing/junit/core/src/main/java/org/apache/sling/junit/rules/OSGiService.java Thu Sep 17 14:41:29 2015
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sling.junit.rules;
+
+/** Improved variant of the Service class that uses generics */
+public class OSGiService <T> extends Service {
+
+ private final Class<T> clazz;
+
+ private OSGiService(Class<T> clazz) {
+ super(clazz);
+ this.clazz = clazz;
+ }
+
+ public static <T> OSGiService<T> ofClass(Class<T> clazz) {
+ return new OSGiService<T>(clazz);
+ }
+
+ public T get() {
+ return (T)super.getService(clazz);
+ }
+}
Modified: sling/trunk/testing/junit/core/src/main/java/org/apache/sling/junit/rules/Service.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/junit/core/src/main/java/org/apache/sling/junit/rules/Service.java?rev=1703635&r1=1703634&r2=1703635&view=diff
==============================================================================
--- sling/trunk/testing/junit/core/src/main/java/org/apache/sling/junit/rules/Service.java (original)
+++ sling/trunk/testing/junit/core/src/main/java/org/apache/sling/junit/rules/Service.java Thu Sep 17 14:41:29 2015
@@ -27,6 +27,8 @@ import org.osgi.framework.ServiceReferen
/**
* Allows a test class to obtain a reference to an OSGi service. This rule embodies the logic to get a bundle context,
* obtain a service reference, fetch the reference to the object and perform the proper cleanup after the test has run.
+ *
+ * The newer OSGiService class uses generics and is more convenient to use.
*/
public class Service implements TestRule {