public Statement apply()

in src/main/java/org/apache/sling/junit/rules/Service.java [44:68]


    public Statement apply(final Statement base, final Description description) {
        return new Statement() {

            @Override
            public void evaluate() throws Throwable {
                final BundleContext bundleContext = Activator.getBundleContext();

                if (bundleContext == null) {
                    // No bundle context usually means we're running client-side
                    // in a test that uses ServerSideTestRule. In this case, this
                    // rule does nothing.
                    base.evaluate();
                    return;
                }

                serviceGetter = ServiceGetter.create(bundleContext, serviceClass, null);
                try {
                    base.evaluate();
                } finally {
                    serviceGetter.close();
                }
            }

        };
    }