<commit_before>/*
 * Copyright (c) IBM Corporation (2009). All Rights Reserved.
 *
 * Licensed 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.osgi.test.cases.blueprint.components.serviceimport;

import java.util.Map;

import org.osgi.test.cases.blueprint.services.AssertionService;
import org.osgi.test.cases.blueprint.services.TestServiceOne;
import org.osgi.test.cases.blueprint.services.ServiceOneListenerInterface;


/**
 * A base class for different reference listeners used to validate
 * reference registration/deregistration calls.
 */
public class ServiceOneListener extends ServiceListener implements ServiceOneListenerInterface {
    // an interlock flag so we don't try to use the service on an initial unbind operation.
    protected boolean initialUnbind = false;

    public ServiceOneListener(String componentId) {
        super(componentId);
    }

    public void setInitialUnbind(boolean setting) {
        initialUnbind = setting;
    }

    public void bind(TestServiceOne service, Map serviceProperties) {
        try {
            // Some tests we switch back and forth, so check the name
            // to see which result we should be getting
            if ("BadService".equals(service.getServiceName())) {
                AssertionService.assertFalse(this, "Bad service call", service.testOne());
            }
            else {
                AssertionService.assertTrue(this, "Bad service call", service.testOne());
            }
        } catch (Throwable e) {
            AssertionService.fail(this, "Unexpected exception in service listener", e);
        }
        bind(TestServiceOne.class, serviceProperties);
    }

    public void unbind(TestServiceOne service, Map serviceProperties) {
        // if the initial state is unbound, then we get passed a null for the proxy
        if (initialUnbind) {
            AssertionService.assertNull(this, "non null proxy passed to an initial unbind method", service);
            // all unbinds from this point are required to pass a proxy
            initialUnbind = false;
        }
        else {

            try {
                // Some tests we switch back and forth, so check the name
                // to see which result we should be getting
                if ("BadService".equals(service.getServiceName())) {
                    AssertionService.assertFalse(this, "Bad service call", service.testOne());
                }
                else {
                    AssertionService.assertTrue(this, "Bad service call", service.testOne());
                }
            } catch (Throwable e) {
                AssertionService.fail(this, "Unexpected exception in service listener", e);
            }
            unbind(TestServiceOne.class, serviceProperties);
        }
    }

    public void bindNoMap(TestServiceOne service) {
        try {
            // Some tests we switch back and forth, so check the name<commit_msg>Potential race condition in some of the tests cause NPE<commit_after>/*
 * Copyright (c) IBM Corporation (2009). All Rights Reserved.
 *
 * Licensed 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.osgi.test.cases.blueprint.components.serviceimport;

import java.util.Map;

import org.osgi.test.cases.blueprint.services.AssertionService;
import org.osgi.test.cases.blueprint.services.TestServiceOne;
import org.osgi.test.cases.blueprint.services.ServiceOneListenerInterface;


/**
 * A base class for different reference listeners used to validate
 * reference registration/deregistration calls.
 */
public class ServiceOneListener extends ServiceListener implements ServiceOneListenerInterface {
    // an interlock flag so we don't try to use the service on an initial unbind operation.
    protected boolean initialUnbind = true;

    public ServiceOneListener(String componentId) {
        super(componentId);
    }

    public void setInitialUnbind(boolean setting) {
        initialUnbind = setting;
    }

    public void bind(TestServiceOne service, Map serviceProperties) {
        // once we've had a bind call, the unbinds must present an object
        initialUnbind = false;
        try {
            // Some tests we switch back and forth, so check the name
            // to see which result we should be getting
            if ("BadService".equals(service.getServiceName())) {
                AssertionService.assertFalse(this, "Bad service call", service.testOne());
            }
            else {
                AssertionService.assertTrue(this, "Bad service call", service.testOne());
            }
        } catch (Throwable e) {
            AssertionService.fail(this, "Unexpected exception in service listener", e);
        }
        bind(TestServiceOne.class, serviceProperties);
    }

    public void unbind(TestServiceOne service, Map serviceProperties) {
        // if the initial state is unbound, then we get passed a null for the proxy
        if (initialUnbind) {
            AssertionService.assertNull(this, "non null proxy passed to an initial unbind method", service);
            // all unbinds from this point are required to pass a proxy
            initialUnbind = false;
        }
        else {

            try {
                // Some tests we switch back and forth, so check the name
                // to see which result we should be getting
                if ("BadService".equals(service.getServiceName())) {
                    AssertionService.assertFalse(this, "Bad service call", service.testOne());
                }
                else {
                    AssertionService.assertTrue(this, "Bad service call", service.testOne());
                }
            } catch (Throwable e) {
                AssertionService.fail(this, "Unexpected exception in service listener", e);
            }
            unbind(TestServiceOne.class, serviceProperties);
        }
    }

    public void bindNoMap(TestServiceOne service) {
        // once we've had a bind call, the unbinds must present an object
        initialUnbind = false;
        try {
            // Some tests we switch back and forth, so check the name
{'fraction_non_alphanumeric': 0.07706370412037689, 'fraction_numerical': 0.002250035156799325, 'mean_word_length': 2.4794520547945207, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2899186', 'n_tokens_mistral': 1743, 'n_tokens_neox': 1695, 'n_words': 650}